diff --git a/README.md b/README.md
index e93cbb6..64c9686 100644
--- a/README.md
+++ b/README.md
@@ -240,12 +240,12 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing,
### Implemented
- Semantic HTML: landmarks (`header`, `nav`, `main`, `footer`), one `h1` per page, lists for groups of cards, and `` for each wine card. We try to use `div` and `span` only for layout. See [conventions](#code-quality-and-conventions).
-- A skip link to the main content, and visible focus on all interactive elements.
+- A skip link to the main content, and visible focus on all interactive elements. An end-to-end test tabs through the main pages and fails if an element gets focus without a visible mark.
- After navigation, focus moves to the page's `h1`. Screen reader users then hear that the page has changed.
- Ratings are always shown as text, for example "4,6 av 5 · 23 dommer". The stars have a text alternative, so a screen reader reads «3,5 av 5 stjerner» instead of five images.
- Giving a review works with the keyboard: the stars are radio buttons, so the arrow keys move through every half star, and each half is at least 24 × 24 px to click (WCAG 2.5.8).
- Loading states are announced in a live region. Errors use `role="alert"` and have a "Prøv igjen" button. The message after saving a review stays in the same live region, so it is announced.
-- Click targets are at least 44 × 44 px. The heart and the bookmark on the wine cards are 44 × 40 px, so they sit closer together; that is still well above the 24 px WCAG 2.5.8 asks for.
+- Click targets are at least 44 × 44 px, and an end-to-end test measures them on the main pages on desktop and mobile. There are three exceptions. The heart and the bookmark on the wine cards are 44 × 40 px, so they sit closer together. Each half star in the review form is 24 × 48 px. Both are above the 24 × 24 px that WCAG 2.5.8 asks for. Links in running text and the grape links on the wine page are as tall as the text, which WCAG 2.5.8 allows for links in text.
- The list buttons are toggle buttons (`aria-pressed`). On the wine page they have visible text in a named group. On the cards they are icons, with the wine's name in the accessible name («Favoritt Origem Merlot»). A pressed button gets a filled icon and a background, so the state does not rest on colour alone.
- «Endre topp 4» uses buttons only, no drag and drop: «Flytt opp», «Flytt ned», «Ta ut» and «Legg til», named with the wine. Each change is read out, focus never jumps to the top of the page, and a button that does nothing right now (`aria-disabled`) can still have focus.
- When a wine disappears from a list on «Min side», a live region says so and focus moves to the list's heading.
@@ -345,7 +345,7 @@ compress files at the time and the test was run over VPN. Turning on compression
|---|---|---|---|
| Unit and components (frontend) | Vitest, React Testing Library, user-event, vitest-axe | URL parameters, formatting, mapping of API data, data hooks, components, the landing page, the wine page with reviews, the list buttons, «Min side», the list pages, the reviews page and «Endre topp 4», the cache rules for the lists, an expired session, loading, empty and error states, and axe on each component | 421 in 46 files |
| Unit (backend) | Vitest | Parsing of X-Wines CSV files, building SQL for search, filtering and sorting, review validation, and passwords, sessions and rate limiting | 147 in 17 files (42 tests, 4 files skipped: they need a test database) |
-| End-to-end | Playwright with axe-core, desktop and mobile | Landing, search and detail pages with a stubbed API: one request per page load, debounce, search, filters, sorting, load more, reload, back button, from search to wine and back, the filter dialog on mobile, no hits, wine not found, API errors, keyboard use, reflow at 320 px, the wine lists (also after a reload, with login on the way, and the move of an old list), «Min side» from login to logout with the top 4 chosen with the keyboard, and no axe violations (WCAG 2.1 AA) | 86 (2 skipped) |
+| End-to-end | Playwright with axe-core, desktop and mobile | Landing, search and detail pages with a stubbed API: one request per page load, debounce, search, filters, sorting, load more, reload, back button, from search to wine and back, the filter dialog on mobile, no hits, wine not found, API errors, keyboard use, reflow at 320 px, the wine lists (also after a reload, with login on the way, and the move of an old list), «Min side» from login to logout with the top 4 chosen with the keyboard, click targets of at least 44 × 44 px and visible focus on the main pages, and no axe violations (WCAG 2.1 AA) | 110 (6 skipped) |
| API | Vitest with Apollo Server (`executeOperation`) | Login, reviews, wine lists, the top 4 and the demo user through real GraphQL requests, with a fake browser per user that keeps the cookie. The review tests run against a separate test database (`TEST_DATABASE_URL`), see [API](docs/api.md#database-tests) | Count again |
| End-to-end with the backend | Playwright, desktop | The same pages against the real backend and a PostgreSQL test database (`TEST_DATABASE_URL`), with nothing stubbed: search, filter, sorting and «Last inn flere» on the 100 test wines, a new user with login, logout and a wrong password, a review from search to «Min side», a favourite that follows the user to another browser, and two users who review the same wine. See [API](docs/api.md#end-to-end-tests-with-the-backend) | 11 in 5 files |
diff --git a/frontend/e2e/support/fakeApi.ts b/frontend/e2e/support/fakeApi.ts
index 8719c49..cf579c3 100644
--- a/frontend/e2e/support/fakeApi.ts
+++ b/frontend/e2e/support/fakeApi.ts
@@ -54,6 +54,21 @@ const emptyReviews = {
pageInfo: { __typename: 'PageInfo', hasNextPage: false, endCursor: null },
};
+const option = (value: string, count: number) => ({
+ __typename: 'FilterOption',
+ value,
+ label: value,
+ count,
+});
+
+const filterOptions = {
+ __typename: 'FilterOptions',
+ types: [option('Red', 3)],
+ countries: [option('IT', 3)],
+ grapes: [option('Merlot', 3)],
+ harmonize: [option('Beef', 3)],
+};
+
/** The answer the real API gives to a top 4 that breaks its rules. */
const badInput = (message: string) => ({
errors: [{ message, extensions: { code: 'BAD_USER_INPUT' } }],
@@ -102,6 +117,7 @@ export async function fakeApi(page: Page, { loggedIn = true } = {}) {
},
MyReviews: () => ({ data: { me: me && { ...me, reviews: emptyReviews } } }),
SearchWines: () => ({ data: { wines: connection(ids.map(wine)) } }),
+ FilterOptions: () => ({ data: { filterOptions } }),
Wine: ({ id }: { id: string }) => ({ data: { wine: { ...wine(id), ...details } } }),
WineReviews: ({ id }: { id: string }) => ({
data: {
diff --git a/frontend/e2e/targets.spec.ts b/frontend/e2e/targets.spec.ts
new file mode 100644
index 0000000..b3aff5c
--- /dev/null
+++ b/frontend/e2e/targets.spec.ts
@@ -0,0 +1,177 @@
+import { expect, test, type Page } from '@playwright/test';
+import { fakeApi, loggedIn } from './support/fakeApi';
+
+/*
+ * E2E for two promises in the README: every click target is at least 44 × 44 px, and every
+ * element that can get focus shows it. Goes through the main pages, logged out and logged in,
+ * on both desktop and mobile. Runs against `vite preview` with the fake API in support/fakeApi.ts.
+ *
+ * The exceptions are the ones the README lists:
+ * - links in running text, and the grape links on the wine page, which are a comma list;
+ * - the heart and the bookmark on the wine cards, 44 × 40 px;
+ * - each half star in the review form, at least 24 × 24 px.
+ */
+
+const INTERACTIVE =
+ 'a[href], button, input:not([type=hidden]), select, textarea, summary, [tabindex]:not([tabindex="-1"])';
+
+/** The visible click targets that are smaller than they should be, as «name width×height». */
+function smallTargets(page: Page) {
+ return page.evaluate((selector) => {
+ const small: string[] = [];
+ for (const el of document.querySelectorAll(selector)) {
+ const style = getComputedStyle(el);
+ if (style.display === 'none' || style.visibility === 'hidden') continue;
+ if (el.closest('[inert], [aria-hidden="true"]')) continue;
+
+ let rect = el.getBoundingClientRect();
+ // A link that covers its whole card (WineCard, RecentReviews): the card is the target.
+ const after = getComputedStyle(el, '::after');
+ if (after.content !== 'none' && after.position === 'absolute' && el.offsetParent) {
+ rect = el.offsetParent.getBoundingClientRect();
+ }
+ // A hidden checkbox or radio button is clicked through its label.
+ const label = el instanceof HTMLInputElement ? el.labels?.[0] : undefined;
+ if (label && (el.type === 'checkbox' || el.type === 'radio')) {
+ rect = label.getBoundingClientRect();
+ }
+ // Not shown (the skip link until it has focus, the closed menu).
+ if (rect.width <= 1 || rect.height <= 1) continue;
+
+ const parent = el.parentElement;
+ const inText =
+ el.tagName === 'A' &&
+ style.display === 'inline' &&
+ (el.closest('dd') !== null ||
+ [...(parent?.childNodes ?? [])].some(
+ (node) => node.nodeType === Node.TEXT_NODE && node.textContent?.trim(),
+ ));
+ if (inText) continue;
+
+ const name = `${el.tagName.toLowerCase()} «${el.getAttribute('aria-label') ?? el.textContent?.trim() ?? ''}»`;
+ const [minWidth, minHeight] =
+ el instanceof HTMLInputElement && el.type === 'radio' && el.name === 'rating'
+ ? [24, 24]
+ : /^(Favoritt|Vil prøve) /.test(el.getAttribute('aria-label') ?? '') &&
+ el.closest('article')
+ ? [44, 40]
+ : [44, 44];
+ if (rect.width < minWidth - 0.5 || rect.height < minHeight - 0.5) {
+ small.push(`${name} ${Math.round(rect.width)}×${Math.round(rect.height)}`);
+ }
+ }
+ return small;
+ }, INTERACTIVE);
+}
+
+/**
+ * Tabs through the whole page and returns the elements where focus has no visible mark: no
+ * outline on the element, on its ::after (a link that covers its card) or on a parent close by
+ * (the star around a radio button), and no focus colour on the border around the search field.
+ */
+async function elementsWithoutFocusMark(page: Page) {
+ await page.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
+ const missing: string[] = [];
+ const seen = new Set();
+ for (let step = 0; step < 200; step++) {
+ await page.keyboard.press('Tab');
+ const result = await page.evaluate(() => {
+ const el = document.activeElement as HTMLElement | null;
+ if (!el || el === document.body) return null;
+ el.dataset.focusStep ??= String(document.querySelectorAll('[data-focus-step]').length);
+ const focusColour = getComputedStyle(document.documentElement)
+ .getPropertyValue('--color-focus')
+ .trim();
+ const probe = document.createElement('span');
+ probe.style.color = focusColour;
+ document.body.append(probe);
+ const focusRgb = getComputedStyle(probe).color;
+ probe.remove();
+
+ const outlined = (style: CSSStyleDeclaration) =>
+ style.outlineStyle !== 'none' && parseFloat(style.outlineWidth) >= 2;
+ const styles = [getComputedStyle(el), getComputedStyle(el, '::after')];
+ let parent = el.parentElement;
+ for (let i = 0; i < 3 && parent; i++, parent = parent.parentElement) {
+ styles.push(getComputedStyle(parent));
+ }
+ const marked = styles.some(
+ (style) =>
+ outlined(style) ||
+ (parseFloat(style.borderTopWidth) >= 2 && style.borderTopColor === focusRgb),
+ );
+ const name = el.getAttribute('aria-label') ?? el.textContent?.trim().slice(0, 40) ?? '';
+ return { id: el.dataset.focusStep, marked, name: `${el.tagName.toLowerCase()} «${name}»` };
+ });
+ if (!result || seen.has(result.id)) break;
+ seen.add(result.id);
+ if (!result.marked) missing.push(result.name);
+ }
+ return missing;
+}
+
+async function expectTargetsAndFocus(page: Page) {
+ await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
+ expect(await smallTargets(page)).toEqual([]);
+ expect(await elementsWithoutFocusMark(page)).toEqual([]);
+}
+
+test.use({ reducedMotion: 'reduce' });
+
+test.describe('Klikkflater og fokus', () => {
+ test('logget ut: søk, vin, konto og en side som ikke finnes', async ({ page }) => {
+ await fakeApi(page, { loggedIn: false });
+
+ await page.goto('./sok');
+ await expect(page.getByRole('article')).toHaveCount(3);
+ await expectTargetsAndFocus(page);
+
+ // The filters: in the sidebar on desktop, in a dialog on mobile.
+ const openFilters = page.getByRole('button', { name: /^Filtrer/ });
+ const onMobile = await openFilters.isVisible();
+ if (onMobile) await openFilters.click();
+ await expect(page.getByRole('checkbox', { name: /Rødvin/ })).toBeVisible();
+ await expectTargetsAndFocus(page);
+ await page.getByRole('checkbox', { name: /Rødvin/ }).check();
+ if (onMobile) await page.getByRole('button', { name: /^Vis \d+ viner?$/ }).click();
+
+ // With a filter: the chip that removes it, and «Nullstill filtre».
+ await expect(page.getByRole('link', { name: 'Nullstill filtre' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./vin/1');
+ await expect(page.getByRole('link', { name: 'Logg inn for å gi din dom' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./konto');
+ await expectTargetsAndFocus(page);
+ await page.getByRole('main').getByRole('button', { name: 'Lag bruker' }).click();
+ await expect(page.getByRole('heading', { level: 1, name: 'Lag bruker' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./finnes-ikke');
+ await expectTargetsAndFocus(page);
+ });
+
+ test('logget inn: vin med stjerner, Min side, en liste og kontoen', async ({ page }) => {
+ await fakeApi(page);
+
+ await page.goto('./vin/1');
+ await loggedIn(page);
+ await page.getByRole('main').getByRole('button', { name: 'Favoritt', exact: true }).click();
+ await expect(page.getByRole('radio', { name: '0,5 av 5 stjerner' })).toBeAttached();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./mine');
+ await expect(page.getByRole('link', { name: 'Se favoritten' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./mine/favoritter');
+ await expect(page.getByRole('link', { name: 'Tilbake til Min side' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+
+ await page.goto('./konto');
+ await expect(page.getByRole('link', { name: 'Gå til Min side' })).toBeVisible();
+ await expectTargetsAndFocus(page);
+ });
+});
diff --git a/frontend/src/components/ui/EmptyState.module.css b/frontend/src/components/ui/EmptyState.module.css
index a44b45b..cd91d06 100644
--- a/frontend/src/components/ui/EmptyState.module.css
+++ b/frontend/src/components/ui/EmptyState.module.css
@@ -44,3 +44,9 @@
align-items: center;
gap: var(--space-3) var(--space-5);
}
+
+.actions > a {
+ display: inline-flex;
+ align-items: center;
+ min-height: var(--tap-target);
+}
diff --git a/frontend/src/features/auth/AccountPage.module.css b/frontend/src/features/auth/AccountPage.module.css
index 41ad3c2..3654f5c 100644
--- a/frontend/src/features/auth/AccountPage.module.css
+++ b/frontend/src/features/auth/AccountPage.module.css
@@ -14,6 +14,9 @@
}
.link {
+ display: inline-flex;
+ align-items: center;
+ min-height: var(--tap-target);
padding: 0;
border: 0;
background: none;
@@ -23,6 +26,12 @@
cursor: pointer;
}
+.myPage {
+ display: inline-flex;
+ align-items: center;
+ min-height: var(--tap-target);
+}
+
.logout {
justify-self: start;
min-height: var(--tap-target);
diff --git a/frontend/src/features/auth/AccountPage.tsx b/frontend/src/features/auth/AccountPage.tsx
index a3d9d2d..42a9807 100644
--- a/frontend/src/features/auth/AccountPage.tsx
+++ b/frontend/src/features/auth/AccountPage.tsx
@@ -58,7 +58,9 @@ export default function AccountPage() {
Du er logget inn som {user.username}.