fix: redirect to /admin/clients after ending impersonation #82

Merged
the-dogfather-cto[bot] merged 1 commits from fix/impersonation-end-redirect into main 2026-03-20 23:37:04 +00:00
2 changed files with 32 additions and 0 deletions
+31
View File
@@ -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(
<MemoryRouter initialEntries={["/?sessionId=sess-1"]}>
<CustomerPortal />
</MemoryRouter>
);
// 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 });
});
});
+1
View File
@@ -73,6 +73,7 @@ export function CustomerPortal() {
}
setSession(null);
setSessionExtended(false);
window.location.href = "/admin/clients";
}, [session]);
const handleExtend = useCallback(async () => {