Debian Codegraph @

www/tests/e2e/links.ts

raw symbols SCIP
1 import { test, expect } from './_fixtures';
2
3 async function checkLinks(hrefs: (string | null)[], request: any) {
4 const internal = hrefs.filter((h): h is string => !!h && !h.startsWith('#') && !h.startsWith('http'));
5 const results = await Promise.all(
6 internal.map(async (href) => {
7 const response = await request.get(href);
8 return { href, status: response.status() };
9 })
10 );
11 const broken = results.filter(r => r.status === 404);
12 expect(broken, `Broken links: ${broken.map(r => r.href).join(', ')}`).toEqual([]);
13 }
14
15 test.describe('Internal link integrity', () => {
16 test('sidebar links resolve (docs)', async ({ page, request }) => {
17 await page.goto('/docs');
18
19 const hrefs = await page.locator('#sidebar-nav a[href]').evaluateAll(
20 (els: HTMLAnchorElement[]) => els.map(el => el.getAttribute('href'))
21 );
22
23 expect(hrefs.length).toBeGreaterThan(10);
24 await checkLinks(hrefs, request);
25 });
26
27 test('sidebar links resolve (reference)', async ({ page, request }) => {
28 await page.goto('/reference/attributes/hx-get');
29
30 const hrefs = await page.locator('#sidebar-nav a[href]').evaluateAll(
31 (els: HTMLAnchorElement[]) => els.map(el => el.getAttribute('href'))
32 );
33
34 expect(hrefs.length).toBeGreaterThan(10);
35 await checkLinks(hrefs, request);
36 });
37
38 test('breadcrumb links resolve', async ({ page, request }) => {
39 await page.goto('/reference/attributes/hx-get');
40
41 const hrefs = await page.locator('nav[aria-label="Breadcrumb"] a[href]').evaluateAll(
42 (els: HTMLAnchorElement[]) => els.map(el => el.getAttribute('href'))
43 );
44
45 await checkLinks(hrefs, request);
46 });
47
48 test('pagination links resolve', async ({ page, request }) => {
49 await page.goto('/reference/attributes/hx-get');
50
51 const hrefs = await page.locator('nav[aria-label="Pagination"] a[href]').evaluateAll(
52 (els: HTMLAnchorElement[]) => els.map(el => el.getAttribute('href'))
53 );
54
55 await checkLinks(hrefs, request);
56 });
57 });