/** * Every listing page layout in every template (backend variants.ts PAGE_VARIANTS): the demo * church's Ministries, Leadership, Events, Messages and Contact pages, one layout at a time. Each * page answers, shows what it lists, keeps the anchors the homepage links to, and axe finds no * violations (WCAG 2.2 AA) at phone and desktop width. * * PAGE_SHOTS= also saves a full-page screenshot of each, to look through by eye. */ import AxeBuilder from "@axe-core/playwright"; import { expect, test } from "@playwright/test"; import { PAGE_LAYOUT_KEYS, PAGE_VARIANTS, TEMPLATE_VARIANTS } from "../backend/src/site/variants.js"; const BACKEND = "http://127.0.0.1:5310"; const TEMPLATES = Object.keys(TEMPLATE_VARIANTS) as (keyof typeof TEMPLATE_VARIANTS)[]; const WIDTHS = [["phone", { width: 390, height: 844 }], ["desktop", { width: 1366, height: 900 }]] as const; const SHOTS = process.env.PAGE_SHOTS; /** The demo's page for each layout key, and something it must show. */ const PAGES: Record<(typeof PAGE_LAYOUT_KEYS)[number], { path: string; shows: string }> = { ministriesPage: { path: "/ministries", shows: "main [id] h2" }, leadershipPage: { path: "/leadership", shows: "main article h2" }, eventsPage: { path: "/events", shows: 'main a[href]:not([href^="#"])' }, messagesPage: { path: "/messages", shows: "main [id] h2" }, contactPage: { path: "/contact", shows: 'main a[href^="mailto:"]' }, }; for (const template of TEMPLATES) { test.describe(`${template} page layouts`, () => { test.beforeAll(async ({ request }) => { expect((await request.post(`${BACKEND}/test/demo?template=${template}`)).ok()).toBeTruthy(); }); for (const key of PAGE_LAYOUT_KEYS) { for (const layout of PAGE_VARIANTS[key]) { test(`${key}: ${layout}`, async ({ page }) => { const res = await page.request.post(`${BACKEND}/test/design`, { data: { variants: { [key]: layout } } }); expect(res.ok()).toBeTruthy(); const { path, shows } = PAGES[key]; for (const [name, size] of WIDTHS) { await page.setViewportSize(size); expect((await page.goto(path))?.status()).toBe(200); await expect(page.locator("html")).toHaveAttribute("data-template", template); await expect(page.locator(shows).first()).toBeVisible(); const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze(); expect(axe.violations.map((v) => `${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`), name).toEqual([]); if (SHOTS) await page.screenshot({ path: `${SHOTS}/${template}-${key}-${layout}-${name}.png`, fullPage: true }); } }); } } }); }