1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00
awx/__tests__/components/AnsibleSelect.test.jsx

57 lines
1.5 KiB
React
Raw Normal View History

import React from 'react';
import { mount } from 'enzyme';
2019-02-20 00:14:28 +03:00
import { I18nProvider } from '@lingui/react';
import AnsibleSelect from '../../src/components/AnsibleSelect';
2019-01-24 21:05:36 +03:00
const label = 'test select';
const mockData = ['/venv/baz/', '/venv/ansible/'];
describe('<AnsibleSelect />', () => {
test('initially renders succesfully', async () => {
mount(
2019-02-20 00:14:28 +03:00
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
</I18nProvider>
);
});
test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mount(
2019-02-20 00:14:28 +03:00
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
/>
</I18nProvider>
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('select').simulate('change');
expect(spy).toHaveBeenCalled();
});
test('Returns correct select options if defaultSelected props is passed', () => {
const wrapper = mount(
2019-02-20 00:14:28 +03:00
<I18nProvider>
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
label={label}
data={mockData}
defaultSelected={mockData[1]}
/>
</I18nProvider>
);
expect(wrapper.find('FormSelect')).toHaveLength(1);
});
});