import fs from 'node:fs'; import { createRequire } from 'node:module'; import { expect, type Page } from '@playwright/test'; const axeSource = fs.readFileSync(createRequire(import.meta.url).resolve('axe-core/axe.min.js'), 'utf8'); /** Prüft die Seite mit axe auf WCAG 2.2 AA – erwartet 0 Verstöße */ export async function expectAccessible(page: Page) { await page.addScriptTag({ content: axeSource }); const violations = await page.evaluate(async () => { // @ts-expect-error axe wird oben eingebunden const r = await window.axe.run(document, { runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa', 'best-practice'] }); return r.violations.map((v: { id: string; nodes: { target: string[] }[] }) => `${v.id}: ${v.nodes.map((n) => n.target.join(' ')).slice(0, 3).join(' | ')}`); }); expect(violations, `axe auf ${page.url()}`).toEqual([]); } export async function login(page: Page, email = 'admin@example.org') { await page.goto('/admin/login'); await page.fill('#email', email); await page.fill('#password', 'demo-passwort'); await page.getByRole('button', { name: 'Anmelden' }).click(); await page.waitForURL((u) => !u.pathname.includes('login')); } /** Einstellungen speichern und warten, bis die Antwort da ist */ export async function saveSettings(page: Page) { await Promise.all([ page.waitForResponse((r) => r.url().includes('/admin/einstellungen') && r.request().method() === 'POST'), page.getByRole('button', { name: 'Speichern' }).first().click() ]); }