// @vitest-environment jsdom // // The entry a reload under an open dialog started from carries the dialog's mark, and a dialog that // does not reopen (About, the cheat sheet) leaves it there. A view pushed from that entry (a channel // page, a search, a sub-view) must not inherit the mark: the first overlay over it took the view's // entry over as its own, and closing it closed the view too. 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("a view pushed from the entry a reload under a dialog started from", () => { it("is not taken over by the first overlay over it", async () => { window.history.replaceState({ sfPage: "feed" }, "", "/?page=feed"); window.history.pushState({ sfPage: "feed", _ov: 3 }, "", "/?page=feed"); const { rememberNavPosition, useBackToClose } = await import("./history"); // openChannel's push, as it spreads the entry it leaves. const left = rememberNavPosition(); expect(left._ov).toBeUndefined(); window.history.pushState({ ...left, _chan: "UC1" }, "", "/?chan=UC1"); const depth = window.history.length; 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 + 1); 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?._chan).toBe("UC1"); expect(window.location.search).toBe("?chan=UC1"); }); });