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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"@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",
"axe-core": "^4.14.0",
"jsdom": "^29.1.1",
"typescript": "~5.9.3",
"vite": "^8.2.2",
Expand Down
165 changes: 165 additions & 0 deletions client/src/a11y.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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';
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<SearchAlbumsData, SearchAlbumsVariables> {
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<SearchAlbumsData, SearchAlbumsVariables>[] = [],
) {
return render(
<MockedProvider mocks={mocks}>
<App />
</MockedProvider>,
);
}

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<SearchAlbumsData, SearchAlbumsVariables> = {
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('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 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<HTMLElement>(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();
});
});
5 changes: 5 additions & 0 deletions docs/AI-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

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