// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { ChatMentionAutocomplete } from "./ChatMentionAutocomplete"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) })); describe("ChatMentionAutocomplete", () => { it("renders grouped accessible options and delegates pointer selection", () => { const onSelect = vi.fn(); const onActiveIndexChange = vi.fn(); render( ); expect(screen.getByRole("listbox", { name: "chat.mention.label" })).toBeInTheDocument(); expect(screen.getAllByRole("option")[1]).toHaveAttribute("aria-selected", "true"); fireEvent.mouseEnter(screen.getAllByRole("option")[0]!); expect(onActiveIndexChange).toHaveBeenCalledWith(0); fireEvent.click(screen.getByRole("option", { name: /Ada/ })); expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ kind: "user", id: "user_1" })); }); it("announces loading and empty states", () => { const { rerender } = render( ); expect(screen.getByLabelText("chat.mention.loading")).toBeInTheDocument(); rerender( ); expect(screen.getByText("chat.mention.empty")).toBeInTheDocument(); }); });