// @vitest-environment jsdom // // A reload under two overlays (a dialog, or a maximised player, over the player) loads on the upper // one's entry; only the player reopens, and takes that entry over. The lower one's entry is still // under it, and nothing reopens there: closing the player steps back over it too, so one close // lands on the page — not on a dead step that looks like it. Its own file: the entry is read as the // module loads, so it is set up before the import. import { describe, expect, it } from "vitest"; import { act, renderHook } from "@testing-library/react"; describe("an overlay reopened on the entry a reload under two started from", () => { it("closes onto the page under both", async () => { window.history.replaceState({ sfPage: "feed" }, "", "/?page=feed"); window.history.pushState({ sfPage: "feed", _ov: 1, _ovd: 1 }, "", "/?page=feed&watch=v1"); window.history.pushState({ sfPage: "feed", _ov: 2, _ovd: 2 }, "", "/?page=feed&watch=v1"); const depth = window.history.length; const { useBackToClose } = await import("./history"); const holder: { unmount?: () => void } = {}; const r = renderHook(() => useBackToClose(() => holder.unmount?.(), { watch: "v1" })); holder.unmount = r.unmount; await act(async () => { await Promise.resolve(); }); expect(window.history.length).toBe(depth); await act(async () => { const landed = new Promise((res) => window.addEventListener("popstate", res, { once: true })); r.unmount(); await landed; await Promise.resolve(); }); expect(window.history.state?._ov).toBeUndefined(); expect(window.location.search).toBe("?page=feed"); }); it("a pushed overlay entry records how many it stands on", async () => { window.history.replaceState({ sfPage: "feed" }, "", "/?page=feed"); const { useBackToClose } = await import("./history"); const r = renderHook(() => useBackToClose(() => {})); await act(async () => { await Promise.resolve(); }); expect(window.history.state?._ovd).toBe(1); r.unmount(); }); });