import { render, screen } from '@testing-library/react';
import { Select } from './Select';
import styles from './Select.module.scss';
const initOptions = [
{ value: '0', label: 'first option' },
{ value: '1', label: 'second option' },
{ value: '2', label: 'third option' },
{ value: '3', label: 'fourth option' },
{ value: '4', label: 'fifth option' },
];
describe('select tests', () => {
it('renders select', () => {
render();
const select = screen.getByRole('combobox');
const options = screen.getAllByRole('option');
options.forEach((option) => expect(select).toContainElement(option));
});
it('renders select with label', () => {
const { rerender } = render();
const select = screen.getByLabelText('random text');
expect(select).toBeInTheDocument();
rerender();
const inputWrapper = screen.getByTestId('inputWrapper');
expect(inputWrapper).not.toHaveClass(styles.x);
expect(inputWrapper).toHaveClass(styles.y);
rerender();
expect(inputWrapper).toHaveStyle('grid-template-columns: 7fr 9fr');
rerender();
const tooltipWrapper = screen.getByTestId('tooltipWrapper');
const tooltipIcon = screen.getByTestId('tooltipIcon');
expect(tooltipIcon).toBeInTheDocument();
expect(screen.queryByText('random tooltip')).not.toBeInTheDocument();
expect(tooltipWrapper).toHaveAttribute('data-tooltip', 'random tooltip');
});
it('applies className to wrapper', () => {
render();
const inputWrapper = screen.getByTestId('inputWrapper');
const select = screen.getByRole('combobox');
expect(inputWrapper).toHaveClass('className');
expect(select).not.toHaveClass('className');
});
it('renders disabled select', () => {
render();
const inputWrapper = screen.getByTestId('inputWrapper');
const select = screen.getByRole('combobox');
expect(select).toBeDisabled();
expect(inputWrapper).toHaveClass('disabled');
});
it('renders large textarea with light color', () => {
render();
const select = screen.getByRole('combobox');
expect(select).toHaveClass(styles.light, styles.large);
expect(select).not.toHaveClass(styles.dark, styles.normal);
});
it('renders textarea with error', () => {
render();
const inputWrapper = screen.getByTestId('inputWrapper');
const error = screen.getByText('random error');
expect(inputWrapper).toContainElement(error);
});
it('passes ref', () => {
const ref = { current: null };
render();
const select = screen.getByRole('combobox');
expect(ref.current).toBe(select);
});
it('renders block select', () => {
render();
const select = screen.getByRole('combobox');
expect(select).toHaveClass(styles.block);
});
});