-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #32045 - Add start-end date pickers to job wizard #567
Merged
adamruzicka
merged 1 commit into
theforeman:master
from
MariaAga:add-schedule-job-wizard-datepicker
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import React, { useState } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormGroup, Radio } from '@patternfly/react-core'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
|
||
export const ScheduleType = () => { | ||
const [isFuture, setIsFuture] = useState(false); | ||
return ( | ||
<FormGroup label={__('Schedule type')} fieldId="schedule-type"> | ||
<Radio | ||
isChecked={!isFuture} | ||
name="schedule-type" | ||
onChange={() => setIsFuture(false)} | ||
id="schedule-type-now" | ||
label={__('Execute now')} | ||
/> | ||
<Radio | ||
isChecked={isFuture} | ||
name="schedule-type" | ||
onChange={() => setIsFuture(true)} | ||
id="schedule-type-future" | ||
label={__('Schedule for future execution')} | ||
/> | ||
</FormGroup> | ||
); | ||
export const ScheduleType = ({ isFuture, setIsFuture }) => ( | ||
<FormGroup label={__('Schedule type')} fieldId="schedule-type"> | ||
<Radio | ||
isChecked={!isFuture} | ||
name="schedule-type" | ||
onChange={() => setIsFuture(false)} | ||
id="schedule-type-now" | ||
label={__('Execute now')} | ||
/> | ||
<Radio | ||
isChecked={isFuture} | ||
name="schedule-type" | ||
onChange={() => setIsFuture(true)} | ||
id="schedule-type-future" | ||
label={__('Schedule for future execution')} | ||
/> | ||
</FormGroup> | ||
); | ||
|
||
ScheduleType.propTypes = { | ||
isFuture: PropTypes.bool.isRequired, | ||
setIsFuture: PropTypes.func.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
webpack/JobWizard/steps/Schedule/__tests__/Schedule.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { fireEvent, screen, render, act } from '@testing-library/react'; | ||
import * as api from 'foremanReact/redux/API'; | ||
import { JobWizard } from '../../../JobWizard'; | ||
import * as selectors from '../../../JobWizardSelectors'; | ||
import { jobTemplate, jobTemplateResponse } from '../../../__tests__/fixtures'; | ||
|
||
const lodash = require('lodash'); | ||
|
||
lodash.debounce = fn => fn; | ||
jest.spyOn(api, 'get'); | ||
jest.spyOn(selectors, 'selectJobTemplate'); | ||
jest.spyOn(selectors, 'selectJobTemplates'); | ||
jest.spyOn(selectors, 'selectJobCategories'); | ||
|
||
const jobCategories = ['Ansible Commands', 'Puppet', 'Services']; | ||
|
||
selectors.selectJobCategories.mockImplementation(() => jobCategories); | ||
|
||
selectors.selectJobTemplates.mockImplementation(() => [ | ||
jobTemplate, | ||
{ ...jobTemplate, id: 2, name: 'template2' }, | ||
]); | ||
selectors.selectJobTemplate.mockImplementation(() => jobTemplateResponse); | ||
api.get.mockImplementation(({ handleSuccess, ...action }) => { | ||
if (action.key === 'JOB_CATEGORIES') { | ||
handleSuccess && handleSuccess({ data: { job_categories: jobCategories } }); | ||
} else if (action.key === 'JOB_TEMPLATE') { | ||
handleSuccess && | ||
handleSuccess({ | ||
data: jobTemplateResponse, | ||
}); | ||
} else if (action.key === 'JOB_TEMPLATES') { | ||
handleSuccess && | ||
handleSuccess({ | ||
data: { results: [jobTemplateResponse.job_template] }, | ||
}); | ||
} | ||
return { type: 'get', ...action }; | ||
}); | ||
|
||
const mockStore = configureMockStore([]); | ||
const store = mockStore({}); | ||
jest.useFakeTimers(); | ||
|
||
describe('Schedule', () => { | ||
it('should save date time between steps ', async () => { | ||
render( | ||
<Provider store={store}> | ||
<JobWizard /> | ||
</Provider> | ||
); | ||
await act(async () => { | ||
fireEvent.click(screen.getByText('Schedule')); | ||
}); | ||
const newStartDate = '2020/03/12'; | ||
const newStartTime = '12:03'; | ||
const newEndsDate = '2030/03/12'; | ||
const newEndsTime = '17:34'; | ||
const [startsDateField, endsDateField] = screen.getAllByPlaceholderText( | ||
'yyyy/mm/dd' | ||
); | ||
const [startsTimeField, endsTimeField] = screen.getAllByPlaceholderText( | ||
'hh:mm' | ||
); | ||
await act(async () => { | ||
await fireEvent.change(startsDateField, { | ||
target: { value: newStartDate }, | ||
}); | ||
await fireEvent.change(startsTimeField, { | ||
target: { value: newStartTime }, | ||
}); | ||
await fireEvent.change(endsDateField, { target: { value: newEndsDate } }); | ||
await fireEvent.change(endsTimeField, { target: { value: newEndsTime } }); | ||
jest.runAllTimers(); // to handle pf4 date picket popover useTimer | ||
}); | ||
await act(async () => { | ||
fireEvent.click(screen.getByText('Category and Template')); | ||
}); | ||
expect(screen.getAllByText('Category and Template')).toHaveLength(3); | ||
|
||
await act(async () => { | ||
fireEvent.click(screen.getByText('Schedule')); | ||
jest.runAllTimers(); | ||
}); | ||
expect(startsDateField.value).toBe(newStartDate); | ||
expect(startsTimeField.value).toBe(newStartTime); | ||
expect(endsDateField.value).toBe(newEndsDate); | ||
expect(endsTimeField.value).toBe(newEndsTime); | ||
}); | ||
it('should remove start date time on execute now', async () => { | ||
render( | ||
<Provider store={store}> | ||
<JobWizard /> | ||
</Provider> | ||
); | ||
await act(async () => { | ||
fireEvent.click(screen.getByText('Schedule')); | ||
}); | ||
const executeNow = screen.getByLabelText('Execute now'); | ||
const executeFuture = screen.getByLabelText( | ||
'Schedule for future execution' | ||
); | ||
expect(executeNow.checked).toBeTruthy(); | ||
const newStartDate = '2020/03/12'; | ||
const newStartTime = '12:03'; | ||
const [startsDateField] = screen.getAllByPlaceholderText('yyyy/mm/dd'); | ||
const [startsTimeField] = screen.getAllByPlaceholderText('hh:mm'); | ||
await act(async () => { | ||
await fireEvent.change(startsDateField, { | ||
target: { value: newStartDate }, | ||
}); | ||
await fireEvent.change(startsTimeField, { | ||
target: { value: newStartTime }, | ||
}); | ||
await jest.runOnlyPendingTimers(); | ||
}); | ||
expect(startsDateField.value).toBe(newStartDate); | ||
expect(startsTimeField.value).toBe(newStartTime); | ||
expect(executeFuture.checked).toBeTruthy(); | ||
await act(async () => { | ||
await fireEvent.click(executeNow); | ||
}); | ||
expect(executeNow.checked).toBeTruthy(); | ||
expect(startsDateField.value).toBe(''); | ||
expect(startsTimeField.value).toBe(''); | ||
}); | ||
|
||
it('should disable end date on never ends', async () => { | ||
render( | ||
<Provider store={store}> | ||
<JobWizard /> | ||
</Provider> | ||
); | ||
await act(async () => { | ||
await fireEvent.click(screen.getByText('Schedule')); | ||
jest.runAllTimers(); | ||
}); | ||
const neverEnds = screen.getByLabelText('Never ends'); | ||
expect(neverEnds.checked).toBeFalsy(); | ||
|
||
const [, endsDateField] = screen.getAllByPlaceholderText('yyyy/mm/dd'); | ||
const [, endsTimeField] = screen.getAllByPlaceholderText('hh:mm'); | ||
expect(endsDateField.disabled).toBeFalsy(); | ||
expect(endsTimeField.disabled).toBeFalsy(); | ||
await act(async () => { | ||
fireEvent.click(neverEnds); | ||
}); | ||
expect(neverEnds.checked).toBeTruthy(); | ||
expect(endsDateField.disabled).toBeTruthy(); | ||
expect(endsTimeField.disabled).toBeTruthy(); | ||
}); | ||
}); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test!