add basic test coverage for job list

This commit is contained in:
Jake McDermott 2019-06-21 11:24:35 -04:00
parent 22dbe5c0f9
commit 69426dee08
4 changed files with 113 additions and 4 deletions

View File

@ -25,7 +25,7 @@ const QS_CONFIG = getQSConfig('job', {
not__launch_type: 'sync',
});
class JobsList extends Component {
class JobList extends Component {
constructor (props) {
super(props);
@ -178,5 +178,5 @@ class JobsList extends Component {
}
}
export { JobsList as _JobsList };
export default withI18n()(withRouter(JobsList));
export { JobList as _JobList };
export default withI18n()(withRouter(JobList));

View 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();
});
});

View 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 } } }
);
});
});

View File

@ -1,3 +1,2 @@
export { default as JobList } from './JobList';
export { default as JobListItem } from './JobListItem';