Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateInput: Fix type of value props #1260

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions components/date-input/spec/DateInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,69 @@ describe('DateInput', () => {
it('that is described by the error and the hint', async () => expect(screen.getByRole('group')).toHaveAccessibleDescription('The day you were born Error: Date must be in the past'));
it('contains the label', async () => expect(screen.getByRole('group')).toHaveTextContent('My date'));
});

describe('when given a defaultValue prop', () => {
const props = {
...minimalProps,
hint: 'The day you were born',
defaultValue: {
day: '05',
month: '04',
year: '2025'
}
};
beforeEach(async () => {
render(h(DateInput, props));
});

it('renders a form-group', async () => expect(screen.getByRole('group')).toBeInTheDocument());
it('contains the label', async () => expect(screen.getByRole('group')).toHaveTextContent('My date'));
it('has a day value', async () => expect(screen.getByLabelText('Day')).toHaveDisplayValue('05'));
it('has a month value', async () => expect(screen.getByLabelText('Month')).toHaveDisplayValue('04'));
it('has a year value', async () => expect(screen.getByLabelText('Year')).toHaveDisplayValue('2025'));
});

describe('when given a value prop', () => {
const props = {
...minimalProps,
hint: 'The day you were born',
value: {
day: '06',
month: '12',
year: '2024'
},
onChange: jest.fn()
};
beforeEach(async () => {
render(h(DateInput, props));
});

it('renders a form-group', async () => expect(screen.getByRole('group')).toBeInTheDocument());
it('contains the label', async () => expect(screen.getByRole('group')).toHaveTextContent('My date'));
it('has a day value', async () => expect(screen.getByLabelText('Day')).toHaveDisplayValue('06'));
it('has a month value', async () => expect(screen.getByLabelText('Month')).toHaveDisplayValue('12'));
it('has a year value', async () => expect(screen.getByLabelText('Year')).toHaveDisplayValue('2024'));
});

describe('when given a value prop', () => {
const props = {
...minimalProps,
hint: 'The day you were born',
value: {
day: '06',
month: '12',
year: '2024'
},
onChange: jest.fn()
};
beforeEach(async () => {
render(h(DateInput, props));
});

it('renders a form-group', async () => expect(screen.getByRole('group')).toBeInTheDocument());
it('contains the label', async () => expect(screen.getByRole('group')).toHaveTextContent('My date'));
it('has a day value', async () => expect(screen.getByLabelText('Day')).toHaveDisplayValue('06'));
it('has a month value', async () => expect(screen.getByLabelText('Month')).toHaveDisplayValue('12'));
it('has a year value', async () => expect(screen.getByLabelText('Year')).toHaveDisplayValue('2024'));
});
daniel-ac-martin marked this conversation as resolved.
Show resolved Hide resolved
});
2 changes: 1 addition & 1 deletion components/date-input/src/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const isPreValidateError = (v: DateInputError): v is DateInputPreValidate
)
);

export type DateInputProps = StandardProps & Omit<InputHTMLAttributes<HTMLInputElement>, 'label'> & {
export type DateInputProps = StandardProps & Omit<InputHTMLAttributes<HTMLInputElement>, 'label' | 'value' | 'defaultValue'> & {
/** Initial value of the field */
defaultValue?: DateInputValue,
/** Error message */
Expand Down
Loading