import AxeBuilder from '@axe-core/playwright' import { expect, test, type Page } from '@playwright/test' import { authenticateAs } from '@/e2e/fixtures/session' const expectNoSeriousViolations = async (page: Page) => { await page.waitForLoadState('domcontentloaded') await page.locator('body').waitFor({ state: 'visible' }) let violations try { ;({ violations } = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21aa']).analyze()) } catch (error) { if (!(error instanceof Error) || !error.message.includes('Execution context was destroyed')) throw error await page.waitForLoadState('domcontentloaded') ;({ violations } = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21aa']).analyze()) } const blocking = violations.filter(({ impact }) => impact === 'critical' || impact === 'serious') expect(blocking, blocking.map(({ id, help }) => `${id}: ${help}`).join('\n')).toEqual([]) } test('auth route has no serious automated accessibility violations', async ({ page }) => { await page.goto('/auth') await expectNoSeriousViolations(page) }) test('admin shell has no serious automated accessibility violations', async ({ context, page }) => { await authenticateAs(context, page, 'admin') await page.route('**/api/v1/**', (route) => route.fulfill({ json: { success: true, data: {} } })) await page.route('**/api/v1/admin/reports/overview', (route) => route.fulfill({ json: { success: true, data: { users: { total: 0, active: 0, pending: 0, suspended: 0 }, events: { total: 0, active: 0, totalHeld: 0, byStatus: { draft: 0, pending_review: 0, published: 0, full: 0, cancelled: 0, completed: 0 }, }, bookings: { total: 0, byStatus: { pending_payment: 0, confirmed: 0, cancelled: 0, expired: 0, refunded: 0, no_show: 0 } }, identityVerifications: { none: 0, pending: 0, verified: 0, rejected: 0 }, financial: { totalCommissionCollected: '0', totalWalletBalance: '0' }, }, }, }) ) await page.goto('/dashboard') await expect(page.getByText('کل کاربران').first()).toBeVisible() await expect(page.locator('#mainContent')).toHaveCSS('opacity', '1') await expectNoSeriousViolations(page) })