Download web/e2e/a11y.e2e.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 3.75 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/e2e/a11y.e2e.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/e2e/a11y.e2e.ts
-
curl -L -o a11y.e2e.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/e2e/a11y.e2e.ts
3.75 kB
| // Accessibility gate: axe-core on every main screen at 1280 and 375 px, light and dark. Serious and critical violations | |
| // fail the test; moderate and minor ones are attached as annotations so they stay visible without blocking. | |
| import AxeBuilder from '@axe-core/playwright'; | |
| import { expect, test, type Browser, type Page } from '@playwright/test'; | |
| import { E2E_PASSWORD, E2E_USER } from './playwright.config'; | |
| const ROUTES = ['/', '/runs', 'RUN', 'RUN/scenarios', 'RUN/workflow', 'RUN/report', '/assistant', '/scenarios', '/tickets', '/reports', '/pods', | |
| '/account', '/admin', '/agents', '/audit', '/learner', '/admin/users']; | |
| const VIEWS = [{ width: 1280, scheme: 'light' }, { width: 1280, scheme: 'dark' }, { width: 375, scheme: 'light' }, { width: 375, scheme: 'dark' }] as const; | |
| const BLOCKING = new Set(['serious', 'critical']); | |
| async function scan(page: Page, where: string) { | |
| const r = await new AxeBuilder({ page }).analyze(); | |
| const blocking = r.violations.filter((v) => BLOCKING.has(v.impact ?? '')); | |
| for (const v of r.violations.filter((x) => !BLOCKING.has(x.impact ?? ''))) { | |
| test.info().annotations.push({ type: `a11y ${v.impact}`, description: `${where}: ${v.id} (${v.nodes.length}) ${v.help}` }); | |
| } | |
| return blocking.map((v) => `${where}: ${v.id} [${v.impact}] x${v.nodes.length}: ${v.help} -> ${v.nodes.slice(0, 2).map((n) => n.target.join(' ')).join(' ; ')}`); | |
| } | |
| async function signedIn(browser: Browser, width: number, scheme: 'light' | 'dark') { | |
| const ctx = await browser.newContext({ viewport: { width, height: width < 800 ? 900 : 1000 }, colorScheme: scheme, reducedMotion: 'reduce' }); | |
| const page = await ctx.newPage(); | |
| await page.goto('/login'); | |
| await page.getByLabel('Username').fill(E2E_USER); | |
| await page.getByLabel('Password').fill(E2E_PASSWORD); | |
| await page.getByRole('button', { name: 'Sign in' }).click(); | |
| await page.waitForURL((u) => !u.pathname.startsWith('/login')); | |
| return { ctx, page }; | |
| } | |
| test.describe.configure({ mode: 'serial' }); | |
| test.setTimeout(900_000); | |
| test('signed out: the sign-in page has no serious or critical accessibility problems', async ({ browser }) => { | |
| const problems: string[] = []; | |
| for (const v of VIEWS) { | |
| const ctx = await browser.newContext({ viewport: { width: v.width, height: 900 }, colorScheme: v.scheme, reducedMotion: 'reduce' }); | |
| const page = await ctx.newPage(); | |
| await page.goto('/login'); | |
| await page.getByLabel('Username').waitFor(); | |
| problems.push(...await scan(page, `/login ${v.width} ${v.scheme}`)); | |
| await ctx.close(); | |
| } | |
| expect(problems, problems.join('\n')).toEqual([]); | |
| }); | |
| test('signed in: every main screen has no serious or critical accessibility problems', async ({ browser }) => { | |
| // one stub run so the run screens have content | |
| const first = await signedIn(browser, 1280, 'light'); | |
| const csrf = (await first.ctx.cookies()).find((c) => c.name === 'fpt_csrf')?.value ?? ''; | |
| const res = await first.page.request.post('/api/runs', { data: { modules: ['P2P'], playwright_mode: 'stub' }, headers: { 'X-CSRF-Token': csrf } }); | |
| expect(res.ok()).toBeTruthy(); | |
| const runId = (await res.json()).run_id as string; | |
| await first.ctx.close(); | |
| const problems: string[] = []; | |
| for (const v of VIEWS) { | |
| const { ctx, page } = await signedIn(browser, v.width, v.scheme); | |
| for (const route of ROUTES) { | |
| const url = route.replace('RUN', `/runs/${runId}`); | |
| await page.goto(url); | |
| await page.waitForLoadState('networkidle').catch(() => undefined); | |
| problems.push(...await scan(page, `${route} ${v.width} ${v.scheme}`)); | |
| } | |
| await ctx.close(); | |
| } | |
| expect(problems, problems.join('\n')).toEqual([]); | |
| }); | |