@@ -8,8 +8,7 @@ const routes = [
8
8
{ path : '/dataset' , id : 'nav-link-dataset' , headerText : 'Dataset Management' } ,
9
9
{ path : '/help' , id : 'nav-link-help' , headerText : 'Help' } ,
10
10
{ path : '/admin' , id : 'nav-link-admin' , headerText : 'Admin' } ,
11
- { path : '/admin/super' , id : 'nav-link-admin-super' , headerText : 'Super Admin' } ,
12
- { path : '/#' , id : 'nav-link-logout' , headerText : 'Home' }
11
+ { path : '/admin/super' , id : 'nav-link-admin-super' , headerText : 'Super Admin' }
13
12
] ;
14
13
15
14
test . describe ( 'Navigation' , ( ) => {
@@ -20,5 +19,21 @@ test.describe('Navigation', () => {
20
19
await navItem . click ( ) ;
21
20
await expect ( page . locator ( '.main-content>h1' ) ) . toHaveText ( route . headerText ) ;
22
21
} ) ;
22
+ test ( `${ route . path } navigation bar has correct active element` , async ( { page } ) => {
23
+ await page . goto ( route . path ) ;
24
+
25
+ // Check that this element is active
26
+ const navItem = page . locator ( '#' + route . id ) ;
27
+ await expect ( navItem ) . toHaveAttribute ( 'aria-current' , 'page' ) ;
28
+
29
+ // Check that other elements aren't active
30
+ const inactive = routes
31
+ . filter ( ( altRoute ) => altRoute . path !== route . path )
32
+ . map ( ( altRoute ) => {
33
+ const navItem = page . locator ( '#' + altRoute . id ) ;
34
+ return expect ( navItem ) . not . toHaveAttribute ( 'aria-current' ) ;
35
+ } ) ;
36
+ await Promise . all ( inactive ) ;
37
+ } ) ;
23
38
} ) ;
24
39
} ) ;
0 commit comments