mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
add basic test coverage for job list
This commit is contained in:
@@ -25,7 +25,7 @@ const QS_CONFIG = getQSConfig('job', {
|
|||||||
not__launch_type: 'sync',
|
not__launch_type: 'sync',
|
||||||
});
|
});
|
||||||
|
|
||||||
class JobsList extends Component {
|
class JobList extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -178,5 +178,5 @@ class JobsList extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { JobsList as _JobsList };
|
export { JobList as _JobList };
|
||||||
export default withI18n()(withRouter(JobsList));
|
export default withI18n()(withRouter(JobList));
|
||||||
|
|||||||
83
src/screens/Job/JobList/JobList.test.jsx
Normal file
83
src/screens/Job/JobList/JobList.test.jsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||||
|
|
||||||
|
import { UnifiedJobsAPI } from '@api';
|
||||||
|
import JobList from './JobList';
|
||||||
|
|
||||||
|
jest.mock('@api');
|
||||||
|
|
||||||
|
const mockResults = [{
|
||||||
|
id: 1,
|
||||||
|
url: '/api/v2/project_updates/1',
|
||||||
|
name: 'job 1',
|
||||||
|
type: 'project update',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {
|
||||||
|
delete: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
url: '/api/v2/jobs/2',
|
||||||
|
name: 'job 2',
|
||||||
|
type: 'job',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {
|
||||||
|
delete: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
id: 3,
|
||||||
|
url: '/api/v2/jobs/3',
|
||||||
|
name: 'job 3',
|
||||||
|
type: 'job',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {
|
||||||
|
delete: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
UnifiedJobsAPI.read.mockResolvedValue({ data: { count: 3, results: mockResults } });
|
||||||
|
|
||||||
|
describe('<JobList />', () => {
|
||||||
|
test('initially renders succesfully', async (done) => {
|
||||||
|
const wrapper = mountWithContexts(<JobList />);
|
||||||
|
await waitForElement(wrapper, 'JobList', (el) => el.state('jobs').length === 3);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('select makes expected state updates', async (done) => {
|
||||||
|
const [mockItem] = mockResults;
|
||||||
|
const wrapper = mountWithContexts(<JobList />);
|
||||||
|
await waitForElement(wrapper, 'JobListItem', (el) => el.length === 3);
|
||||||
|
|
||||||
|
wrapper.find('JobListItem').first().prop('onSelect')(mockItem);
|
||||||
|
expect(wrapper.find('JobList').state('selected').length).toEqual(1);
|
||||||
|
|
||||||
|
wrapper.find('JobListItem').first().prop('onSelect')(mockItem);
|
||||||
|
expect(wrapper.find('JobList').state('selected').length).toEqual(0);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('select-all-delete makes expected state updates and api calls', async (done) => {
|
||||||
|
const wrapper = mountWithContexts(<JobList />);
|
||||||
|
await waitForElement(wrapper, 'JobListItem', (el) => el.length === 3);
|
||||||
|
|
||||||
|
wrapper.find('DataListToolbar').prop('onSelectAll')(true);
|
||||||
|
expect(wrapper.find('JobList').state('selected').length).toEqual(3);
|
||||||
|
|
||||||
|
wrapper.find('DataListToolbar').prop('onSelectAll')(false);
|
||||||
|
expect(wrapper.find('JobList').state('selected').length).toEqual(0);
|
||||||
|
|
||||||
|
wrapper.find('DataListToolbar').prop('onSelectAll')(true);
|
||||||
|
expect(wrapper.find('JobList').state('selected').length).toEqual(3);
|
||||||
|
|
||||||
|
wrapper.find('ToolbarDeleteButton').prop('onDelete')();
|
||||||
|
expect(UnifiedJobsAPI.destroy).toHaveBeenCalledTimes(3);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
27
src/screens/Job/JobList/JobListItem.test.jsx
Normal file
27
src/screens/Job/JobList/JobListItem.test.jsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { createMemoryHistory } from 'history';
|
||||||
|
|
||||||
|
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||||
|
|
||||||
|
import JobListItem from './JobListItem';
|
||||||
|
|
||||||
|
describe('<JobListItem />', () => {
|
||||||
|
test('initially renders succesfully', () => {
|
||||||
|
const history = createMemoryHistory({
|
||||||
|
initialEntries: ['/jobs'],
|
||||||
|
});
|
||||||
|
mountWithContexts(
|
||||||
|
<JobListItem
|
||||||
|
job={{
|
||||||
|
id: 1,
|
||||||
|
name: 'Job',
|
||||||
|
type: 'project update'
|
||||||
|
}}
|
||||||
|
detailUrl="/organization/1"
|
||||||
|
isSelected
|
||||||
|
onSelect={() => {}}
|
||||||
|
/>,
|
||||||
|
{ context: { router: { history } } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
export { default as JobList } from './JobList';
|
export { default as JobList } from './JobList';
|
||||||
export { default as JobListItem } from './JobListItem';
|
export { default as JobListItem } from './JobListItem';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user