import AxeBuilder from "@axe-core/playwright"; import { test, expect } from "@playwright/test"; type AxeViolation = { id: string; help: string; impact?: string | null; nodes: Array<{ target?: unknown; failureSummary?: string }> }; const severity = (violations: AxeViolation[]) => violations.filter((violation) => violation.impact === "critical" || violation.impact === "serious") .map((violation) => `${violation.id}: ${violation.help} (${violation.nodes.length} nodes) :: ${violation.nodes.slice(0, 6).map((node) => `${JSON.stringify(node.target)} ${node.failureSummary ?? ""}`).join(" | ")}`); test("reducer tutorial landing, React course tree and live hierarchy tree are accessible", async ({ page }) => { test.setTimeout(240_000); await page.goto("/?tutorial=reducer"); await expect(page.getByRole("heading", { name: /从零制作/ })).toBeVisible({ timeout: 60_000 }); const courseTree = page.getByRole("tree", { name: "二级减速器课程结构" }); await expect(courseTree).toBeVisible({ timeout: 30_000 }); await expect(courseTree.getByRole("treeitem").first()).toBeVisible(); const landing = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]).analyze(); expect(severity(landing.violations)).toEqual([]); await page.getByRole("button", { name: /开始学习/ }).click(); const panel = page.locator('[data-course="reducer"]'); await expect(panel).toBeVisible({ timeout: 120_000 }); await expect(page.getByRole("button", { name: /^下一步/ })).toBeEnabled({ timeout: 180_000 }); await page.getByRole("button", { name: /^下一步/ }).click(); await expect(page.locator('[data-tutorial-step="housing-block"]')).toBeVisible(); await expect(panel.locator(".tutorial-checks")).toHaveAttribute("aria-live", "polite"); // The assembly step renders the live React hierarchy tree from SceneIR. await page.getByRole("button", { name: "查看课程目录" }).click(); await page.locator("nav.tutorial-steps button", { hasText: "轴组件 Empty" }).click(); await expect(page.locator('[data-tutorial-step="shaft-assemblies"]')).toBeVisible(); const hierarchy = page.getByRole("tree", { name: "场景装配层级" }); await expect(hierarchy).toBeVisible(); await expect(hierarchy.getByRole("treeitem").first()).toBeVisible(); const overlay = await new AxeBuilder({ page }).include(".parts-tutorial-overlay").withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]).analyze(); expect(severity(overlay.violations)).toEqual([]); });