// @vitest-environment jsdom // // A reload under an open overlay (a player the address names) loads the document on that overlay's // entry, and the page opens the overlay again. It takes that entry over: pushed over it instead, Back // would close the player onto the same page once more — one dead step for every reload. 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"; const search = () => new URLSearchParams(window.location.search); describe("an overlay reopened on the entry a reload started from", () => { it("takes that entry over, and Back lands on the page under it", async () => { window.history.replaceState({ sfPage: "feed" }, "", "/?q=music"); window.history.pushState({ sfPage: "feed", _ov: 3 }, "", "/?q=music&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); expect(search().get("watch")).toBe("v1"); await act(async () => { const landed = new Promise((res) => window.addEventListener("popstate", res, { once: true })); window.history.back(); await landed; await Promise.resolve(); }); expect(window.location.search).toBe("?q=music"); }); });