redux-devtools/packages/devui/tests/Select.test.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
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';
import { options } from '../src/Select/options';
2019-01-03 16:00:55 +03:00
describe('Select', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
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}
onChange={() => {
// noop
}}
2019-01-03 16:00:55 +03:00
value="one"
menuMaxHeight={20}
clearable
disabled
isLoading
multi
searchable={false}
openOuterUp
/>
);
expect(renderToJson(wrapper)).toMatchSnapshot();
});
it('should select another option', () => {
const onChange = jest.fn();
const wrapper = mount(
<Select options={options} onInputChange={onChange} />
);
2019-01-03 16:00:55 +03:00
const input = wrapper.find('input');
((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');
((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();
});
});