write LabelSelect tests

This commit is contained in:
Keith Grant 2019-09-27 15:30:42 -07:00
parent da149d931c
commit 554a63d8fc
2 changed files with 51 additions and 3 deletions

View File

@ -1,9 +1,53 @@
import React from 'react';
import { mount } from 'enzyme';
import { LabelsAPI } from '@api';
import { sleep} from '@testUtils/testUtils';
import LabelSelect from './LabelSelect';
jest.mock('@api');
const options = [
{ id: 1, name: 'one' },
{ id: 2, name: 'two' },
];
describe('<LabelSelect />', () => {
test('should', () => {
wrapper = mount(<LabelSelect />);
})
afterEach(() => {
jest.resetAllMocks();
});
test('should fetch labels', async () => {
LabelsAPI.read.mockReturnValue({
data: { results: options },
});
const wrapper = mount(<LabelSelect value={[]} />);
await sleep(1);
wrapper.update();
expect(LabelsAPI.read).toHaveBeenCalledTimes(1);
expect(wrapper.find('MultiSelect').prop('options')).toEqual(options);
});
test('should fetch two pages labels if present', async () => {
LabelsAPI.read.mockReturnValueOnce({
data: {
results: options,
next: '/foo?page=2',
},
});
LabelsAPI.read.mockReturnValueOnce({
data: {
results: options,
},
});
const wrapper = mount(<LabelSelect value={[]} />);
await sleep(1);
wrapper.update();
expect(LabelsAPI.read).toHaveBeenCalledTimes(2);
expect(wrapper.find('MultiSelect').prop('options')).toEqual([
...options,
...options
]);
});
});

View File

@ -12,6 +12,10 @@ describe('<PlaybookSelect />', () => {
});
});
afterEach(() => {
jest.resetAllMocks();
})
test('should reload playbooks when project value changes', () => {
const wrapper = mountWithContexts(
<PlaybookSelect