Skip to content

Commit

Permalink
Add aria curent tests for navigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
srpiatt committed Feb 8, 2024
1 parent 31c2ca7 commit 0ce216c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const routes = [
{ path: '/dataset', id: 'nav-link-dataset', headerText: 'Dataset Management' },
{ path: '/help', id: 'nav-link-help', headerText: 'Help' },
{ path: '/admin', id: 'nav-link-admin', headerText: 'Admin' },
{ path: '/admin/super', id: 'nav-link-admin-super', headerText: 'Super Admin' },
{ path: '/#', id: 'nav-link-logout', headerText: 'Home' }
{ path: '/admin/super', id: 'nav-link-admin-super', headerText: 'Super Admin' }
];

test.describe('Navigation', () => {
Expand All @@ -20,5 +19,21 @@ test.describe('Navigation', () => {
await navItem.click();
await expect(page.locator('.main-content>h1')).toHaveText(route.headerText);
});
test(`${route.path} navigation bar has correct active element`, async ({ page }) => {
await page.goto(route.path);

// Check that this element is active
const navItem = page.locator('#' + route.id);
await expect(navItem).toHaveAttribute('aria-current', 'page');

// Check that other elements aren't active
const inactive = routes
.filter((altRoute) => altRoute.path !== route.path)
.map((altRoute) => {
const navItem = page.locator('#' + altRoute.id);
return expect(navItem).not.toHaveAttribute('aria-current');
});
await Promise.all(inactive);
});
});
});

0 comments on commit 0ce216c

Please sign in to comment.