From 17a965552acd29347ca6d4ade41688b601833af5 Mon Sep 17 00:00:00 2001 From: Scrubs McBarkley Date: Fri, 20 Mar 2026 23:19:06 +0000 Subject: [PATCH] fix: redirect to /admin/clients after ending impersonation session Closes #81 - Add window.location.href = '/admin/clients' after clearing session state in handleEnd so staff are sent back to the admin panel - Add a test that verifies the redirect fires when End Session is clicked Co-Authored-By: Paperclip --- apps/web/src/__tests__/portal.test.tsx | 31 ++++++++++++++++++++++++++ apps/web/src/portal/CustomerPortal.tsx | 1 + 2 files changed, 32 insertions(+) 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 () => {