import { test, expect, type Locator, type Page } from "@playwright/test" import axe from "axe-core" import { certificateRoutes, openIssue } from "./fixtures/certificate-issue" import { setupBackups } from "./fixtures/backups" import { openBackup } from "./fixtures/backup-job" async function check(page: Page, dialog: Locator) { const tabs = dialog.getByRole("tablist", { name: "Шаги формы" }).getByRole("tab") const ids: string[] = [] for (const tab of await tabs.all()) { const id = await tab.getAttribute("id"), panelId = await tab.getAttribute("aria-controls") expect(id).toBeTruthy(); expect(panelId).toBeTruthy(); ids.push(id!, panelId!) expect(await page.evaluate(id => document.getElementById(id!)?.getAttribute("aria-labelledby"), panelId)).toBe(id) } expect(new Set(ids).size).toBe(ids.length) for (const tab of await tabs.all()) { await tab.click() await expect(tab).toHaveAttribute("aria-selected", "true") await expect(dialog.getByRole("tabpanel")).toHaveCount(1) expect(await dialog.getByRole("tabpanel").getAttribute("id")).toBe(await tab.getAttribute("aria-controls")) } await page.addScriptTag({ content: axe.source }) const violations = await dialog.evaluate(async element => { const result = await (window as unknown as { axe: typeof axe }).axe.run(element, { runOnly: { type: "rule", values: ["aria-required-children", "aria-required-parent", "aria-valid-attr-value", "aria-valid-attr"] } }) return result.violations.map(v => v.id) }) expect(violations).toEqual([]) } test("Stepper: выпуск — панели связаны со всеми вкладками", async ({ page }) => { await certificateRoutes(page); await check(page, await openIssue(page)) }) test("Stepper: backup — панели связаны со всеми вкладками", async ({ page }) => { await setupBackups(page); await check(page, await openBackup(page)) }) test("Stepper: создание сервера — панели связаны со всеми вкладками", async ({ page }) => { await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", r => r.fulfill({ json: new URL(r.request().url()).pathname === "/api/auth/config" ? { required: false } : new URL(r.request().url()).pathname === "/api/servers" ? [] : {} })) await page.goto("/servers"); await page.getByRole("button", { name: "Добавить сервер", exact: true }).click() await check(page, page.getByRole("dialog")) })