From 78bfa7945daf6fdaec67cc2bb94fe784aa8eb41b Mon Sep 17 00:00:00 2001 From: Erik Hjelm Fjeldheim Date: Thu, 22 Oct 2026 15:55:47 -0600 Subject: [PATCH 1/3] test: #17 run axe-core over every state of the search page Adds axe-core as a client dev dependency and checks the search page in all four of its states: idle, with results, with no results, and when the search fails. Also asserts the skip link stays the first focusable element after a search has rendered. Two deliberate details in the harness: - color-contrast is disabled because jsdom does no layout or painting, so axe has nothing to measure a rendered ratio against and would report every pair as incomplete rather than passing. Contrast is verified by hand in a browser, which is where the README numbers come from. - the harness asserts axe found passing rules before asserting it found no violations. Without that an empty container would pass vacuously whatever the markup looked like. I checked this by running the harness against a deliberately broken tree and confirming it reported violations. Verified: axe reports zero violations on the search page in all four states. Audited by hand and already conforming: focus-visible outlines are never suppressed anywhere in the CSS, every form control has an accessible name, and the result count already carries role=status with aria-live=polite. --- client/package.json | 1 + client/src/a11y.test.tsx | 145 +++++++++++++++++++++++++++++++++++++++ pnpm-lock.yaml | 9 +++ 3 files changed, 155 insertions(+) create mode 100644 client/src/a11y.test.tsx diff --git a/client/package.json b/client/package.json index 11820db..af354cd 100644 --- a/client/package.json +++ b/client/package.json @@ -25,6 +25,7 @@ "@types/react": "^19.2.18", "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^6.1.0", + "axe-core": "^4.14.0", "jsdom": "^29.1.1", "typescript": "~5.9.3", "vite": "^8.2.2", diff --git a/client/src/a11y.test.tsx b/client/src/a11y.test.tsx new file mode 100644 index 0000000..3106c70 --- /dev/null +++ b/client/src/a11y.test.tsx @@ -0,0 +1,145 @@ +import { describe, it, expect } from 'vitest'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { MockedProvider } from '@apollo/client/testing/react'; +import type { MockedResponse } from '@apollo/client/testing'; +import { GraphQLError } from 'graphql'; +import axe from 'axe-core'; + +import App from './App.js'; +import { SEARCH_ALBUMS } from './api/searchAlbums.js'; +import type { + AlbumSummary, + SearchAlbumsData, + SearchAlbumsVariables, +} from './api/searchAlbums.js'; + +const album: AlbumSummary = { + id: '1', + title: 'Abbey Road', + artists: [{ id: '1', name: 'The Beatles' }], + releaseYear: 1969, + genres: [{ id: '1', name: 'Rock' }], + averageRating: 4.8, + reviewCount: 1240, +}; + +function mockSearch( + query: string, + albums: AlbumSummary[] = [album], +): MockedResponse { + return { + request: { + query: SEARCH_ALBUMS, + variables: { input: { query, sort: 'RELEVANCE' }, first: 20, after: null }, + }, + result: { + data: { + searchAlbums: { + edges: albums.map((node) => ({ cursor: node.id, node })), + totalCount: albums.length, + pageInfo: { hasNextPage: false, endCursor: null }, + }, + }, + }, + delay: 10, + }; +} + +function renderApp( + mocks: MockedResponse[] = [], +) { + return render( + + + , + ); +} + +function submitSearch(query: string) { + fireEvent.change(screen.getByRole('searchbox'), { target: { value: query } }); + fireEvent.submit(screen.getByRole('search')); +} + +/** + * Runs axe over the rendered tree and fails with a readable list if anything + * is wrong. + * + * `color-contrast` is off because jsdom does no layout or painting, so axe + * has nothing to measure a rendered contrast ratio against and would report + * every pair as incomplete rather than passing. Contrast is verified by hand + * in a browser, which is where the numbers in the README come from. Every + * other rule axe can evaluate runs here. + */ +async function expectNoViolations(container: HTMLElement) { + const results = await axe.run(container, { + rules: { 'color-contrast': { enabled: false } }, + }); + + // Guard against a false pass: if axe examined nothing it would report a + // clean tree whatever the markup looks like. + expect(results.passes.length).toBeGreaterThan(0); + + const summary = results.violations.map( + (violation) => + `${violation.id}: ${violation.help} (${violation.nodes.length} node(s)) -> ${violation.nodes[0]?.html}`, + ); + + expect(summary).toEqual([]); +} + +describe('axe-core on the search page', () => { + it('is clean before anything is searched', async () => { + const { container } = renderApp(); + await expectNoViolations(container); + }); + + it('is clean with results rendered', async () => { + const { container } = renderApp([mockSearch('Abbey')]); + submitSearch('Abbey'); + + await screen.findByRole('region', { name: 'Search results' }); + await waitFor(() => + expect(screen.getByText(/Showing 1 of 1 albums/)).toBeInTheDocument(), + ); + + await expectNoViolations(container); + }); + + it('is clean with no results', async () => { + const { container } = renderApp([mockSearch('zzzz', [])]); + submitSearch('zzzz'); + + await screen.findByRole('heading', { name: 'No albums found' }); + await expectNoViolations(container); + }); + + it('is clean when the search fails', async () => { + const failing: MockedResponse = { + request: { + query: SEARCH_ALBUMS, + variables: { + input: { query: 'boom', sort: 'RELEVANCE' }, + first: 20, + after: null, + }, + }, + result: { errors: [new GraphQLError('Something went wrong')] }, + }; + const { container } = renderApp([failing]); + submitSearch('boom'); + + await screen.findByText('Could not load albums. Please try again.'); + await expectNoViolations(container); + }); + + it('keeps the skip link as the first focusable element on every state', async () => { + const { container } = renderApp([mockSearch('Abbey')]); + submitSearch('Abbey'); + await screen.findByRole('region', { name: 'Search results' }); + + const focusable = container.querySelectorAll( + 'a[href], button, input, [tabindex]', + ); + expect(focusable[0]?.classList.contains('skip-link')).toBe(true); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c3001c2..0843e90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -78,6 +78,9 @@ importers: '@vitejs/plugin-react': specifier: ^6.1.0 version: 6.1.1(vite@8.3.1(@types/node@24.19.2)(esbuild@0.28.2)(tsx@4.23.15)) + axe-core: + specifier: ^4.14.0 + version: 4.14.0 jsdom: specifier: ^29.1.1 version: 29.1.1 @@ -1264,6 +1267,10 @@ packages: resolution: {integrity: sha512-UzGt8zg7Ny8djbYMhxl2zuEevVa7r2gJjYY5Lwr1xM7+XU2nd6CkIWFTVcCIbAP63vSz71NaVyyuSk9lHKcy0A==} engines: {node: '>=4'} + axe-core@4.14.0: + resolution: {integrity: sha512-9WTZxEjsZ7b13TH8JPmbV2z8CHbl80/2hm3XPEG4JgNdQLK81IBRXmSxHfMAOkSqQeRxT/0dwNDz2GOm3zzpcQ==} + engines: {node: '>=4'} + axobject-query@4.1.0: resolution: {integrity: sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==} engines: {node: '>= 0.4'} @@ -3638,6 +3645,8 @@ snapshots: axe-core@4.13.0: {} + axe-core@4.14.0: {} + axobject-query@4.1.0: {} balanced-match@1.0.2: {} From 5e3013a47385e051ca154d80089a8a5c2debb040 Mon Sep 17 00:00:00 2001 From: Erik Hjelm Fjeldheim Date: Thu, 22 Oct 2026 15:58:21 -0600 Subject: [PATCH 2/3] docs: #17 #18 record the work and correct three stale claims AI usage rows for 20 and 22 October, including the review finding I got wrong and corrected, and the one palette value the tool proposed that did not meet the 3:1 a form-control border needs. Three statements were out of date. architecture.md still listed URL-based search state as planned, which landed with #19. The README still listed accessibility and sustainability as planned while both are delivered here. The README milestone row still said M2 was current and the frontend description still mentioned a 300 ms debounce that #19 removed. --- README.md | 2 +- docs/AI-USAGE.md | 5 +++++ docs/architecture.md | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40843fd..df14aea 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ The two `AlbumDetailPage` rows are the chunk added by the album detail route (#1 The frontend supports searching by album title or artist, committed on Search or Enter rather than while typing, with loading and error feedback, and a no-results message. It currently shows the first 20 matches ordered by relevance. -**Planned:** Frontend filters, sorting, pagination controls and album details; reviews, ratings and wantlist functionality; accessibility and sustainability work (M3); and Playwright end-to-end tests (M4). The database tables for reviews and crate items exist, but their GraphQL functionality is still planned. `X-User-Id` is also defined but not yet handled at runtime. +**Planned:** Frontend filters, sorting and pagination controls; album details; reviews, ratings and wantlist functionality; and Playwright end-to-end tests (M4). The database tables for reviews and crate items exist, but their GraphQL functionality is still planned. `X-User-Id` is also defined but not yet handled at runtime. Accessibility and sustainability are M3 work and are covered under [Sustainability measures](#sustainability-measures) and the accessibility pass in the issue tracker. ### Backend search behavior diff --git a/docs/AI-USAGE.md b/docs/AI-USAGE.md index d5cbdd8..b0b3350 100644 --- a/docs/AI-USAGE.md +++ b/docs/AI-USAGE.md @@ -59,6 +59,11 @@ the part that matters most. | 2026-10-19 | erikhfj | opencode | Reviewed #53 against the code rather than as prose. Found the README contradicting its own Implemented section and a smoke test that dropped an expectation while keeping the field in the query. Verified Rachel's other claims, including that `AVERAGE_RATING_DESC` throws, which corrected my own "four sort modes" in the README. | | 2026-10-19 | erikhfj | opencode | Search state in the URL for #19, with `useSearchState` owning `q`, `sort`, `genres` and `decades`. My first version committed on a 300 ms debounce, which rewrote the URL mid-word and reset the input back through the `query !== previousQuery` branch; it read as the page reloading on every keystroke. Changed so the query reaches the URL only on Search. | +| 2026-10-20 | erikhfj | opencode | Processed two co-students' reviews of the project. Both found the same real bug: search matches whole words, so `radio` finds nothing for Radiohead. Their diagnosis was right, but the fix proposed, `to_tsquery` with `:*`, throws on quotes and dashes, which is the whole reason the code uses `websearch_to_tsquery`. Filed #55 to build the prefix query in TypeScript instead. Their rating suggestion exposed something worse: #12 asked for `AVG(review.rating)` as the keyset sort key, an aggregate that moves whenever anyone writes a review. Revised #12 to a trigger-maintained `album.average_rating`, warned #15 not to write the same column, and corrected #18 where a bullet still described a debounce #19 had already removed. | +| 2026-10-22 | erikhfj | opencode | Reviewed #57 and #58 by running the full gate suite on the branches rather than reading them as prose. Six findings on each. One of mine was wrong: I wrote that `App.tsx` was the only file in the repo carrying a UTF-8 BOM. It is one of four, and three predate that PR entirely. Posted a correction rather than leaving the error standing. Recorded here because a wrong review is as much a failure of control as a wrong patch. | +| 2026-10-22 | erikhfj | opencode | #18, dark theme under `prefers-color-scheme`. Lifted the eight hard-coded colours into custom properties first so the light palette stays byte-identical. Did not take the generated palette as-is: `--border-strong` at `#556055` measured 2.5:1 against the surface, under the 3:1 a form-control border needs, so it became `#6b766b` at 3.4:1. Computed every ratio by hand rather than trusting the values that came back. | +| 2026-10-22 | erikhfj | opencode | #17, axe-core over all four states of the search page. A green suite proves nothing on its own, so the harness asserts axe found passing rules before asserting it found no violations, and I checked it against a deliberately broken tree first to confirm it reports failures. `color-contrast` is disabled because jsdom paints nothing; that limitation is written into the PR rather than quietly omitted. | + ## Notes - The prototype was never merged. `archive/scaffold-prototype` is a reference to diff --git a/docs/architecture.md b/docs/architecture.md index ffe9aca..91b744d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -5,7 +5,7 @@ in M2 and M3. The API contract is `schema.graphql`, the data model is in `docs/data-model.md`, and the planned interface is described in `docs/ui-specification.md`. -At M2, search, filtering, sorting, pagination and DataLoaders are implemented in the backend. User identity, reviews, crate functionality and URL-based search state are planned for later milestones. +At M2, search, filtering, sorting, pagination and DataLoaders are implemented in the backend. URL-based search state landed in M3. User identity, reviews and crate functionality are planned for later milestones. ## 1. PostgreSQL + GraphQL Yoga From b37235a20b059a04b7c92dcfc66088e12d22b51b Mon Sep 17 00:00:00 2001 From: Erik Hjelm Fjeldheim Date: Fri, 23 Oct 2026 11:10:06 -0600 Subject: [PATCH 3/3] test: #17 verify the skip link with Tab instead of DOM order Rachel was right that the old assertion proved nothing about keyboard use. It checked that the first element matching a focusable selector carried the skip-link class, which passes even when the link is unreachable or points at nothing. Replaced with two tests that say what they mean. One Tab from a fresh page must land on the skip link, and the href must resolve to an element that can take focus. That needs @testing-library/user-event, since jsdom does not traverse the tab order on its own. Checked the tests fail when they should: with the link given tabIndex=-1 and href=#nope both go red. The old test passed against that same broken markup. --- client/package.json | 1 + client/src/a11y.test.tsx | 32 ++++++++++++++++++++++++++------ pnpm-lock.yaml | 13 +++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index af354cd..dbdb1a7 100644 --- a/client/package.json +++ b/client/package.json @@ -22,6 +22,7 @@ "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^7.0.1", "@testing-library/react": "^16.3.3", + "@testing-library/user-event": "^14.6.8", "@types/react": "^19.2.18", "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^6.1.0", diff --git a/client/src/a11y.test.tsx b/client/src/a11y.test.tsx index 3106c70..ff1211f 100644 --- a/client/src/a11y.test.tsx +++ b/client/src/a11y.test.tsx @@ -1,5 +1,6 @@ import { describe, it, expect } from 'vitest'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { MockedProvider } from '@apollo/client/testing/react'; import type { MockedResponse } from '@apollo/client/testing'; import { GraphQLError } from 'graphql'; @@ -132,14 +133,33 @@ describe('axe-core on the search page', () => { await expectNoViolations(container); }); - it('keeps the skip link as the first focusable element on every state', async () => { - const { container } = renderApp([mockSearch('Abbey')]); + it('is the first thing Tab reaches on the search page', async () => { + renderApp(); + const user = userEvent.setup(); + + // One Tab from a fresh page has to land on the skip link. Checking that it + // is first in the DOM is not the same thing: a link can be first in the + // markup and still unreachable if something ahead of it is not tabbable. + await user.tab(); + expect(screen.getByRole('link', { name: 'Skip to content' })).toHaveFocus(); + }); + + it('points the skip link at a target that exists and can take focus', async () => { + renderApp([mockSearch('Abbey')]); submitSearch('Abbey'); await screen.findByRole('region', { name: 'Search results' }); - const focusable = container.querySelectorAll( - 'a[href], button, input, [tabindex]', - ); - expect(focusable[0]?.classList.contains('skip-link')).toBe(true); + const skipLink = screen.getByRole('link', { name: 'Skip to content' }); + + // An href pointing at nothing skips nothing. + const href = skipLink.getAttribute('href'); + expect(href).toMatch(/^#/); + const target = document.querySelector(href!); + expect(target).not.toBeNull(); + + // The target has to be programmatically focusable too, or the browser + // scrolls to it and leaves focus stranded back in the navigation. + target!.focus(); + expect(target).toHaveFocus(); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0843e90..6be07d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: '@testing-library/react': specifier: ^16.3.3 version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) + '@testing-library/user-event': + specifier: ^14.6.8 + version: 14.6.8(@testing-library/dom@10.4.2) '@types/react': specifier: ^19.2.18 version: 19.3.0 @@ -1012,6 +1015,12 @@ packages: '@types/react-dom': optional: true + '@testing-library/user-event@14.6.8': + resolution: {integrity: sha512-vgSSqnANMnkcYR/vUNDbwS7aM3OErRLNUG8vCVVlj4oc6cKffUrccX7UAS5AmJQQNZTSibi9z5GvvRZ0aYgUCQ==} + engines: {node: '>=12', npm: '>=6'} + peerDependencies: + '@testing-library/dom': '>=7.21.4' + '@types/aria-query@5.0.4': resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==} @@ -3338,6 +3347,10 @@ snapshots: '@types/react': 19.3.0 '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@testing-library/user-event@14.6.8(@testing-library/dom@10.4.2)': + dependencies: + '@testing-library/dom': 10.4.2 + '@types/aria-query@5.0.4': {} '@types/chai@5.2.3':