/** * @file Select.test.tsx * @description The shared Select as a WAI-ARIA listbox button: expanded state, * listbox/option roles with aria-selected, aria-activedescendant tracking, * Arrow/Home/End/Enter/Escape/type-ahead, focus back on the trigger, and a * list that flips up by the room in its split pane, not the window's. * @author Nguyễn Ngọc Trí Vĩ */ import { describe, it, expect, vi } from "vitest"; import { fireEvent, render, screen } from "@testing-library/react"; import { Select } from "../Select"; const OPTIONS = [ { value: "a", label: "Apple" }, { value: "b", label: "Banana" }, { value: "c", label: "Cherry" }, { value: "d", label: "Blueberry" }, ]; function setup(value = "b") { const onChange = vi.fn(); render( {}} options={OPTIONS} label="Fruit" /> ); // A top pane 0–400 in a 2000px window; the trigger near its bottom. vi.spyOn(screen.getByTestId("pane"), "getBoundingClientRect").mockReturnValue(rect(0, 400)); const button = screen.getByRole("button", { name: "Fruit" }); vi.spyOn(button, "getBoundingClientRect").mockReturnValue(rect(360, 380)); vi.stubGlobal("innerHeight", 2000); fireEvent.click(button); expect(screen.getByRole("listbox").className).toContain("bottom-full"); vi.unstubAllGlobals(); }); });