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
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
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"
|
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
|
|
|
});
|
|
|
|
|
|
|
|
it('should select another option', () => {
|
|
|
|
const onChange = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
|
|
|
<Select options={options} onChange={onChange} />
|
2020-09-04 07:10:24 +03:00
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2021-10-22 07:18:03 +03:00
|
|
|
userEvent.type(screen.getByRole('combobox'), 'two');
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
|
|
userEvent.type(screen.getByRole('combobox'), '{enter}');
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't find any results", () => {
|
|
|
|
const onChange = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
|
|
|
<Select options={options} onChange={onChange} />
|
|
|
|
);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2021-10-22 07:18:03 +03:00
|
|
|
userEvent.type(screen.getByRole('combobox'), 'text');
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
|
|
userEvent.type(screen.getByRole('combobox'), '{enter}');
|
|
|
|
expect(onChange).not.toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|