// @vitest-environment jsdom // // A reload under two overlays: the player reopens on the upper one's entry, the lower one's is dead // under it. A browser Back closes the player — and steps over the dead entry too, onto the page, as // the player's own close does. 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 landing = () => new Promise((res) => window.addEventListener("popstate", res, { once: true })); describe("a browser Back over an overlay reopened on the entry a reload under two started from", () => { it("lands on 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 { useBackToClose } = await import("./history"); let closed = false; renderHook(() => useBackToClose(() => (closed = true), { watch: "v1" })); await act(async () => { await Promise.resolve(); }); await act(async () => { const first = landing(); window.history.back(); await first; await landing(); // the step over the dead entry await Promise.resolve(); }); expect(closed).toBe(true); expect(window.history.state?._ov).toBeUndefined(); expect(window.location.search).toBe("?page=feed"); }); });