// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini import path from 'node:path'; import AxeBuilder from '@axe-core/playwright'; import { test, expect } from '../harness/fixtures'; import { SCREENSHOTS_DIR } from '../harness/env'; import { up } from '../harness/api'; import { addAddress, createZone } from '../harness/personas'; test.use({ group: 'a11y' }); test('all HTML pages meet axe severity limits in both themes and viewport sizes', async ({ world }) => { test.setTimeout(240_000); const admin = await world.bootstrapAdmin(); const api = await world.apiAs(admin); const user = await world.createUser(api, 'user'); const zonePath = await createZone(api, world.zoneName()); await addAddress(api, zonePath, 'www', '192.0.2.15'); const userPath = up(user.username); const adminPages = [ ['zones', '/'], ['zone', zonePath], ['import', `${zonePath}/import`], ['audit', '/audit'], ['account', '/account'], ['users', '/users'], ['user', userPath], ]; for (const colorScheme of ['light', 'dark'] as const) { for (const width of [360, 1440]) { const opts = { colorScheme, viewport: { width, height: 900 } }; const assess = async (ui: Awaited>, name: string, target: string, status = 200) => { expect((await ui.goto(target))?.status(), target).toBe(status); await expect(ui.page.getByRole('heading', { level: 1 })).toBeVisible(); const { violations } = await new AxeBuilder({ page: ui.page }).analyze(); const severe = violations.filter(({ impact }) => impact === 'serious' || impact === 'critical'); await ui.page.screenshot({ path: path.join(SCREENSHOTS_DIR, `${name}-${width}-${colorScheme}.png`), fullPage: true }); expect.soft(severe.map(({ id, nodes }) => ({ id, targets: nodes.map((n) => n.target) })), `${name} at ${width}px in ${colorScheme}`).toEqual([]); }; const anon = await world.ui(opts); await assess(anon, 'login', '/login'); await assess(anon, 'version', '/version'); await anon.close(); const adminUi = await world.uiAs(admin, opts); for (const [name, target] of adminPages) await assess(adminUi, name, target); await adminUi.close(); const userUi = await world.uiAs(user, opts); await assess(userUi, 'forbidden', '/users', 403); await assess(userUi, 'not-found', zonePath, 404); await userUi.close(); } } });