microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/docs-update-scripts-linting-readme

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/docusaurus/e2e/keyboard-nav.spec.ts

35lines · modecode

1import { test, expect } from '@playwright/test';
2import AxeBuilder from '@axe-core/playwright';
3
4const WCAG_TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'];
5
6// WCAG 2.1.1 Keyboard: primary navigation must be operable by keyboard and
7// every interactive element must surface a visible focus state.
8test.describe('Keyboard navigation', () => {
9 test('navbar links are reachable via Tab from the top of the page', async ({ page }) => {
10 await page.goto('/hve-core/docs/getting-started/');
11
12 const docNavLink = page.getByRole('link', { name: 'Documentation', exact: true });
13 await expect(docNavLink).toBeVisible();
14
15 // Walk the focus order until the Documentation navbar link receives focus.
16 let focusedDocLink = false;
17 for (let i = 0; i < 12; i++) {
18 await page.keyboard.press('Tab');
19 if (await docNavLink.evaluate((el) => el === document.activeElement)) {
20 focusedDocLink = true;
21 break;
22 }
23 }
24
25 expect(focusedDocLink).toBe(true);
26 });
27
28 test('doc page initial state passes an axe scan', async ({ page }) => {
29 await page.goto('/hve-core/docs/getting-started/');
30 await expect(page.getByRole('main')).toBeVisible();
31
32 const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze();
33 expect(results.violations).toEqual([]);
34 });
35});
36