/** @jest-environment jsdom */ import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import SearchableUserSelect from '@/components/SearchableUserSelect' describe('SearchableUserSelect', () => { const users = [ { id: 'user-1', username: 'moli', displayName: '魔礼红' }, { id: 'user-2', username: 'wuxie', displayName: '无邪' }, ] test('支持拼音搜索、键盘选择与标准 combobox 语义', async () => { const onChange = jest.fn() const user = userEvent.setup() render( , ) const combobox = screen.getByRole('combobox') expect(combobox).toHaveAttribute('aria-expanded', 'false') await user.click(combobox) await user.type(combobox, 'molihong') expect(combobox).toHaveAttribute('aria-expanded', 'true') expect(screen.getByRole('option', { name: /魔礼红/ })).toBeInTheDocument() expect(screen.queryByRole('option', { name: /无邪/ })).not.toBeInTheDocument() await user.keyboard('{Enter}') expect(onChange).toHaveBeenCalledWith('user-1', '魔礼红') }) test('加载期间保留已选人员并禁用交互', () => { render( , ) const combobox = screen.getByRole('combobox') expect(combobox).toBeDisabled() expect(combobox).toHaveValue('无邪 (wuxie)') expect(combobox).toHaveAttribute('aria-busy', 'true') }) })