@@ -102,7 +102,8 @@ describe('Navbar', () => {
102102 ( getAuthStatus as jest . Mock ) . mockResolvedValue ( { authenticated : false } ) ;
103103 ( getCurrentUser as jest . Mock ) . mockImplementation ( ( ) => new Promise ( ( ) => { } ) ) ;
104104 renderWithRouter ( < Navbar /> ) ;
105- expect ( screen . getByText ( / U s e r : \u2026 / ) ) . toBeInTheDocument ( ) ;
105+ expect ( screen . getByText ( / U s e r I D : \u2026 / ) ) . toBeInTheDocument ( ) ;
106+ expect ( screen . getByText ( 'Status: checking access' ) ) . toBeInTheDocument ( ) ;
106107 } ) ;
107108
108109 it ( 'fetches and displays the current user on success' , async ( ) => {
@@ -111,17 +112,20 @@ describe('Navbar', () => {
111112 ( getCurrentUser as jest . Mock ) . mockResolvedValue ( 'admin' ) ;
112113 renderWithRouter ( < Navbar /> ) ;
113114 await waitFor ( ( ) => {
114- expect ( screen . getByText ( 'User: admin' ) ) . toBeInTheDocument ( ) ;
115+ expect ( screen . getByText ( 'User ID: admin' ) ) . toBeInTheDocument ( ) ;
116+ expect ( screen . getByText ( 'Status: logged in' ) ) . toBeInTheDocument ( ) ;
115117 } ) ;
116118 } ) ;
117119
118- it ( 'displays "unknown" for user if fetch fails ' , async ( ) => {
120+ it ( 'shows read only user state and login prompt when unauthenticated ' , async ( ) => {
119121 ( getAppVersion as jest . Mock ) . mockResolvedValue ( '1.2.3' ) ;
120122 ( getAuthStatus as jest . Mock ) . mockResolvedValue ( { authenticated : false } ) ;
121123 ( getCurrentUser as jest . Mock ) . mockRejectedValue ( new Error ( 'Network error' ) ) ;
122124 renderWithRouter ( < Navbar /> ) ;
123125 await waitFor ( ( ) => {
124- expect ( screen . getByText ( 'User: unknown' ) ) . toBeInTheDocument ( ) ;
126+ expect ( screen . getByText ( 'User ID: unknown (read only)' ) ) . toBeInTheDocument ( ) ;
127+ expect ( screen . getByText ( 'Status: read only' ) ) . toBeInTheDocument ( ) ;
128+ expect ( screen . getByRole ( 'link' , { name : 'Login to edit bookings' } ) ) . toHaveAttribute ( 'href' , '/login' ) ;
125129 } ) ;
126130 } ) ;
127131
0 commit comments