forked from baron/baron-sso
Merge pull request 'feature/df-rp-e2e' (#1135) from feature/df-rp-e2e into dev
Reviewed-on: baron/baron-sso#1135
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { act } from "react";
|
||||
import { act, useEffect } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { MemoryRouter, Route, Routes } from "react-router-dom";
|
||||
import { MemoryRouter, Route, Routes, useNavigate } from "react-router-dom";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import AppLayout from "./AppLayout";
|
||||
|
||||
@@ -49,6 +49,24 @@ vi.mock("../../lib/i18n", () => ({
|
||||
|
||||
const roots: Root[] = [];
|
||||
|
||||
type TestWindow = Window & {
|
||||
__baronNavigate?: (to: string) => void;
|
||||
};
|
||||
|
||||
function RouteProbe() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
(window as TestWindow).__baronNavigate = navigate;
|
||||
|
||||
return () => {
|
||||
delete (window as TestWindow).__baronNavigate;
|
||||
};
|
||||
}, [navigate]);
|
||||
|
||||
return <div>Client outlet</div>;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
authState.isAuthenticated = true;
|
||||
authState.isLoading = false;
|
||||
@@ -89,7 +107,7 @@ async function renderLayout(initialEntry = "/clients") {
|
||||
<MemoryRouter initialEntries={[initialEntry]}>
|
||||
<Routes>
|
||||
<Route path="/" element={<AppLayout />}>
|
||||
<Route path="clients" element={<div>Client outlet</div>} />
|
||||
<Route path="clients" element={<RouteProbe />} />
|
||||
<Route path="profile" element={<div>Profile outlet</div>} />
|
||||
</Route>
|
||||
</Routes>
|
||||
@@ -181,4 +199,15 @@ describe("devfront AppLayout", () => {
|
||||
|
||||
expect(authState.signinSilent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("attempts silent renewal when route changes and the session is expiring", async () => {
|
||||
authState.user.expires_at = Math.floor(Date.now() / 1000) + 60;
|
||||
await renderLayout();
|
||||
|
||||
await act(async () => {
|
||||
(window as TestWindow).__baronNavigate?.("/profile");
|
||||
});
|
||||
|
||||
expect(authState.signinSilent).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user