kafka-ui/kafka-ui-react-app/src/components/common/Select/__tests__/Select.spec.tsx
NelyDavtyan 39359bb9a9
live message tailing (#1672)
* live tailing

* addind test case

* fixing useffect array deps

* adding test cases for select

* adding test cases for filters

* deleting unused code

* adding test case for filter
2022-03-03 15:15:40 +04:00

56 lines
1.7 KiB
TypeScript

import Select, { SelectProps } from 'components/common/Select/Select';
import React from 'react';
import { render } from 'lib/testHelpers';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
jest.mock('react-hook-form', () => ({
useFormContext: () => ({
register: jest.fn(),
}),
}));
const options = [
{ label: 'test-label1', value: 'test-value1' },
{ label: 'test-label2', value: 'test-value2' },
];
const renderComponent = (props?: Partial<SelectProps>) =>
render(<Select name="test" {...props} />);
describe('Custom Select', () => {
it('renders component', () => {
renderComponent();
expect(screen.getByRole('listbox')).toBeInTheDocument();
});
it('show select options when select is being clicked', () => {
renderComponent({
options,
});
expect(screen.getByRole('option')).toBeInTheDocument();
userEvent.click(screen.getByRole('listbox'));
expect(screen.getAllByRole('option')).toHaveLength(3);
});
it('checking select option change', () => {
renderComponent({
options,
});
userEvent.click(screen.getByRole('listbox'));
userEvent.selectOptions(screen.getByRole('listbox'), ['test-label1']);
expect(screen.getByRole('option')).toHaveTextContent('test-label1');
});
describe('when non-live', () => {
it('there is not live icon', () => {
renderComponent({ isLive: false });
expect(screen.queryByTestId('liveIcon')).not.toBeInTheDocument();
});
});
describe('when live', () => {
it('there is live icon', () => {
renderComponent({ isLive: true });
expect(screen.getByTestId('liveIcon')).toBeInTheDocument();
});
});
});