import { describe, it, expect, vi } from "vitest"; import { render, screen, fireEvent } from "@testing-library/react"; import { Dropdown } from "../../src/components/Dropdown"; import { FilterSheet } from "../../src/components/FilterSheet"; function TestDropdown() { return ( ( )} > {() =>
option
}
); } describe("Dropdown", () => { it("closes on Escape", () => { render(); fireEvent.click(screen.getByText("trigger")); expect(screen.getByTestId("dropdown-panel")).toBeInTheDocument(); fireEvent.keyDown(document.body, { key: "Escape" }); expect(screen.queryByTestId("dropdown-panel")).not.toBeInTheDocument(); }); it("Escape closes only the open dropdown, not the sheet underneath", () => { // regression: Escape in an open dropdown inside the mobile FilterSheet closed both layers const onClose = vi.fn(); render( , ); fireEvent.click(screen.getByText("trigger")); expect(screen.getByTestId("dropdown-panel")).toBeInTheDocument(); fireEvent.keyDown(document.body, { key: "Escape" }); expect(screen.queryByTestId("dropdown-panel")).not.toBeInTheDocument(); expect(onClose).not.toHaveBeenCalled(); // with the dropdown closed, Escape reaches the sheet fireEvent.keyDown(document.body, { key: "Escape" }); expect(onClose).toHaveBeenCalledTimes(1); }); });