diff --git a/apps/web/src/__tests__/portal.test.tsx b/apps/web/src/__tests__/portal.test.tsx index 660b228..36f04af 100644 --- a/apps/web/src/__tests__/portal.test.tsx +++ b/apps/web/src/__tests__/portal.test.tsx @@ -281,4 +281,35 @@ describe("CustomerPortal session loading", () => { expect(impersonationFetches).toHaveLength(0); expect(screen.queryByRole("button", { name: /End Session/i })).not.toBeInTheDocument(); }); + + it("redirects to /admin/clients after ending impersonation session", async () => { + // Mock window.location.href + const originalLocation = window.location; + Object.defineProperty(window, "location", { + value: { href: "" }, + writable: true, + }); + + const { CustomerPortal } = await import("../portal/CustomerPortal.js"); + render( + + + + ); + + // Wait for banner to appear + await waitFor(() => { + expect(screen.getByRole("button", { name: /End Session/i })).toBeInTheDocument(); + }); + + // Click "End Session" — this triggers handleEnd which calls the API then redirects + fireEvent.click(screen.getByRole("button", { name: /End Session/i })); + + await waitFor(() => { + expect(window.location.href).toBe("/admin/clients"); + }); + + // Restore + Object.defineProperty(window, "location", { value: originalLocation, writable: true }); + }); }); diff --git a/apps/web/src/portal/CustomerPortal.tsx b/apps/web/src/portal/CustomerPortal.tsx index e3fad41..b74e297 100644 --- a/apps/web/src/portal/CustomerPortal.tsx +++ b/apps/web/src/portal/CustomerPortal.tsx @@ -73,6 +73,7 @@ export function CustomerPortal() { } setSession(null); setSessionExtended(false); + window.location.href = "/admin/clients"; }, [session]); const handleExtend = useCallback(async () => {