From b513053842d8d81d7468010748ee8c42e597b55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 13:52:11 +0100 Subject: [PATCH 1/2] fix(a11y): raise brand colour contrast to WCAG AA White text on the brand orange (#e86a1c) was 3.23:1 and orange text on the light surfaces was below 4.5:1, failing axe color-contrast on most pages. Shift the brand ramp one step darker (primary #a8470b, hover #9a3f08, active #8f3a06) and use secondary text for the desktop servings hint. Add an axe-core Playwright suite that checks WCAG 2.x A/AA rules on public and signed-in pages at desktop and mobile widths, so contrast regressions fail CI. Closes #67 --- apps/web/src/components/ui/SKILL.md | 2 +- .../recipe-detail/RecipeDetailPage.css | 4 +- apps/web/src/styles/tokens.css | 18 ++- e2e/accessibility.spec.ts | 149 ++++++++++++++++++ package-lock.json | 24 +++ package.json | 1 + 6 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 e2e/accessibility.spec.ts diff --git a/apps/web/src/components/ui/SKILL.md b/apps/web/src/components/ui/SKILL.md index 310e944..af271d6 100644 --- a/apps/web/src/components/ui/SKILL.md +++ b/apps/web/src/components/ui/SKILL.md @@ -83,7 +83,7 @@ instead of repeating equivalent raw values. Do not add CSS variable fallbacks such as: ```css -var(--color-brand-primary, #e86a1c) +var(--color-brand-primary, #a8470b) ``` when the project guarantees that `tokens.css` is loaded. diff --git a/apps/web/src/features/recipe-detail/RecipeDetailPage.css b/apps/web/src/features/recipe-detail/RecipeDetailPage.css index 059b14d..3c8a8c0 100644 --- a/apps/web/src/features/recipe-detail/RecipeDetailPage.css +++ b/apps/web/src/features/recipe-detail/RecipeDetailPage.css @@ -259,7 +259,9 @@ .recipe-detail-page__servings-control p { margin-block-start: var(--space-1); - color: var(--color-text-muted); + /* Secondary, not muted: muted text is only 4.4:1 on the desktop panel's + --color-surface-muted background; secondary keeps it at 4.8:1. */ + color: var(--color-text-secondary); font-size: var(--font-size-xs); } diff --git a/apps/web/src/styles/tokens.css b/apps/web/src/styles/tokens.css index ef84314..202c5a4 100644 --- a/apps/web/src/styles/tokens.css +++ b/apps/web/src/styles/tokens.css @@ -1,8 +1,18 @@ :root { - /* Brand */ - --color-brand-primary: #e86a1c; - --color-brand-primary-hover: #cc5b14; - --color-brand-primary-active: #b84f0d; + /* + * Brand + * + * Brand colours are used both as button backgrounds (with white text) and + * as text/link colour on the light surfaces. They must keep at least 4.5:1 + * contrast (WCAG 2.2 AA) in both roles: + * - primary on white text: 5.88:1, on --color-bg-page: 5.21:1, + * on --color-surface-selected: 4.67:1 + * - hover: 6.80:1 and active: 7.57:1 with white text + * Check new values against these surfaces before changing them. + */ + --color-brand-primary: #a8470b; + --color-brand-primary-hover: #9a3f08; + --color-brand-primary-active: #8f3a06; --color-brand-accent-soft: #fff4e8; /* Backgrounds and surfaces */ diff --git a/e2e/accessibility.spec.ts b/e2e/accessibility.spec.ts new file mode 100644 index 0000000..3d3a3bf --- /dev/null +++ b/e2e/accessibility.spec.ts @@ -0,0 +1,149 @@ +import AxeBuilder from '@axe-core/playwright'; +import { expect, test, type Page } from '@playwright/test'; +import type { + RecipeFieldsFragment, + RecipeSummaryFieldsFragment, +} from '../contracts/generated'; + +/* + * Automated WCAG checks with axe-core. + * + * The pages run against the static preview build with the GraphQL API mocked, + * like the smoke tests, so the checks need no database. Only WCAG 2.x A/AA + * rules are enforced; axe "best-practice" rules are advisory and left out. + * axe finds roughly a third of accessibility problems, so keyboard tests and + * manual checks are still needed. + */ + +const WCAG_TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa']; + +const recipe: RecipeFieldsFragment = { + id: '11111111-1111-4111-8111-111111111111', + title: 'Creamy salmon pasta', + description: 'Weeknight pasta with salmon, lemon and dill.', + category: 'dinner', + cuisine: 'Italian', + difficulty: 'easy', + visibility: 'public', + imageUrl: null, + sourceRecipeId: null, + prepMinutes: 5, + cookMinutes: 10, + servings: 2, + createdAt: '2026-10-22T12:00:00Z', + updatedAt: '2026-10-22T12:00:00Z', + author: { id: 'chef', name: 'Chef' }, + ingredients: [ + { id: 'i1', name: 'Pasta', amount: 200, unit: 'g', note: null }, + { id: 'i2', name: 'Salmon', amount: 150, unit: 'g', note: 'skinless' }, + ], + instructions: [ + { step: 1, text: 'Boil the pasta.' }, + { step: 2, text: 'Fry the salmon and mix.' }, + ], + tags: ['pasta', 'fish', 'quick'], + rating: { average: 4.5, count: 2 }, + userRating: null, + saveCount: 3, + isSaved: false, + isCreatedByCurrentUser: false, +}; + +const summary: RecipeSummaryFieldsFragment = { + id: recipe.id, + title: recipe.title, + description: recipe.description, + visibility: recipe.visibility, + imageUrl: recipe.imageUrl, + prepMinutes: recipe.prepMinutes, + cookMinutes: recipe.cookMinutes, + servings: recipe.servings, + tags: recipe.tags, + rating: recipe.rating, + isSaved: recipe.isSaved, + isCreatedByCurrentUser: recipe.isCreatedByCurrentUser, +}; + +const recipePage = { + items: [summary], + totalCount: 1, + totalPages: 1, + page: 1, + pageSize: 6, +}; + +const user = { + id: 'a11y-user', + name: 'Axe Tester', + email: 'axe@example.invalid', +}; + +/** Answers the client's GraphQL operations with fixed data. */ +async function mockApi(page: Page, signedIn: boolean) { + await page.route('**/project2/api/graphql', async (route) => { + const body = route.request().postDataJSON() as { + query?: string; + variables?: { id?: string }; + }; + const query = body.query ?? ''; + let data: Record; + if (query.includes('query CurrentUser')) { + data = { currentUser: signedIn ? user : null }; + } else if (query.includes('query Recipes')) { + data = { recipes: recipePage }; + } else if (query.includes('query Cookbook')) { + data = { cookbook: recipePage }; + } else { + data = { recipe: body.variables?.id === recipe.id ? recipe : null }; + } + await route.fulfill({ json: { data } }); + }); +} + +const pages = [ + { path: '.', heading: 'Explore Recipes', signedIn: false }, + { path: `recipes/${recipe.id}`, heading: recipe.title, signedIn: false }, + { + path: 'recipes/00000000-0000-4000-8000-000000000000', + heading: 'Recipe not found', + signedIn: false, + }, + { path: 'login', heading: 'Log in', signedIn: false }, + { path: 'register', heading: 'Register', signedIn: false }, + { path: 'does-not-exist', heading: 'Page not found', signedIn: false }, + { path: 'cookbook', heading: 'My Cookbook', signedIn: true }, + { path: 'recipes/new', heading: 'Add Recipe', signedIn: true }, +]; + +const viewports = [ + { name: 'desktop', width: 1280, height: 800 }, + { name: 'mobile', width: 375, height: 812 }, +]; + +for (const viewport of viewports) { + for (const target of pages) { + test(`${target.path} has no WCAG A/AA violations on ${viewport.name}`, async ({ + page, + }) => { + await mockApi(page, target.signedIn); + await page.setViewportSize(viewport); + await page.goto(target.path); + // Wait for data to render so the scan covers the real page content. + await expect( + page.getByRole('heading', { name: target.heading }).first(), + ).toBeVisible(); + + const results = await new AxeBuilder({ page }) + .withTags(WCAG_TAGS) + .analyze(); + + // Print a readable summary instead of the raw axe objects on failure. + const violations = results.violations.map( + (violation) => + `${violation.id} (${violation.impact}): ${violation.help} -> ` + + violation.nodes.map((node) => node.target.join(' ')).join(', '), + ); + expect(violations).toEqual([]); + }); + } +} diff --git a/package-lock.json b/package-lock.json index 60476a7..8eadc62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "apps/*" ], "devDependencies": { + "@axe-core/playwright": "4.10.2", "@eslint/js": "9.39.5", "@graphql-codegen/core": "6.2.0", "@graphql-codegen/typed-document-node": "7.1.0", @@ -164,6 +165,29 @@ "dev": true, "license": "MIT" }, + "node_modules/@axe-core/playwright": { + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/@axe-core/playwright/-/playwright-4.10.2.tgz", + "integrity": "sha512-6/b5BJjG6hDaRNtgzLIfKr5DfwyiLHO4+ByTLB0cJgWSM8Ll7KqtdblIS6bEkwSF642/Ex91vNqIl3GLXGlceg==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "axe-core": "~4.10.3" + }, + "peerDependencies": { + "playwright-core": ">= 1.0.0" + } + }, + "node_modules/@axe-core/playwright/node_modules/axe-core": { + "version": "4.10.3", + "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.10.3.tgz", + "integrity": "sha512-Xm7bpRXnDSX2YE2YFfBk2FnF0ep6tmG7xPh8iHee8MIcrgq762Nkce856dYtJYLkuIoYZvGfTs/PbZhideTcEg==", + "dev": true, + "license": "MPL-2.0", + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", diff --git a/package.json b/package.json index 09c0afc..ea8f538 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "images:cleanup": "tsx --env-file-if-exists=.env scripts/cleanup-images.ts" }, "devDependencies": { + "@axe-core/playwright": "4.10.2", "@eslint/js": "9.39.5", "@graphql-codegen/core": "6.2.0", "@graphql-codegen/typed-document-node": "7.1.0", From 3f69c96ea87f9f93192dfb6876eef016deaabb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 19:10:10 +0100 Subject: [PATCH 2/2] test(a11y): scan after recipe data has rendered; realistic cookbook Review on #86 (non-blocking): Explore and Cookbook now wait for the recipe card link before running axe, so the scan covers the loaded results rather than the loading state, and the Cookbook mock returns a recipe the user has saved. Refs #67 --- e2e/accessibility.spec.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/e2e/accessibility.spec.ts b/e2e/accessibility.spec.ts index 3d3a3bf..f25bce7 100644 --- a/e2e/accessibility.spec.ts +++ b/e2e/accessibility.spec.ts @@ -92,7 +92,10 @@ async function mockApi(page: Page, signedIn: boolean) { } else if (query.includes('query Recipes')) { data = { recipes: recipePage }; } else if (query.includes('query Cookbook')) { - data = { cookbook: recipePage }; + // A realistic cookbook entry: a recipe the signed-in user has saved. + data = { + cookbook: { ...recipePage, items: [{ ...summary, isSaved: true }] }, + }; } else { data = { recipe: body.variables?.id === recipe.id ? recipe : null }; } @@ -100,8 +103,20 @@ async function mockApi(page: Page, signedIn: boolean) { }); } -const pages = [ - { path: '.', heading: 'Explore Recipes', signedIn: false }, +// `ready`: a recipe link that only exists once the page's data has loaded, +// so the scan covers the rendered results, not the loading state. +const pages: { + path: string; + heading: string; + signedIn: boolean; + ready?: string; +}[] = [ + { + path: '.', + heading: 'Explore Recipes', + signedIn: false, + ready: recipe.title, + }, { path: `recipes/${recipe.id}`, heading: recipe.title, signedIn: false }, { path: 'recipes/00000000-0000-4000-8000-000000000000', @@ -111,7 +126,12 @@ const pages = [ { path: 'login', heading: 'Log in', signedIn: false }, { path: 'register', heading: 'Register', signedIn: false }, { path: 'does-not-exist', heading: 'Page not found', signedIn: false }, - { path: 'cookbook', heading: 'My Cookbook', signedIn: true }, + { + path: 'cookbook', + heading: 'My Cookbook', + signedIn: true, + ready: recipe.title, + }, { path: 'recipes/new', heading: 'Add Recipe', signedIn: true }, ]; @@ -132,6 +152,10 @@ for (const viewport of viewports) { await expect( page.getByRole('heading', { name: target.heading }).first(), ).toBeVisible(); + if (target.ready) + await expect( + page.getByRole('link', { name: target.ready }).first(), + ).toBeVisible(); const results = await new AxeBuilder({ page }) .withTags(WCAG_TAGS)