From e40824bded1c8263e21016107237419e2185cd86 Mon Sep 17 00:00:00 2001 From: kialam Date: Fri, 28 Oct 2022 15:59:54 -0700 Subject: [PATCH] Fix Schedules Form date validation same day different time scenario (#13062) * Format datetime and convert to ms to compare which date is larger. * Add supporting unit test. --- .../Schedule/shared/ScheduleForm.js | 10 +++++-- .../Schedule/shared/ScheduleForm.test.js | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/awx/ui/src/components/Schedule/shared/ScheduleForm.js b/awx/ui/src/components/Schedule/shared/ScheduleForm.js index a857cc10f4..43407d2737 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleForm.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleForm.js @@ -416,8 +416,14 @@ function ScheduleForm({ if (options.end === 'onDate') { if ( - DateTime.fromISO(values.startDate) >= - DateTime.fromISO(options.endDate) + DateTime.fromFormat( + `${values.startDate} ${values.startTime}`, + 'yyyy-LL-dd h:mm a' + ).toMillis() >= + DateTime.fromFormat( + `${options.endDate} ${options.endTime}`, + 'yyyy-LL-dd h:mm a' + ).toMillis() ) { freqErrors.endDate = t`Please select an end date/time that comes after the start date/time.`; } diff --git a/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js b/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js index 5e1ea28b8d..61c6313093 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js @@ -900,6 +900,36 @@ describe('', () => { ); }); + test('should create schedule with the same start and end date provided that the end date is at a later time', async () => { + const today = DateTime.now().toFormat('yyyy-LL-dd'); + const laterTime = DateTime.now().plus({ hours: 1 }).toFormat('h:mm a'); + await act(async () => { + wrapper.find('DatePicker[aria-label="End date"]').prop('onChange')( + today, + new Date(today) + ); + }); + wrapper.update(); + expect( + wrapper + .find('FormGroup[data-cy="schedule-End date/time"]') + .prop('helperTextInvalid') + ).toBe( + 'Please select an end date/time that comes after the start date/time.' + ); + await act(async () => { + wrapper.find('TimePicker[aria-label="End time"]').prop('onChange')( + laterTime + ); + }); + wrapper.update(); + expect( + wrapper + .find('FormGroup[data-cy="schedule-End date/time"]') + .prop('helperTextInvalid') + ).toBe(undefined); + }); + test('error shown when on day number is not between 1 and 31', async () => { await act(async () => { wrapper.find('FrequencySelect#schedule-frequency').invoke('onChange')([