mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
write LabelSelect tests
This commit is contained in:
@@ -1,9 +1,53 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
|
import { LabelsAPI } from '@api';
|
||||||
|
import { sleep} from '@testUtils/testUtils';
|
||||||
import LabelSelect from './LabelSelect';
|
import LabelSelect from './LabelSelect';
|
||||||
|
|
||||||
|
jest.mock('@api');
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{ id: 1, name: 'one' },
|
||||||
|
{ id: 2, name: 'two' },
|
||||||
|
];
|
||||||
|
|
||||||
describe('<LabelSelect />', () => {
|
describe('<LabelSelect />', () => {
|
||||||
test('should', () => {
|
afterEach(() => {
|
||||||
wrapper = mount(<LabelSelect />);
|
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
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ describe('<PlaybookSelect />', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
})
|
||||||
|
|
||||||
test('should reload playbooks when project value changes', () => {
|
test('should reload playbooks when project value changes', () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<PlaybookSelect
|
<PlaybookSelect
|
||||||
|
|||||||
Reference in New Issue
Block a user