Skip to content

Commit

Permalink
uses pf date and time picker to schedule form
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSCorey committed May 26, 2021
1 parent d2d62ad commit 2c7ec14
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 136 deletions.
2 changes: 2 additions & 0 deletions awx/ui_next/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
{
"markupOnly": true,
"ignoreAttribute": [
"dateFieldName",
"timeFieldName",
"to",
"streamType",
"path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ function ScheduleAdd({
end,
frequency,
interval,
startDateTime,
timezone,
occurrences,
runOn,
runOnTheDay,
runOnTheMonth,
runOnDayMonth,
runOnDayNumber,
endDateTime,
runOnTheOccurrence,
credentials,
daysOfWeek,
Expand Down Expand Up @@ -100,6 +98,10 @@ function ScheduleAdd({
});
}
}
delete requestData.startDate;
delete requestData.startTime;
delete requestData.endDate;
delete requestData.endTime;

const {
data: { id: scheduleId },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('<ScheduleAdd />', () => {
frequency: 'none',
interval: 1,
name: 'Run once schedule',
startDateTime: '2020-03-25T10:00:00',
startDate: '2020-03-25',
startTime: '10:00:00',
timezone: 'America/New_York',
});
});
Expand All @@ -101,7 +102,8 @@ describe('<ScheduleAdd />', () => {
interval: 10,
name: 'Run every 10 minutes 10 times',
occurrences: 10,
startDateTime: '2020-03-25T10:30:00',
startDate: '2020-03-25',
startTime: '10:30:00',
timezone: 'America/New_York',
});
});
Expand All @@ -118,11 +120,13 @@ describe('<ScheduleAdd />', () => {
wrapper.find('Formik').invoke('onSubmit')({
description: 'test description',
end: 'onDate',
endDateTime: '2020-03-26T10:45:00',
endDate: '2020-03-26',
endTime: '10:45:00',
frequency: 'hour',
interval: 1,
name: 'Run every hour until date',
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -142,7 +146,8 @@ describe('<ScheduleAdd />', () => {
frequency: 'day',
interval: 1,
name: 'Run daily',
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -164,7 +169,8 @@ describe('<ScheduleAdd />', () => {
interval: 1,
name: 'Run weekly on mon/wed/fri',
occurrences: 1,
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -186,7 +192,8 @@ describe('<ScheduleAdd />', () => {
occurrences: 1,
runOn: 'day',
runOnDayNumber: 1,
startDateTime: '2020-04-01T10:45',
startTime: '10:45',
startDate: '2020-04-01',
timezone: 'America/New_York',
});
});
Expand All @@ -203,15 +210,17 @@ describe('<ScheduleAdd />', () => {
wrapper.find('Formik').invoke('onSubmit')({
description: 'test description',
end: 'never',
endDateTime: '2020-03-26T11:00:00',
endDate: '2020-03-26',
endTime: '11:00:00',
frequency: 'month',
interval: 1,
name: 'Run monthly on the last Tuesday',
occurrences: 1,
runOn: 'the',
runOnTheDay: 'tuesday',
runOnTheOccurrence: -1,
startDateTime: '2020-03-31T11:00',
startDate: '2020-03-31',
startTime: '11:00',
timezone: 'America/New_York',
});
});
Expand All @@ -235,7 +244,8 @@ describe('<ScheduleAdd />', () => {
runOn: 'day',
runOnDayMonth: 3,
runOnDayNumber: 1,
startDateTime: '2020-03-01T00:00',
startDate: '2020-03-01',
startTime: '00:00',
timezone: 'America/New_York',
});
});
Expand All @@ -260,7 +270,8 @@ describe('<ScheduleAdd />', () => {
runOnTheOccurrence: 2,
runOnTheDay: 'friday',
runOnTheMonth: 4,
startDateTime: '2020-04-10T11:15',
startDate: '2020-04-10',
startTime: '11:15',
timezone: 'America/New_York',
});
});
Expand All @@ -285,7 +296,8 @@ describe('<ScheduleAdd />', () => {
runOnTheOccurrence: 1,
runOnTheDay: 'weekday',
runOnTheMonth: 10,
startDateTime: '2020-04-10T11:15',
startDate: '2020-04-10',
startTime: '11:15',
timezone: 'America/New_York',
});
});
Expand Down Expand Up @@ -371,7 +383,8 @@ describe('<ScheduleAdd />', () => {
wrapper.find('Formik').invoke('onSubmit')({
name: 'Schedule',
end: 'never',
endDateTime: '2021-01-29T14:15:00',
endDate: '2021-01-29',
endTime: '14:15:00',
frequency: 'none',
occurrences: 1,
runOn: 'day',
Expand All @@ -386,7 +399,8 @@ describe('<ScheduleAdd />', () => {
{ name: 'cred 1', id: 10 },
{ name: 'cred 2', id: 20 },
],
startDateTime: '2021-01-28T14:15:00',
startDate: '2021-01-28',
startTime: '14:15:00',
timezone: 'America/New_York',
});
});
Expand Down Expand Up @@ -455,7 +469,8 @@ describe('<ScheduleAdd />', () => {
frequency: 'none',
interval: 1,
name: 'Run once schedule',
startDateTime: '2020-03-25T10:00:00',
startDate: '2020-03-25',
startTime: '10:00:00',
timezone: 'America/New_York',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ function ScheduleEdit({
end,
frequency,
interval,
startDateTime,
timezone,
occurences,
runOn,
runOnTheDay,
runOnTheMonth,
runOnDayMonth,
runOnDayNumber,
endDateTime,
runOnTheOccurence,
daysOfWeek,
...submitValues
Expand Down Expand Up @@ -98,6 +96,10 @@ function ScheduleEdit({
...submitValues,
rrule: rule.toString().replace(/\n/g, ' '),
};
delete requestData.startDate;
delete requestData.startTime;
delete requestData.endDate;
delete requestData.endTime;

if (Object.keys(values).includes('daysToKeep')) {
if (!requestData.extra_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import ScheduleEdit from './ScheduleEdit';
jest.mock('../../../api');

let wrapper;

const now = new Date();
const closestQuarterHour = new Date(Math.ceil(now.getTime() / 900000) * 900000);
const tomorrow = new Date(closestQuarterHour);
tomorrow.setDate(tomorrow.getDate() + 1);
const mockSchedule = {
rrule:
'DTSTART;TZID=America/New_York:20200402T144500 RRULE:INTERVAL=1;COUNT=1;FREQ=MINUTELY',
Expand Down Expand Up @@ -200,7 +203,8 @@ describe('<ScheduleEdit />', () => {
frequency: 'none',
interval: 1,
name: 'Run once schedule',
startDateTime: '2020-03-25T10:00:00',
startDate: '2020-03-25',
startTime: '10:00:00',
timezone: 'America/New_York',
});
});
Expand All @@ -221,7 +225,8 @@ describe('<ScheduleEdit />', () => {
interval: 10,
name: 'Run every 10 minutes 10 times',
occurrences: 10,
startDateTime: '2020-03-25T10:30:00',
startDate: '2020-03-25',
startTime: '10:30:00',
timezone: 'America/New_York',
});
});
Expand All @@ -239,11 +244,13 @@ describe('<ScheduleEdit />', () => {
wrapper.find('Formik').invoke('onSubmit')({
description: 'test description',
end: 'onDate',
endDateTime: '2020-03-26T10:45:00',
endDate: '2020-03-26',
endTime: '10:45:00',
frequency: 'hour',
interval: 1,
name: 'Run every hour until date',
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -263,7 +270,8 @@ describe('<ScheduleEdit />', () => {
frequency: 'day',
interval: 1,
name: 'Run daily',
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -285,7 +293,8 @@ describe('<ScheduleEdit />', () => {
interval: 1,
name: 'Run weekly on mon/wed/fri',
occurrences: 1,
startDateTime: '2020-03-25T10:45:00',
startDate: '2020-03-25',
startTime: '10:45:00',
timezone: 'America/New_York',
});
});
Expand All @@ -308,7 +317,8 @@ describe('<ScheduleEdit />', () => {
occurrences: 1,
runOn: 'day',
runOnDayNumber: 1,
startDateTime: '2020-04-01T10:45',
startDate: '2020-04-01',
startTime: '10:45',
timezone: 'America/New_York',
});
});
Expand All @@ -334,12 +344,14 @@ describe('<ScheduleEdit />', () => {
runOn: 'the',
runOnTheDay: 'tuesday',
runOnTheOccurrence: -1,
startDateTime: '2020-03-31T11:00',
startDate: '2020-03-31',
startTime: '11:00',
timezone: 'America/New_York',
});
});
expect(SchedulesAPI.update).toHaveBeenCalledWith(27, {
description: 'test description',
endDateTime: '2020-03-26T11:00:00',
name: 'Run monthly on the last Tuesday',
extra_data: {},
occurrences: 1,
Expand All @@ -360,7 +372,8 @@ describe('<ScheduleEdit />', () => {
runOn: 'day',
runOnDayMonth: 3,
runOnDayNumber: 1,
startDateTime: '2020-03-01T00:00',
startTime: '00:00',
startDate: '2020-03-01',
timezone: 'America/New_York',
});
});
Expand All @@ -386,7 +399,8 @@ describe('<ScheduleEdit />', () => {
runOnTheOccurrence: 2,
runOnTheDay: 'friday',
runOnTheMonth: 4,
startDateTime: '2020-04-10T11:15',
startTime: '11:15',
startDate: '2020-04-10',
timezone: 'America/New_York',
});
});
Expand All @@ -413,7 +427,8 @@ describe('<ScheduleEdit />', () => {
runOnTheOccurrence: 1,
runOnTheDay: 'weekday',
runOnTheMonth: 10,
startDateTime: '2020-04-10T11:15',
startTime: '11:15',
startDate: '2020-04-10',
timezone: 'America/New_York',
});
});
Expand Down Expand Up @@ -524,7 +539,8 @@ describe('<ScheduleEdit />', () => {
wrapper.find('Formik').invoke('onSubmit')({
name: mockSchedule.name,
end: 'never',
endDateTime: '2021-01-29T14:15:00',
endDate: '2021-01-29',
endTime: '14:15:00',
frequency: 'none',
occurrences: 1,
runOn: 'day',
Expand All @@ -534,7 +550,8 @@ describe('<ScheduleEdit />', () => {
runOnTheMonth: 1,
runOnTheOccurrence: 1,
skip_tags: '',
startDateTime: '2021-01-28T14:15:00',
startDate: '2021-01-28',
startTime: '14:15:00',
timezone: 'America/New_York',
credentials: [
{ id: 3, name: 'Credential 3', kind: 'ssh', url: '' },
Expand Down Expand Up @@ -622,15 +639,18 @@ describe('<ScheduleEdit />', () => {
await act(async () =>
wrapper.find('Button[aria-label="Save"]').prop('onClick')()
);

expect(SchedulesAPI.update).toBeCalledWith(27, {
endDateTime: undefined,
startDateTime: undefined,
description: '',
extra_data: {},
occurrences: 1,
runOnTheOccurrence: 1,
name: 'foo',
inventory: 702,
rrule:
'DTSTART;TZID=America/New_York:20200402T144500 RRULE:INTERVAL=1;COUNT=1;FREQ=MINUTELY',
'DTSTART;TZID=America/New_York:20200402T184500 RRULE:INTERVAL=1;COUNT=1;FREQ=MINUTELY',
});
});
test('should submit survey with default values properly, without opening prompt wizard', async () => {
Expand Down Expand Up @@ -726,7 +746,8 @@ describe('<ScheduleEdit />', () => {
frequency: 'none',
interval: 1,
name: 'Run once schedule',
startDateTime: '2020-03-25T10:00:00',
startDate: '2020-03-25',
startTime: '10:00:00',
timezone: 'America/New_York',
});
});
Expand Down
Loading

0 comments on commit 2c7ec14

Please sign in to comment.