Skip to content

Commit

Permalink
[open-formulieren/open-forms#3671] Added unit test and story for max …
Browse files Browse the repository at this point in the history
…date
  • Loading branch information
vaszig committed Dec 19, 2023
1 parent 8954cbe commit 4623e84
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/formio/components/DateField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,38 @@ export const DateWithMinField = {
// await expect(error).not.toBeNull();
},
};

export const DateWithMaxField = {
render: SingleFormioComponent,
args: {
key: 'date',
label: 'Datum <= 18-12-2023',
extraComponentProperties: {
format: 'dd-MM-yyyy',
placeholder: 'dd-mm-yyyy',
enableTime: false,
datePicker: {
minDate: null,
maxDate: '2023-12-18T00:00:00+01:00',
},
customOptions: {
allowInvalidPreload: true,
},
validate: {
dateMinMax: true,
},
},
},
play: async ({canvasElement}) => {
const canvas = within(canvasElement);

const dateInput = canvas.getByRole('textbox');

userEvent.type(dateInput, '19-12-2023');
expect(dateInput).toHaveDisplayValue('19-12-2023');

// TODO: I cannot get this to work. If you do it manually in storybook, it works... (it shows the error).
// const error = canvas.queryByText('maxDate');
// await expect(error).not.toBeNull();
},
};
24 changes: 24 additions & 0 deletions src/jstests/formio/components/date.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ describe('Date Component', () => {
done();
});

test('Date validator: check max date including the current one', done => {
const component = {
label: 'date',
key: 'date',
type: 'date',
datePicker: {
minDate: null,
maxDate: '2023-09-08',
},
customOptions: {
allowInvalidPreload: true,
},
validate: {dateMinMax: true},
};

const componentInstance = new FormioComponent(component, {}, {});

const isValid1 = MinMaxDateValidator.check(componentInstance, {}, '2023-09-08');

expect(isValid1).toBeTruthy();

done();
});

test('Date validator: error message', done => {
const component = {
label: 'date',
Expand Down

0 comments on commit 4623e84

Please sign in to comment.