From 4623e84e60310185b17c049d03213fe01389a607 Mon Sep 17 00:00:00 2001 From: vasileios Date: Tue, 19 Dec 2023 08:41:44 +0100 Subject: [PATCH] [open-formulieren/open-forms#3671] Added unit test and story for max date --- src/formio/components/DateField.stories.js | 35 ++++++++++++++++++++++ src/jstests/formio/components/date.spec.js | 24 +++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/formio/components/DateField.stories.js b/src/formio/components/DateField.stories.js index 99f594621..6acd2f0bc 100644 --- a/src/formio/components/DateField.stories.js +++ b/src/formio/components/DateField.stories.js @@ -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(); + }, +}; diff --git a/src/jstests/formio/components/date.spec.js b/src/jstests/formio/components/date.spec.js index 374c79cca..977ac329a 100644 --- a/src/jstests/formio/components/date.spec.js +++ b/src/jstests/formio/components/date.spec.js @@ -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',