redux-devtools/packages/redux-devtools-ui/test/Select.test.tsx

64 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2019-01-03 16:00:55 +03:00
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 { container } = render(
<Select
options={options}
onChange={() => {
// noop
}}
/>,
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('renders with props', () => {
const { container } = render(
2019-01-03 16:00:55 +03:00
<Select
options={options}
onChange={() => {
// noop
}}
value={options.filter((option) => option.value === 'one')}
maxMenuHeight={20}
isClearable
isDisabled
2019-01-03 16:00:55 +03:00
isLoading
isMulti
isSearchable={false}
menuPlacement="top"
/>,
2019-01-03 16:00:55 +03:00
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('should select another option', async () => {
2019-01-03 16:00:55 +03:00
const onChange = jest.fn();
const { container } = render(
<Select options={options} onChange={onChange} />,
);
2019-01-03 16:00:55 +03:00
await userEvent.type(screen.getByRole('combobox'), 'two');
expect(container.firstChild).toMatchSnapshot();
await userEvent.type(screen.getByRole('combobox'), '{enter}');
expect(onChange).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
it("shouldn't find any results", async () => {
2019-01-03 16:00:55 +03:00
const onChange = jest.fn();
const { container } = render(
<Select options={options} onChange={onChange} />,
);
2019-01-03 16:00:55 +03:00
await userEvent.type(screen.getByRole('combobox'), 'text');
expect(container.firstChild).toMatchSnapshot();
await userEvent.type(screen.getByRole('combobox'), '{enter}');
expect(onChange).not.toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
});