// @vitest-environment jsdom // // A reload under an overlay that reopens (the player) loads on the overlay's entry, its mark on it. // A page that settles before the overlay is back (the rail steps off a playlist deleted since, before // the player's row has loaded) has not been sent to another view: nothing the user did moved it. The // mark stays, and the reopened overlay takes its entry over rather than pushing one more — one more // was a Back that went nowhere. Its own file: the entry is read as the history module loads, so it is // set up before the import. import { describe, expect, it } from "vitest"; import { act, renderHook } from "@testing-library/react"; describe("a page settling on the entry a reload under an overlay started from", () => { it("before the user has done anything, leaves the entry to the overlay that reopens", async () => { Object.defineProperty(navigator, "userActivation", { configurable: true, value: { hasBeenActive: false }, }); window.history.replaceState({ sfPage: "playlists" }, "", "/?page=playlists&pl=7"); window.history.pushState( { sfPage: "playlists", _ov: 1, _ovd: 1 }, "", "/?page=playlists&pl=7&watch=Z", ); const { useUrlMirror } = await import("./useUrlMirror"); const { useBackToClose } = await import("./history"); const mirror = renderHook(({ pl }) => useUrlMirror({ pl }), { initialProps: { pl: "7" } }); mirror.rerender({ pl: "1" }); expect(new URLSearchParams(window.location.search).get("pl")).toBe("1"); const depth = window.history.length; renderHook(() => useBackToClose(() => {})); await act(async () => { await Promise.resolve(); }); expect(window.history.length).toBe(depth); }); });