// @vitest-environment jsdom // // The emailed verification link, confirmed wherever it is opened. The regression this pins: the token // used to be consumed inside Welcome.tsx, which App renders ONLY when there is no session — so opening // the link in a browser that already held a Siftlode session posted nothing, the fragment was then // stripped, and the user got no signal at all. Incognito worked, which is why it survived. // // entryUrl snapshots window.location at IMPORT time, so each case resets the module registry and sets // the URL before importing — that is the behaviour under test, not a workaround. import { describe, it, expect, afterEach, vi } from "vitest"; import { render, screen, cleanup, act } from "@testing-library/react"; afterEach(() => { cleanup(); vi.resetModules(); vi.restoreAllMocks(); window.history.replaceState(null, "", "/"); }); /** Mount the hook at a given entry URL with a stubbed /auth/verify, and hand back what it reported. */ async function mountAt(url: string, verifyEmail: ReturnType) { // Carries whatever state the case set up: history.state is part of what the hook must not destroy. window.history.replaceState(window.history.state, "", url); vi.resetModules(); vi.doMock("./api", async (importOriginal) => { const actual = await importOriginal(); return { ...actual, api: { ...actual.api, verifyEmail } }; }); const { useVerifyEntry } = await import("./useVerifyEntry"); function Probe() { const entry = useVerifyEntry(); return ( <>
{`${entry.outcome ?? "none"}:${entry.email ?? "-"}`}
{entry.resetPending ? "reset-pending" : "-"}