2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2020-09-09 17:35:22 +03:00
|
|
|
import { render, mount, CommonWrapper, ReactWrapper } from 'enzyme';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { renderToJson, mountToJson } from 'enzyme-to-json';
|
|
|
|
import { Select } from '../src';
|
2020-09-02 20:30:47 +03:00
|
|
|
import { options } from '../src/Select/options';
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Select', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2020-09-09 17:35:22 +03:00
|
|
|
const wrapper = render(
|
|
|
|
<Select
|
|
|
|
options={options}
|
|
|
|
onChange={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
expect(renderToJson(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
|
|
|
const wrapper = render(
|
|
|
|
<Select
|
|
|
|
options={options}
|
2020-09-09 17:35:22 +03:00
|
|
|
onChange={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2021-06-07 07:54:05 +03:00
|
|
|
value={options.filter((option) => option.value === 'one')}
|
|
|
|
maxMenuHeight={20}
|
|
|
|
isClearable
|
|
|
|
isDisabled
|
2019-01-03 16:00:55 +03:00
|
|
|
isLoading
|
2021-06-07 07:54:05 +03:00
|
|
|
isMulti
|
|
|
|
isSearchable={false}
|
|
|
|
menuPlacement="top"
|
2019-01-03 16:00:55 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(renderToJson(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select another option', () => {
|
|
|
|
const onChange = jest.fn();
|
2020-09-04 07:10:24 +03:00
|
|
|
const wrapper = mount(
|
|
|
|
<Select options={options} onInputChange={onChange} />
|
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
|
|
|
const input = wrapper.find('input');
|
2021-06-18 06:56:36 +03:00
|
|
|
(input.at(0).instance() as unknown as HTMLInputElement).value = 'two';
|
2019-01-03 16:00:55 +03:00
|
|
|
input.first().simulate('change');
|
|
|
|
expect(mountToJson(wrapper)).toMatchSnapshot();
|
|
|
|
input.first().simulate('keyDown', { keyCode: 13 });
|
|
|
|
expect(onChange).toBeCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't find any results", () => {
|
|
|
|
const onChange = jest.fn();
|
|
|
|
const wrapper = mount(<Select options={options} onChange={onChange} />);
|
|
|
|
|
|
|
|
const input = wrapper.find('input');
|
2021-06-18 06:56:36 +03:00
|
|
|
(input.at(0).instance() as unknown as HTMLInputElement).value = 'text';
|
2019-01-03 16:00:55 +03:00
|
|
|
input.first().simulate('change');
|
|
|
|
expect(mountToJson(wrapper)).toMatchSnapshot(); // 'No results found'
|
|
|
|
input.first().simulate('keyDown', { keyCode: 13 });
|
|
|
|
expect(onChange).not.toBeCalled();
|
|
|
|
});
|
|
|
|
});
|