import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { describe, it, expect, vi } from 'vitest'; import { ComboboxPanel } from './ComboboxPanel'; import { voidFunction } from '../../../../utils/function'; describe('Panel', () => { const options = [ { id: '1', value: 'Option 1' }, { id: '2', value: 'Option 2' }, { id: '3', value: 'Option 3' }, ]; const optionRenderer = ({ option }: any) =>
{option.value}
; it('renders null when expanded is false', () => { render( ); expect(screen.queryByRole('option')).not.toBeInTheDocument(); }); it('renders the options when expanded is true', () => { render( ); expect(screen.getByRole('listbox')).toBeInTheDocument(); options.forEach((option) => { expect(screen.getByText(option.value)).toBeInTheDocument(); }); }); // it('renders the selected option with the "selected" class', () => { // render( // {}} // /> // ); // expect(screen.getByRole('listbox')).toBeInTheDocument(); // options.forEach((option, index) => { // const optionElement = screen.getByText(option.value); // if (index === 1) { // expect(optionElement).toHaveClass('selected'); // } else { // expect(optionElement).not.toHaveClass('selected'); // } // }); // }); it('calls onSelect when an option is clicked', async () => { const handleSelect = vi.fn(); render( ); expect(screen.getByRole('listbox')).toBeInTheDocument(); const option = screen.getByText('Option 2'); await userEvent.click(option); expect(handleSelect).toHaveBeenCalledWith('1'); }); });