import React from 'react';
import {mount, shallow} from 'enzyme';
import SelectControl from 'app/components/forms/selectControl';
describe('SelectControl', function() {
it('renders with react-select "options"', function() {
const wrapper = shallow();
expect(wrapper.find('StyledSelect').prop('options')).toEqual([
{value: 'foo', label: 'Foo'},
]);
});
it('renders with react-select "multi"', function() {
let wrapper = shallow();
expect(wrapper.find('StyledSelect').prop('multi')).toEqual(true);
wrapper = shallow();
expect(wrapper.find('StyledSelect').prop('multi')).toEqual(true);
wrapper = shallow();
expect(wrapper.find('StyledSelect').prop('multi')).toBeUndefined();
});
it('renders with select2 flat "choices"', function() {
const wrapper = shallow();
expect(wrapper.find('StyledSelect').prop('options')).toEqual([
{value: 'a', label: 'a'},
{value: 'b', label: 'b'},
{value: 'c', label: 'c'},
]);
});
it('renders with select2 paired "choices"', function() {
const wrapper = shallow(
);
expect(wrapper.find('StyledSelect').prop('options')).toEqual([
{value: 'a', label: 'abc'},
{value: 'b', label: 'bcd'},
{value: 'c', label: 'cde'},
]);
});
it('renders with complex objects with paired "choices"', function() {
const mock = jest.fn();
const Foo =
Foo
;
const Bar = Bar
;
const wrapper = mount(
);
expect(wrapper.find('StyledSelect').prop('options')).toEqual([
{value: {id: 'foo', name: 'Foo'}, label: Foo},
{value: {id: 'bar', name: 'Bar'}, label: Bar},
]);
wrapper.find('input').simulate('focus');
wrapper.find('.Select-control').simulate('mouseDown', {button: 0});
expect(
wrapper
.find('div.Select-option')
.first()
.prop('children')
).toEqual(Foo);
wrapper
.find('Option')
.first()
.simulate('mouseDown');
expect(mock).toHaveBeenCalledWith({
value: {id: 'foo', name: 'Foo'},
label: Foo,
});
});
});