2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
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';
|
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', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Select
|
|
|
|
options={options}
|
|
|
|
onChange={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2019-01-03 16:00:55 +03:00
|
|
|
<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"
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should select another option', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onChange = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2023-07-12 21:03:20 +03:00
|
|
|
<Select options={options} onChange={onChange} />,
|
2020-09-04 07:10:24 +03:00
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.type(screen.getByRole('combobox'), 'two');
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.type(screen.getByRole('combobox'), '{enter}');
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onChange).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it("shouldn't find any results", async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onChange = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2023-07-12 21:03:20 +03:00
|
|
|
<Select options={options} onChange={onChange} />,
|
2021-10-22 07:18:03 +03:00
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.type(screen.getByRole('combobox'), 'text');
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.type(screen.getByRole('combobox'), '{enter}');
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onChange).not.toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|