Open History to see the last commit
1import type { SnapShotSource } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3import { userEvent } from "vite-plus/test/browser";
4
5import "~/index.css";
6import { render } from "../../../test/render";
7import { ExpandedImageDialog } from "./ExpandedImageDialog";
8
9const PIXEL =
10 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
11
12const snapShotSource: SnapShotSource = {
13 kind: "snap-shot",
14 capturedAt: "2026-01-01T00:00:00.000Z",
15 appName: "Finder",
16 windowTitle: "Downloads",
17};
18
19describe("ExpandedImageDialog", () => {
20 it("Escape closes a popup opened inside the dialog before the dialog", async () => {
21 const onClose = vi.fn();
22 await using screen = await render(
23 <ExpandedImageDialog
24 preview={{ images: [{ src: PIXEL, name: "shot.png", source: snapShotSource }], index: 0 }}
25 onClose={onClose}
26 />,
27 // The dialog renders no links and reads no route.
28 { router: false },
29 );
30
31 await userEvent.click(screen.getByRole("button", { name: "No accessibility data" }));
32 await expect.element(screen.getByText("Accessibility data")).toBeVisible();
33
34 await userEvent.keyboard("{Escape}");
35 await expect.element(screen.getByText("Accessibility data")).not.toBeInTheDocument();
36 expect(onClose).not.toHaveBeenCalled();
37
38 // Focus returns to the popup's trigger and opens its tooltip; leave it for a plain control.
39 (screen.getByRole("button", { name: "Close image preview" }).element() as HTMLElement).focus();
40 await userEvent.keyboard("{Escape}");
41 await vi.waitFor(() => expect(onClose).toHaveBeenCalledOnce());
42 });
43});