Skip to content

Commit 0ce216c

Browse files
committed
Add aria curent tests for navigation.
1 parent 31c2ca7 commit 0ce216c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tests/test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const routes = [
88
{ path: '/dataset', id: 'nav-link-dataset', headerText: 'Dataset Management' },
99
{ path: '/help', id: 'nav-link-help', headerText: 'Help' },
1010
{ 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' }
1312
];
1413

1514
test.describe('Navigation', () => {
@@ -20,5 +19,21 @@ test.describe('Navigation', () => {
2019
await navItem.click();
2120
await expect(page.locator('.main-content>h1')).toHaveText(route.headerText);
2221
});
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+
});
2338
});
2439
});

0 commit comments

Comments
 (0)