11import type { Session } from "@coder-studio/core" ;
2- import { fireEvent , render , screen , waitFor , within } from "@testing-library/react" ;
2+ import { act , fireEvent , render , screen , waitFor , within } from "@testing-library/react" ;
33import userEvent from "@testing-library/user-event" ;
44import { createStore , Provider } from "jotai" ;
55import type { ReactNode } from "react" ;
@@ -820,7 +820,7 @@ describe("MobileShell Phase 2 workspace", () => {
820820 expect ( screen . queryByRole ( "button" , { name : "Switch workspace" } ) ) . not . toBeInTheDocument ( ) ;
821821 } ) ;
822822
823- it ( "does not bootstrap workspaces from / on mobile when auth is enabled and user is unauthenticated" , ( ) => {
823+ it ( "does not bootstrap workspaces from / on mobile before redirecting to /login when auth is enabled and user is unauthenticated" , async ( ) => {
824824 const sendCommand = vi . fn ( ) ;
825825 const store = createStore ( ) ;
826826 store . set ( connectionStatusAtom , "connected" ) ;
@@ -851,9 +851,11 @@ describe("MobileShell Phase 2 workspace", () => {
851851 </ Provider >
852852 ) ;
853853
854- expect ( screen . getByText ( "WelcomePage" ) ) . toBeInTheDocument ( ) ;
855- expect ( screen . getByTestId ( "location-display" ) ) . toHaveTextContent ( "/" ) ;
856- expect ( sendCommand ) . not . toHaveBeenCalled ( ) ;
854+ await waitFor ( ( ) => {
855+ expect ( screen . getByText ( "LoginPage" ) ) . toBeInTheDocument ( ) ;
856+ expect ( screen . getByTestId ( "location-display" ) ) . toHaveTextContent ( "/login" ) ;
857+ expect ( sendCommand ) . not . toHaveBeenCalled ( ) ;
858+ } ) ;
857859 } ) ;
858860
859861 it ( "keeps the explicit /login route on mobile when auth is enabled and user is unauthenticated" , async ( ) => {
@@ -910,7 +912,7 @@ describe("MobileShell Phase 2 workspace", () => {
910912 expect ( screen . getByText ( "Page not found" ) ) . toBeInTheDocument ( ) ;
911913 } ) ;
912914
913- it ( "does not rewrite /auth to /login on mobile when auth is required and user is unauthenticated" , async ( ) => {
915+ it ( "rewrites /auth to /login on mobile when auth is required and user is unauthenticated" , async ( ) => {
914916 const store = createStore ( ) ;
915917 store . set ( connectionStatusAtom , "connected" ) ;
916918 store . set ( authEnabledAtom , true ) ;
@@ -926,9 +928,8 @@ describe("MobileShell Phase 2 workspace", () => {
926928 ) ;
927929
928930 await waitFor ( ( ) => {
929- expect ( screen . getByText ( "Page not found" ) ) . toBeInTheDocument ( ) ;
930- expect ( screen . getByTestId ( "location-display" ) ) . toHaveTextContent ( "/auth" ) ;
931- expect ( screen . queryByText ( "LoginPage" ) ) . not . toBeInTheDocument ( ) ;
931+ expect ( screen . getByText ( "LoginPage" ) ) . toBeInTheDocument ( ) ;
932+ expect ( screen . getByTestId ( "location-display" ) ) . toHaveTextContent ( "/login" ) ;
932933 } ) ;
933934 } ) ;
934935
@@ -1458,12 +1459,16 @@ describe("MobileShell Phase 2 workspace", () => {
14581459 expect ( store . get ( visibleMobileSessionIdAtom ) ) . toBe ( "sess_2" ) ;
14591460 } ) ;
14601461
1461- store . set ( pendingFocusSessionAtom , "sess_1" ) ;
1462+ await act ( async ( ) => {
1463+ store . set ( pendingFocusSessionAtom , "sess_1" ) ;
1464+ } ) ;
14621465
14631466 await waitFor ( ( ) => {
14641467 expect ( screen . getByTestId ( "mobile-session-card" ) ) . toHaveTextContent ( "sess_1" ) ;
14651468 } ) ;
1466- expect ( store . get ( visibleMobileSessionIdAtom ) ) . toBe ( "sess_1" ) ;
1469+ await waitFor ( ( ) => {
1470+ expect ( store . get ( visibleMobileSessionIdAtom ) ) . toBe ( "sess_1" ) ;
1471+ } ) ;
14671472
14681473 unmount ( ) ;
14691474
0 commit comments