// @vitest-environment jsdom // // A dialog opened from a player in true fullscreen portals INTO the fullscreen element (a node under // is painted beneath it, i.e. invisible). Leaving fullscreen changes that container — and a // React portal whose container changes is torn down and recreated, so everything the dialog held went // with it: a half-filled download form reset to its defaults and focus fell to (a verifier's // side finding in deep-review round 4). import { describe, it, expect, afterEach } from "vitest"; import { render, cleanup, screen, fireEvent, act } from "@testing-library/react"; import { vi } from "vitest"; vi.mock("react-i18next", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, useTranslation: () => ({ t: (key: string) => key }) }; }); import Modal from "./Modal"; const setFullscreen = (el: Element | null) => act(() => { Object.defineProperty(document, "fullscreenElement", { value: el, configurable: true }); document.dispatchEvent(new Event("fullscreenchange")); }); afterEach(() => { cleanup(); setFullscreen(null); }); describe("a dialog open while fullscreen is left", () => { it("keeps what the viewer had typed in it, and the focus inside it", async () => { const stage = document.createElement("div"); document.body.appendChild(stage); await setFullscreen(stage); render( {}}> , ); const field = screen.getByLabelText("name") as HTMLInputElement; fireEvent.change(field, { target: { value: "my cut" } }); field.focus(); expect(stage.contains(field)).toBe(true); await setFullscreen(null); // the browser's own Esc leaves fullscreen; the dialog stays open const after = screen.getByLabelText("name") as HTMLInputElement; expect(after.value).toBe("my cut"); expect(document.activeElement).toBe(after); stage.remove(); }); });