add tests for select

This commit is contained in:
Pavel Mineev
2021-08-08 14:25:10 -05:00
committed by Umputun
parent 7317d46699
commit 718ad691c0
2 changed files with 46 additions and 0 deletions
@@ -0,0 +1,46 @@
import '@testing-library/jest-dom';
import { h } from 'preact';
import { render } from 'tests/utils';
import { Select } from './select';
const items = [
{
label: 'None',
value: 'none',
},
{
label: 'Oldest',
value: 'oldest',
},
{
label: 'Newest',
value: 'newest',
},
{
label: 'Best',
value: 'best',
},
{
label: 'Worst',
value: 'worst',
},
];
describe('<Select/>', () => {
it('should has static class names', () => {
const { container } = render(<Select items={items} selected={items[0]} />);
expect(container.querySelector('.select')).toBeInTheDocument();
expect(container.querySelector('.select-arrow')).toBeInTheDocument();
expect(container.querySelector('.select-element')).toBeInTheDocument();
});
it('should render selected item', () => {
const { container, getAllByText } = render(<Select items={items} selected={items[0]} />);
const selectedOption = container.querySelectorAll('option')[0];
expect(getAllByText(items[0].label)).toHaveLength(2);
expect(selectedOption.selected).toBeTruthy();
expect(selectedOption.textContent).toBe(items[0].label);
});
});