| 1 | import { test, expect } from './_fixtures'; |
| 2 | |
| 3 | test.describe('/docs sidebar', () => { |
| 4 | |
| 5 | test.beforeEach(async ({ page }) => { |
| 6 | await page.goto('/docs'); |
| 7 | await page.waitForSelector('.sidebar-link'); |
| 8 | await page.waitForTimeout(300); |
| 9 | }); |
| 10 | |
| 11 | test('sidebar links are hash-only anchors, not full paths', async ({ page }) => { |
| 12 | const hrefs = await page.locator('.sidebar-link').evaluateAll( |
| 13 | links => links.map(l => l.getAttribute('href')) |
| 14 | ); |
| 15 | for (const href of hrefs) { |
| 16 | expect(href).toMatch(/^#/); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | test('clicking a sidebar link scrolls to the matching heading', async ({ page }) => { |
| 21 | await page.locator('.sidebar-link[href="#hypermedia-controls"]').click(); |
| 22 | await page.waitForTimeout(500); |
| 23 | |
| 24 | const heading = page.locator('h2#hypermedia-controls'); |
| 25 | await expect(heading).toBeInViewport(); |
| 26 | }); |
| 27 | |
| 28 | test('clicking a sidebar link marks it as active', async ({ page }) => { |
| 29 | const link = page.locator('.sidebar-link[href="#hypermedia-controls"]'); |
| 30 | await link.click(); |
| 31 | await page.waitForTimeout(800); |
| 32 | |
| 33 | await expect(link).toHaveAttribute('aria-current', 'true'); |
| 34 | await expect(page.locator('.sidebar-link[aria-current]')).toHaveCount(1); |
| 35 | }); |
| 36 | |
| 37 | test('clicking a second sidebar link moves active to it', async ({ page }) => { |
| 38 | const first = page.locator('.sidebar-link[href="#hypermedia-controls"]'); |
| 39 | const second = page.locator('.sidebar-link[href="#multi-target-updates"]'); |
| 40 | |
| 41 | await first.click(); |
| 42 | await page.waitForTimeout(800); |
| 43 | await expect(first).toHaveAttribute('aria-current', 'true'); |
| 44 | |
| 45 | await second.click(); |
| 46 | await page.waitForTimeout(800); |
| 47 | await expect(second).toHaveAttribute('aria-current', 'true'); |
| 48 | await expect(first).not.toHaveAttribute('aria-current'); |
| 49 | }); |
| 50 | |
| 51 | test('clicking a sidebar link ABOVE the current active one activates it', async ({ page }) => { |
| 52 | const lower = page.locator('.sidebar-link[href="#multi-target-updates"]'); |
| 53 | await lower.click(); |
| 54 | await page.waitForTimeout(800); |
| 55 | await expect(lower).toHaveAttribute('aria-current', 'true'); |
| 56 | |
| 57 | const upper = page.locator('.sidebar-link[href="#hypermedia-controls"]'); |
| 58 | await upper.click(); |
| 59 | await page.waitForTimeout(800); |
| 60 | await expect(upper).toHaveAttribute('aria-current', 'true'); |
| 61 | await expect(lower).not.toHaveAttribute('aria-current'); |
| 62 | }); |
| 63 | |
| 64 | test('clicking a sidebar link does not fetch a new page', async ({ page }) => { |
| 65 | const docRequests: string[] = []; |
| 66 | page.on('request', req => { |
| 67 | if (req.resourceType() === 'document') docRequests.push(req.url()); |
| 68 | }); |
| 69 | |
| 70 | await page.locator('.sidebar-link[href="#installation"]').click(); |
| 71 | await page.waitForTimeout(500); |
| 72 | |
| 73 | expect(docRequests).toHaveLength(0); |
| 74 | }); |
| 75 | |
| 76 | test('scrolling the page activates the corresponding sidebar link', async ({ page }) => { |
| 77 | // Scroll into the section by clicking, then verify scrollspy tracked it |
| 78 | await page.locator('.sidebar-link[href="#css-transitions"]').click(); |
| 79 | await page.waitForTimeout(800); |
| 80 | |
| 81 | // Scroll a bit further into the section so the observer catches up |
| 82 | await page.evaluate(() => window.scrollBy(0, 200)); |
| 83 | await page.waitForTimeout(500); |
| 84 | |
| 85 | const link = page.locator('.sidebar-link[href="#css-transitions"]'); |
| 86 | await expect(link).toHaveAttribute('aria-current', 'true'); |
| 87 | }); |
| 88 | }); |