| 1 | import { test, expect } from './_fixtures'; |
| 2 | |
| 3 | test.describe('Accessibility', () => { |
| 4 | test('page has proper landmark structure', async ({ page }) => { |
| 5 | await page.goto('/'); |
| 6 | await expect(page.locator('header[role="banner"]')).toBeVisible(); |
| 7 | await expect(page.locator('main#content-main-content')).toBeVisible(); |
| 8 | }); |
| 9 | |
| 10 | test('navigation has aria-label', async ({ page }) => { |
| 11 | await page.goto('/'); |
| 12 | await expect(page.locator('nav[aria-label="Primary Navigation"]')).toBeVisible(); |
| 13 | await expect(page.locator('nav[aria-label="Mobile Navigation"]')).toBeAttached(); |
| 14 | }); |
| 15 | |
| 16 | test('content pages have sidebar with aria-label', async ({ page }) => { |
| 17 | await page.goto('/docs'); |
| 18 | await expect(page.locator('nav[aria-label="Sidebar Navigation"]')).toBeVisible(); |
| 19 | }); |
| 20 | |
| 21 | test('search dialog has correct aria attributes', async ({ page }) => { |
| 22 | await page.goto('/'); |
| 23 | const dialog = page.locator('dialog#search-modal'); |
| 24 | await expect(dialog).toHaveAttribute('role', 'alertdialog'); |
| 25 | await expect(dialog).toHaveAttribute('aria-modal', 'true'); |
| 26 | await expect(dialog).toHaveAttribute('aria-label', 'Search documentation'); |
| 27 | }); |
| 28 | |
| 29 | test('images on about page have alt text', async ({ page }) => { |
| 30 | await page.goto('/about'); |
| 31 | const imagesWithoutAlt = page.locator('main img:not([alt])'); |
| 32 | await expect(imagesWithoutAlt).toHaveCount(0); |
| 33 | }); |
| 34 | |
| 35 | test('no duplicate IDs on a content page', async ({ page }) => { |
| 36 | await page.goto('/reference/attributes/hx-get'); |
| 37 | const duplicates = await page.evaluate(() => { |
| 38 | const ids = Array.from(document.querySelectorAll('[id]')).map(el => el.id); |
| 39 | return ids.filter((id, i) => ids.indexOf(id) !== i); |
| 40 | }); |
| 41 | expect(duplicates).toEqual([]); |
| 42 | }); |
| 43 | }); |