Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/components/ui/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/features/recipe-detail/RecipeDetailPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 14 additions & 4 deletions apps/web/src/styles/tokens.css
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
173 changes: 173 additions & 0 deletions e2e/accessibility.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
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<string, unknown>;
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')) {
// 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 };
}
await route.fulfill({ json: { data } });
});
}

// `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',
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,
ready: recipe.title,
},
{ 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();
if (target.ready)
await expect(
page.getByRole('link', { name: target.ready }).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([]);
});
}
}
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down