/** @vitest-environment jsdom */ import { cleanup, render, screen } from '@testing-library/react'; import { afterEach, describe, expect, it, vi } from 'vitest'; import Select from './Select'; afterEach(cleanup); const alpha = { value: 1, label: 'Alpha' }; const beta = { value: 2, label: 'Beta' }; const gamma = { value: 3, label: 'Gamma' }; describe('Select', () => { it('keeps the selected label when the option leaves a server-side search result', () => { const props = { value: 1, onChange: vi.fn(), onSearchChange: vi.fn() }; const { rerender } = render(); expect(input).toHaveValue('Alpha'); }); it('drops the remembered label once the value changes', () => { const onChange = vi.fn(); const { rerender } = render(); expect(screen.getByRole('combobox')).toHaveValue(''); }); it('keeps every selected option of a multi-select when they leave the option list', () => { const props = { multiple: true as const, value: [1, 2], onChange: vi.fn() }; const { rerender } = render(); expect(screen.getByText('2 selected')).toBeInTheDocument(); }); it('forwards the description and invalid state to the input', () => { render(