File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const AdminRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
99 if ( ! isAuthenticated ) return < Navigate to = "/login" replace /> ;
1010 if ( user ?. role !== 'admin' ) {
1111 return (
12- < div className = "flex flex-col items-center justify-center min-h-[60vh] text-center" >
12+ < div data-testid = "admin-route-forbidden" className = "flex flex-col items-center justify-center min-h-[60vh] text-center" >
1313 < h1 className = "text-4xl font-bold text-gray-800 mb-4" > 403</ h1 >
1414 < p className = "text-lg text-gray-600" > Access Denied — Admin only.</ p >
1515 </ div >
Original file line number Diff line number Diff line change @@ -25,10 +25,7 @@ test.describe('RBAC – Viewer role', () => {
2525 // 3. Redirect to login
2626 const url = page . url ( ) ;
2727 const wasRedirected = ! url . includes ( '/admin' ) || url . includes ( '/login' ) ;
28- const showsForbidden = await page
29- . getByText ( / 4 0 3 | u n a u t h o r i z e d | f o r b i d d e n | a c c e s s d e n i e d | n o t a u t h o r i z e d / i)
30- . isVisible ( )
31- . catch ( ( ) => false ) ;
28+ const showsForbidden = await page . getByTestId ( 'admin-route-forbidden' ) . isVisible ( ) . catch ( ( ) => false ) ;
3229 const showsEmptyOrError = await page
3330 . getByText ( / n o u s e r s | e r r o r | s o m e t h i n g w e n t w r o n g / i)
3431 . isVisible ( )
@@ -94,7 +91,7 @@ test.describe('RBAC – Admin role', () => {
9491 expect ( page . url ( ) ) . not . toMatch ( / \/ l o g i n / ) ;
9592
9693 // Should NOT see a 403/forbidden page
97- const isForbidden = await page . getByText ( / 4 0 3 | f o r b i d d e n | a c c e s s d e n i e d / i ) . isVisible ( ) . catch ( ( ) => false ) ;
94+ const isForbidden = await page . getByTestId ( 'admin-route- forbidden' ) . isVisible ( ) . catch ( ( ) => false ) ;
9895 expect ( isForbidden ) . toBe ( false ) ;
9996 } ) ;
100- } ) ;
97+ } ) ;
You can’t perform that action at this time.
0 commit comments