Skip to content

Commit

Permalink
Merge pull request ansible#6166 from ansible/backport-5983-4.2
Browse files Browse the repository at this point in the history
[4.2] Backport Validate same start/end day different time schedule
  • Loading branch information
akus062381 authored Nov 1, 2022
2 parents 44c11ff + 07e1252 commit 1be224c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion awx/ui/src/components/Schedule/shared/ScheduleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,12 @@ function ScheduleForm({
const {
end,
endDate,
endTime,
frequency,
runOn,
runOnDayNumber,
startDate,
startTime,
} = values;

if (
Expand All @@ -577,7 +579,14 @@ function ScheduleForm({

if (
end === 'onDate' &&
DateTime.fromISO(startDate) >= DateTime.fromISO(endDate)
DateTime.fromFormat(
`${startDate} ${startTime}`,
'yyyy-LL-dd h:mm a'
).toMillis() >=
DateTime.fromFormat(
`${endDate} ${endTime}`,
'yyyy-LL-dd h:mm a'
).toMillis()
) {
errors.endDate = t`Please select an end date/time that comes after the start date/time.`;
}
Expand Down
30 changes: 30 additions & 0 deletions awx/ui/src/components/Schedule/shared/ScheduleForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,36 @@ describe('<ScheduleForm />', () => {
);
});

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 () => {
act(() => {
wrapper.find('select[id="schedule-frequency"]').invoke('onChange')(
Expand Down

0 comments on commit 1be224c

Please sign in to comment.