// @vitest-environment jsdom import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it } from "vitest"; import { Button, Tooltip } from "../../src/presentation/design-system/index.ts"; describe("Tooltip", () => { it("describes the focusable trigger itself", async () => { const user = userEvent.setup(); render( <>

Existing hint

, ); await user.tab(); const trigger = screen.getByRole("button", { name: "Help" }); expect(trigger).toHaveFocus(); expect(trigger).toHaveAccessibleDescription("Existing hint Optional detail"); }); it("closes with Escape and opens again on the next focus", async () => { const user = userEvent.setup(); render( <> , ); await user.tab(); const tooltip = screen.getByRole("tooltip"); expect(tooltip).toBeVisible(); await user.keyboard("{Escape}"); expect(tooltip).not.toBeVisible(); expect(screen.getByRole("button", { name: "Help" })).toHaveFocus(); await user.tab(); await user.tab({ shift: true }); expect(screen.getByRole("tooltip")).toBeVisible(); }); it("closes a hovered tooltip with Escape", async () => { const user = userEvent.setup(); render( , ); await user.hover(screen.getByRole("button", { name: "Help" })); await user.keyboard("{Escape}"); expect(screen.getByRole("tooltip", { hidden: true })).not.toBeVisible(); }); });