Files
such.software/apps/web/tests/a11y.spec.ts
T
such-gitea f495e35764 feat(privacy): explain the platform's role to customers of merchant shops
Add /privacy/shops for customers of independent shops on the Such Software
commerce platform. Every storefront footer links Platform Privacy, and the
main policy described only the website, so a shop customer had no account
of who the seller is or what the platform does with their information.

The page names the merchant as seller of record and Such Software as the
service provider acting on the merchant's instructions, lists the uses,
what the platform never does, and the services involved in an order, and
routes order and data requests to the merchant and platform questions to
support. Retention, hosting location and a published sub-processor list
are left out until they are decided.

The main privacy page links the new page, the sitemap ranks it with the
other legal pages, and it joins the accessibility suite.
2026-11-16 20:53:14 -05:00

153 lines
5.3 KiB
TypeScript

import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
// Skip webkit for home page - canvas/WebGL issues cause error state
const isWebkit = (browserName: string) => browserName === "webkit";
const pages = [
{ name: "Home", path: "/" },
{ name: "Services", path: "/services" },
{ name: "About", path: "/about" },
{ name: "Shop Privacy", path: "/privacy/shops" },
];
for (const { name, path } of pages) {
test.describe(`${name} Page Accessibility`, () => {
test(`should have no WCAG 2.2 AA violations`, async ({ page, browserName }) => {
// Skip webkit on home page due to canvas/WebGL compatibility issues
test.skip(isWebkit(browserName) && path === "/", "Webkit has canvas issues on home page");
await page.goto(path);
await page.waitForLoadState("domcontentloaded");
// Give time for React hydration
await page.waitForTimeout(1000);
const results = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag22aa"])
.analyze();
expect(results.violations).toEqual([]);
});
test(`should have proper heading hierarchy`, async ({ page }) => {
await page.goto(path);
await page.waitForLoadState("domcontentloaded");
const headings = await page.evaluate(() => {
const h = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
return Array.from(h).map((el) => ({
level: parseInt(el.tagName[1]),
text: el.textContent?.trim().slice(0, 50),
}));
});
// Should have exactly one h1
const h1s = headings.filter((h) => h.level === 1);
expect(h1s.length).toBe(1);
// No skipped heading levels
for (let i = 1; i < headings.length; i++) {
const current = headings[i].level;
const previous = headings[i - 1].level;
const skipped = current > previous + 1;
expect(skipped, `Heading "${headings[i].text}" skips levels`).toBe(false);
}
});
test(`should have no color contrast issues`, async ({ page, browserName }) => {
test.skip(isWebkit(browserName) && path === "/", "Webkit has canvas issues on home page");
await page.goto(path);
await page.waitForLoadState("domcontentloaded");
await page.waitForTimeout(1000);
const results = await new AxeBuilder({ page })
.withTags(["wcag2aa"])
.options({ runOnly: ["color-contrast"] })
.analyze();
expect(results.violations).toEqual([]);
});
test(`should be keyboard navigable`, async ({ page }) => {
await page.goto(path);
await page.waitForLoadState("domcontentloaded");
// Tab through interactive elements
const focusableElements = await page.evaluate(() => {
const elements = document.querySelectorAll(
'a[href], button, input, textarea, select, [tabindex]:not([tabindex="-1"])'
);
return elements.length;
});
expect(focusableElements).toBeGreaterThan(0);
// First tab should reach skip link or first focusable element
await page.keyboard.press("Tab");
const firstFocused = await page.evaluate(() => document.activeElement?.tagName);
expect(firstFocused).toBeTruthy();
});
});
}
test.describe("Theme Accessibility", () => {
test("should maintain accessibility in dark mode", async ({ page, browserName }) => {
test.skip(isWebkit(browserName), "Webkit has canvas issues on home page");
await page.goto("/");
await page.waitForLoadState("domcontentloaded");
await page.waitForTimeout(1000);
// Toggle to dark mode
const themeToggle = page.getByRole("button", { name: /theme|dark|light/i });
if (await themeToggle.isVisible()) {
await themeToggle.click();
await page.waitForTimeout(500);
}
const results = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa"])
.analyze();
expect(results.violations).toEqual([]);
});
});
test.describe("Form Accessibility", () => {
test("contact form should have proper labels and ARIA", async ({ page, browserName }) => {
test.skip(isWebkit(browserName), "Webkit has canvas issues on home page");
await page.goto("/");
await page.waitForLoadState("domcontentloaded");
await page.waitForTimeout(1000);
// Scroll to contact section
await page.evaluate(() => {
document.getElementById("contact")?.scrollIntoView();
});
await page.waitForTimeout(500);
// Check form fields exist with accessible names (label or aria-label)
const nameInput = page.locator('input[name="name"]');
const emailInput = page.locator('input[name="email"]');
const messageInput = page.locator('textarea[name="message"]');
await expect(nameInput).toBeVisible();
await expect(emailInput).toBeVisible();
await expect(messageInput).toBeVisible();
// Check fields have accessible labels (via label element or aria-label)
const nameLabel = await nameInput.evaluate((el) => {
const label = document.querySelector(`label[for="${el.id}"]`);
return label?.textContent || el.getAttribute("aria-label") || el.getAttribute("placeholder");
});
expect(nameLabel).toBeTruthy();
// Check required fields are marked
await expect(nameInput).toHaveAttribute("required");
await expect(emailInput).toHaveAttribute("required");
await expect(messageInput).toHaveAttribute("required");
});
});