// @vitest-environment jsdom // // A switch or sign-out hands the tab's next page its account instead of moving the pin: the page being left // still unloads as its own account. The players' resume beacons read the pin as they fire on the way out, // and with the pin already moved they saved one account's playback position into the other. import { beforeEach, describe, expect, it, vi } from "vitest"; beforeEach(() => { sessionStorage.clear(); sessionStorage.setItem("siftlode.activeAccount", "3"); vi.resetModules(); // the hand-over is taken at import: each import below is a page load }); describe("pinOnNextPage", () => { it("leaves the pin alone until the next page, which takes the account over once", async () => { const leaving = await import("./activeAccount"); leaving.pinOnNextPage(7); expect(leaving.activeAccountId()).toBe(3); // the unload still acts as 3 vi.resetModules(); const next = await import("./activeAccount"); expect(next.activeAccountId()).toBe(7); next.pinActiveAccount(9); // BootGate corrects it vi.resetModules(); // and an F5 keeps the correction expect((await import("./activeAccount")).activeAccountId()).toBe(9); }); it("hands over no account at all, so the next page adopts the session's default", async () => { const leaving = await import("./activeAccount"); leaving.pinOnNextPage(null); expect(leaving.activeAccountId()).toBe(3); vi.resetModules(); expect((await import("./activeAccount")).activeAccountId()).toBeNull(); }); });