Files
awx/src/components/AnsibleSelect/AnsibleSelect.test.jsx
Marliana Lara 7b3e5cd8d5 Refactor AnsibleSelect data prop to accept an array of option objects
* First custom_virtualenv in options list is always default
2019-06-25 15:47:42 -04:00

57 lines
1.3 KiB
JavaScript

import React from 'react';
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import AnsibleSelect, { _AnsibleSelect } from './AnsibleSelect';
const mockData = [
{
label: 'Baz',
value: '/venv/baz/'
},
{
label: 'Default',
value: '/venv/ansible/'
}
];
describe('<AnsibleSelect />', () => {
test('initially renders succesfully', async () => {
mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
data={mockData}
/>
);
});
test('calls "onSelectChange" on dropdown select change', () => {
const spy = jest.spyOn(_AnsibleSelect.prototype, 'onSelectChange');
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
data={mockData}
/>
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('select').simulate('change');
expect(spy).toHaveBeenCalled();
});
test('Returns correct select options', () => {
const wrapper = mountWithContexts(
<AnsibleSelect
value="foo"
name="bar"
onChange={() => { }}
data={mockData}
/>
);
// console.log(wrapper.debug());
expect(wrapper.find('FormSelect')).toHaveLength(1);
expect(wrapper.find('FormSelectOption')).toHaveLength(2);
});
});