mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
update tests to check for PF Select
This commit is contained in:
parent
1289ca9103
commit
1cc4e302f9
@ -3,19 +3,22 @@ import { mount } from 'enzyme';
|
||||
import TagMultiSelect from './TagMultiSelect';
|
||||
|
||||
describe('<TagMultiSelect />', () => {
|
||||
it('should render MultiSelect', () => {
|
||||
it('should render Select', () => {
|
||||
const wrapper = mount(
|
||||
<TagMultiSelect value="foo,bar" onChange={jest.fn()} />
|
||||
);
|
||||
expect(wrapper.find('MultiSelect').prop('options')).toEqual([
|
||||
{ id: 'foo', name: 'foo' },
|
||||
{ id: 'bar', name: 'bar' },
|
||||
]);
|
||||
wrapper.find('input').simulate('focus');
|
||||
const options = wrapper.find('SelectOption');
|
||||
expect(options).toHaveLength(2);
|
||||
expect(options.at(0).prop('value')).toEqual('foo');
|
||||
expect(options.at(1).prop('value')).toEqual('bar');
|
||||
});
|
||||
|
||||
it('should not treat empty string as an option', () => {
|
||||
const wrapper = mount(<TagMultiSelect value="" onChange={jest.fn()} />);
|
||||
expect(wrapper.find('MultiSelect').prop('options')).toEqual([]);
|
||||
wrapper.find('input').simulate('focus');
|
||||
expect(wrapper.find('Select').prop('isExpanded')).toEqual(true);
|
||||
expect(wrapper.find('SelectOption')).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should trigger onChange', () => {
|
||||
@ -23,13 +26,9 @@ describe('<TagMultiSelect />', () => {
|
||||
const wrapper = mount(
|
||||
<TagMultiSelect value="foo,bar" onChange={onChange} />
|
||||
);
|
||||
wrapper.find('input').simulate('focus');
|
||||
|
||||
const select = wrapper.find('MultiSelect');
|
||||
select.invoke('onChange')([
|
||||
{ name: 'foo' },
|
||||
{ name: 'bar' },
|
||||
{ name: 'baz' },
|
||||
]);
|
||||
wrapper.find('Select').invoke('onSelect')(null, 'baz');
|
||||
expect(onChange).toHaveBeenCalledWith('foo,bar,baz');
|
||||
});
|
||||
});
|
||||
|
||||
@ -19,12 +19,16 @@ describe('<LabelSelect />', () => {
|
||||
});
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mount(<LabelSelect value={[]} onError={() => {}} />);
|
||||
wrapper = mount(
|
||||
<LabelSelect value={[]} onError={() => {}} onChange={() => {}} />
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
|
||||
expect(LabelsAPI.read).toHaveBeenCalledTimes(1);
|
||||
expect(wrapper.find('MultiSelect').prop('options')).toEqual(options);
|
||||
wrapper.find('input').simulate('focus');
|
||||
const selectOptions = wrapper.find('SelectOption');
|
||||
expect(selectOptions).toHaveLength(2);
|
||||
expect(selectOptions.at(0).prop('value')).toEqual(options[0]);
|
||||
expect(selectOptions.at(1).prop('value')).toEqual(options[1]);
|
||||
});
|
||||
|
||||
test('should fetch two pages labels if present', async () => {
|
||||
@ -36,19 +40,20 @@ describe('<LabelSelect />', () => {
|
||||
});
|
||||
LabelsAPI.read.mockReturnValueOnce({
|
||||
data: {
|
||||
results: options,
|
||||
results: [{ id: 3, name: 'three' }, { id: 4, name: 'four' }],
|
||||
},
|
||||
});
|
||||
let wrapper;
|
||||
await act(async () => {
|
||||
wrapper = mount(<LabelSelect value={[]} onError={() => {}} />);
|
||||
wrapper = mount(
|
||||
<LabelSelect value={[]} onError={() => {}} onChange={() => {}} />
|
||||
);
|
||||
});
|
||||
wrapper.update();
|
||||
|
||||
expect(LabelsAPI.read).toHaveBeenCalledTimes(2);
|
||||
expect(wrapper.find('MultiSelect').prop('options')).toEqual([
|
||||
...options,
|
||||
...options,
|
||||
]);
|
||||
wrapper.find('input').simulate('focus');
|
||||
const selectOptions = wrapper.find('SelectOption');
|
||||
expect(selectOptions).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user