tests: category select component

This commit is contained in:
Nicolas Meienberger 2023-04-13 23:32:50 +02:00 committed by Nicolas Meienberger
parent 41863f364a
commit 4a9fed80ff

View file

@ -0,0 +1,44 @@
import React from 'react';
import CategorySelector from './CategorySelector';
import { fireEvent, render, screen } from '../../../../../../tests/test-utils';
describe('Test: CategorySelector', () => {
it('should render without crashing', () => {
// arrange
const onSelect = jest.fn();
const className = 'test-class';
// act
render(<CategorySelector onSelect={onSelect} className={className} />);
// assert
expect(screen.getByRole('combobox')).toBeInTheDocument();
});
it('should call onSelect when an option is selected', () => {
// arrange
const onSelect = jest.fn();
const className = 'test-class';
render(<CategorySelector onSelect={onSelect} className={className} />);
const combobox = screen.getByRole('combobox');
// act
fireEvent.input(combobox, { target: { value: 'automation' } });
const listItem = screen.getByText('Automation');
fireEvent.click(listItem);
// assert
expect(onSelect).toHaveBeenCalledWith('automation');
});
it('should set the initial value when provided', () => {
// arrange
const onSelect = jest.fn();
const className = 'test-class';
render(<CategorySelector onSelect={onSelect} className={className} initialValue="automation" />);
// assert
expect(screen.getByText('Automation')).toBeInTheDocument();
});
});