11import { fireEvent , render , screen , waitFor } from "@testing-library/react" ;
22import { createStore , Provider } from "jotai" ;
33import { MemoryRouter } from "react-router-dom" ;
4- import { afterEach , describe , expect , it , vi } from "vitest" ;
4+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
55import { activationStatusAtom } from "../../atoms/activation" ;
66import { authEnabledAtom } from "../../atoms/connection" ;
77import { SessionGatePage } from "./session-gate" ;
88
99const originalFetch = globalThis . fetch ;
10+ const originalLocation = window . location ;
1011
1112describe ( "SessionGatePage" , ( ) => {
13+ beforeEach ( ( ) => {
14+ Object . defineProperty ( window , "location" , {
15+ configurable : true ,
16+ value : {
17+ ...originalLocation ,
18+ replace : vi . fn ( ) ,
19+ reload : vi . fn ( ) ,
20+ } ,
21+ } ) ;
22+ } ) ;
23+
1224 afterEach ( ( ) => {
1325 globalThis . fetch = originalFetch ;
26+ Object . defineProperty ( window , "location" , {
27+ configurable : true ,
28+ value : originalLocation ,
29+ } ) ;
1430 } ) ;
1531
1632 it ( "shows a password form when auth is enabled" , ( ) => {
@@ -78,7 +94,7 @@ describe("SessionGatePage", () => {
7894 } ) ;
7995 } ) ;
8096
81- it ( "navigates back to / after successful re-entry when auth is disabled" , async ( ) => {
97+ it ( "reloads the app after successful re-entry when auth is disabled" , async ( ) => {
8298 const requestReentry = vi . fn ( ) . mockResolvedValue ( true ) ;
8399 const store = createStore ( ) ;
84100 store . set ( authEnabledAtom , false ) ;
@@ -96,6 +112,7 @@ describe("SessionGatePage", () => {
96112
97113 await waitFor ( ( ) => {
98114 expect ( requestReentry ) . toHaveBeenCalledTimes ( 1 ) ;
115+ expect ( window . location . replace ) . toHaveBeenCalledWith ( "/" ) ;
99116 } ) ;
100117 } ) ;
101118} ) ;
0 commit comments