diff --git a/README.md b/README.md index 8fb22a9..6f45fdf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kork & Krone -**Last updated:** 6 November 2026 +**Last updated:** 7 November 2026 **Submission:** 3 (first complete prototype, beta) **Status:** In progress. See [Status for submission 3](#status-for-submission-3). @@ -50,7 +50,7 @@ Submission 3 should be the first complete prototype, with search, browsing, sort | Apollo Client in the frontend | Done | | | Search page with results | Done | Search with debounce, number of hits and "Last inn flere" at `/sok` | | Filtering and sorting in the user interface | Next | The API and URL filters work, but the panel is missing | -| Wine detail page | Planned | Placeholder page at `/vin/:id` | +| Wine detail page | Done | Facts, food pairing and rating at `/vin/:id`. Student reviews are added with the reviews feature | | Student reviews (stored in the database) | Planned | | | Larger dataset on the VM | Planned | | | Continuous integration (CI) | Not yet started | | @@ -103,7 +103,7 @@ This section describes what users can do. "Backend" means the API supports the f | Sorting | Done | Planned | Top rated, most rated, name and alcohol. Always sorts the whole result, not only the loaded page | | Pagination | Done | Done | Cursor-based. The user loads more results with a button, not with infinite scroll. Focus moves to the first new wine | | Search state in the URL | Not needed | Done | `?q=&type=&land=&drue=&mat=&sort=`. Survives reloads. Typing replaces the history entry, so the back button leaves the search instead of stepping through every word | -| Wine detail page | Done (`wine(id)`) | Planned | Name, winery, region, grapes, alcohol, food pairing, both ratings, and the latest student reviews | +| Wine detail page | Done (`wine(id)`) | Done | Name, winery, region, grapes, alcohol, body, acidity, vintages and food pairing in Norwegian. Grapes and food link to the search. Student reviews are planned | | Student reviews | Planned | Planned | Die roll from 1 to 6 and an optional comment, stored in PostgreSQL, the new rating is shown at once without a reload (Apollo cache update) | | Wishlist ("Vil prøve") | Planned | Done, stored in the browser | Moves to the backend when users and reviews are in place | | User | Planned | Planned | Login or anonymous ID stored in browser | @@ -198,7 +198,7 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing, ### Some known gaps -- The filter panel and detail page are not built yet, so they are not tested. +- The filter panel is not built yet, so it is not tested. - We have not tested with a screen reader yet. - eslint-plugin-jsx-a11y is not set up yet. - The filter panel on mobile will need a dialog with correct focus handling. This is planned. @@ -229,7 +229,7 @@ We follow the principle from the course: measure, set a budget and show the numb | Metric | Budget | Measured | Date | How we measure | |---|---|---|---|---| -| JavaScript on the landing page (gzip) | Less than 150 kB | 154,01 kB (over budget after adding Apollo Client) | 6 Nov 2026 | Sum of the gzip sizes from `npm run build` for the files the landing page loads | +| JavaScript on the landing page (gzip) | Less than 150 kB | 154,89 kB (over budget after adding Apollo Client) | 7 Nov 2026 | Sum of the gzip sizes from `npm run build` for the files the landing page loads | | Data transferred when loading the landing page | Less than 300 kB | Not measured yet | | Chrome DevTools, Network tab, cache disabled, on the VM | | Data transferred in a fixed search scenario | Less than 500 kB | Not measured yet | | Same method. Needs the search page | | Lighthouse (mobile) | Performance at least 90, accessibility 100 | Performance 39, accessibility 100, best practices 100, SEO 100 | 30 Oct 2026 | Lighthouse in Chrome DevTools, incognito, against the VM | @@ -243,14 +243,14 @@ and because the test was run over VPN. These are the "before" numbers. We will m | Level | Tools | What we test | Number of tests | |---|---|---|---| -| 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, loading, empty and error states, and axe on each component | 134 | +| 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, loading, empty and error states, and axe on each component | 188 | | Unit (backend) | Vitest | Parsing of X-Wines CSV files, and building SQL for search, filtering and sorting | 2 test files | -| End-to-end | Playwright with axe-core, desktop and mobile | Landing page and search page with a stubbed API: one request per page load, debounce, search, load more, reload, back button, no hits, API errors, keyboard use, reflow at 320 px, and no axe violations (WCAG 2.1 AA) | 26 (13 tests in 2 browser projects) | +| 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, load more, reload, back button, from search to wine and back, no hits, wine not found, API errors, keyboard use, reflow at 320 px, and no axe violations (WCAG 2.1 AA) | 40 (20 tests in 2 browser projects) | | API | Not set up yet | Resolvers against a test database: search, filtering, sorting and pagination | Planned | -Counted on 6 November 2026. +Counted on 7 November 2026. -**Coverage (frontend, 6 November 2026):** lines 98.32 %, branches 79.6 %, functions 95 %, statements 87.71 %. +**Coverage (frontend, 7 November 2026):** lines 98.58 %, branches 82.39 %, functions 95.9 %, statements 89.18 %. Vitest enforces a minimum of 80 % for lines, functions and statements and 75 % for branches (`vitest.config.ts`). We will add the missing tests before raising the limits further, and we do not lower the limits to make the run pass. @@ -342,7 +342,7 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a 2. [x] Search page: search field with debounce, list of results, number of hits, "Last inn flere", and empty and error states. 3. [ ] Filter panel with counts from `filterOptions`, and sorting. All choices stored in the URL. 4. [x] Connect the landing page to the backend. -5. [ ] Wine detail page. +5. [x] Wine detail page. 6. [ ] Start the backend on the VM and load the dataset. ### Then: towards the next submission diff --git a/frontend/e2e/landing.spec.ts b/frontend/e2e/landing.spec.ts index 19ddd6d..876c48a 100644 --- a/frontend/e2e/landing.spec.ts +++ b/frontend/e2e/landing.spec.ts @@ -67,8 +67,10 @@ test.describe('Forsiden', () => { }); test('kan brukes med bare tastatur: hopp-lenke og søk', async ({ page }) => { + const skipLink = page.getByRole('link', { name: 'Hopp til hovedinnhold' }); + await expect(skipLink).toBeAttached(); // Tab before React has rendered would do nothing. await page.keyboard.press('Tab'); - await expect(page.getByRole('link', { name: 'Hopp til hovedinnhold' })).toBeFocused(); + await expect(skipLink).toBeFocused(); }); test('har ingen axe-brudd (WCAG 2.1 AA)', async ({ page }) => { diff --git a/frontend/e2e/wine.spec.ts b/frontend/e2e/wine.spec.ts new file mode 100644 index 0000000..43011c9 --- /dev/null +++ b/frontend/e2e/wine.spec.ts @@ -0,0 +1,131 @@ +import AxeBuilder from '@axe-core/playwright'; +import { expect, test, type Page } from '@playwright/test'; + +/* E2E for the detail page. Runs against `vite preview` with a stubbed GraphQL API. */ +const wine = { + __typename: 'Wine', + id: '100062', + name: 'Origem Merlot', + type: 'Red', + grapes: ['Merlot'], + country: 'Brazil', + countryCode: 'BR', + regionName: 'Vale dos Vinhedos', + wineryName: 'Casa Valduga', + website: 'http://www.casavalduga.com.br', + elaborate: 'Varietal/100%', + harmonize: ['Beef', 'Pizza'], + abv: 13, + body: 'Full-bodied', + acidity: 'Medium', + vintages: [2020, 2005], + communityRating: 4.12, + communityRatingCount: 12, +}; + +const searchResult = { + data: { + wines: { + __typename: 'WineConnection', + totalCount: 1, + edges: [{ __typename: 'WineEdge', cursor: '1', node: wine }], + pageInfo: { __typename: 'PageInfo', hasNextPage: false, endCursor: '1' }, + }, + }, +}; + +async function stubApi(page: Page) { + await page.route('**/project2/graphql', (route) => { + const { operationName, variables } = route.request().postDataJSON() as { + operationName: string; + variables: { id?: string }; + }; + if (operationName === 'Wine') { + return route.fulfill({ + json: { data: { wine: variables.id === wine.id ? wine : null } }, + }); + } + return route.fulfill({ json: searchResult }); + }); +} + +test.describe('Detaljsiden', () => { + test('fra søk til vin og tilbake til samme søk', async ({ page }) => { + await stubApi(page); + await page.goto('./sok?q=merlot'); + + await page.getByRole('link', { name: 'Origem Merlot' }).click(); + + const heading = page.getByRole('heading', { level: 1, name: 'Origem Merlot' }); + await expect(heading).toBeFocused(); + await expect(page).toHaveTitle(/Origem Merlot/); + await expect(page.getByText('Rødvin · Brasil, Vale dos Vinhedos')).toBeVisible(); + + await page.getByRole('link', { name: 'Tilbake til søket' }).click(); + await expect(page).toHaveURL(/\/sok\?q=merlot$/); + await expect(page.getByRole('searchbox', { name: 'Søk etter vin' })).toHaveValue('merlot'); + }); + + test('tilbakelenken overlever omlasting', async ({ page }) => { + await stubApi(page); + await page.goto('./sok?q=merlot'); + await page.getByRole('link', { name: 'Origem Merlot' }).click(); + await expect(page.getByRole('link', { name: 'Tilbake til søket' })).toBeVisible(); + + await page.reload(); + + await expect(page.getByRole('link', { name: 'Tilbake til søket' })).toHaveAttribute( + 'href', + /\/sok\?q=merlot$/, + ); + }); + + test('«Passer til» starter et søk på matrett', async ({ page }) => { + await stubApi(page); + await page.goto('./vin/100062'); + + await page.getByRole('link', { name: 'Storfe' }).click(); + + await expect(page).toHaveURL(/\/sok\?mat=Beef$/); + }); + + test('husker «Vil prøve» etter omlasting', async ({ page }) => { + await stubApi(page); + await page.goto('./vin/100062'); + const button = page.getByRole('button', { name: 'Vil prøve' }); + + await button.click(); + await expect(button).toHaveAttribute('aria-pressed', 'true'); + await page.reload(); + + await expect(button).toHaveAttribute('aria-pressed', 'true'); + }); + + test('forklarer når vinen ikke finnes', async ({ page }) => { + await stubApi(page); + await page.goto('./vin/1'); + await expect(page.getByRole('heading', { level: 1, name: 'Fant ikke vinen' })).toBeVisible(); + await expect(page.getByRole('link', { name: 'Utforsk alle viner' })).toBeVisible(); + }); + + test('har ingen axe-brudd (WCAG 2.1 AA)', async ({ page }) => { + await stubApi(page); + await page.goto('./vin/100062'); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Origem Merlot'); + const axe = await new AxeBuilder({ page }) + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) + .analyze(); + expect(axe.violations).toEqual([]); + }); + + test('har ingen horisontal scroll ved 320 px', async ({ page }) => { + await stubApi(page); + await page.setViewportSize({ width: 320, height: 640 }); + await page.goto('./vin/100062'); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Origem Merlot'); + const overflow = await page.evaluate( + () => document.documentElement.scrollWidth > window.innerWidth, + ); + expect(overflow).toBe(false); + }); +}); diff --git a/frontend/src/app/App.test.tsx b/frontend/src/app/App.test.tsx index 829ca82..64b0663 100644 --- a/frontend/src/app/App.test.tsx +++ b/frontend/src/app/App.test.tsx @@ -22,7 +22,7 @@ function renderRoute(route: string) { describe('AppRoutes', () => { it.each([ ['/finnes-ikke', 'Fant ikke siden'], - ['/vin/1', 'Vin'], + ['/vin/abc', 'Fant ikke vinen'], ['/mine', 'Mine anmeldelser'], ])('shows the right page for %s', async (route, heading) => { renderRoute(route); diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx index d0fc9c8..c1b1b76 100644 --- a/frontend/src/app/App.tsx +++ b/frontend/src/app/App.tsx @@ -6,6 +6,7 @@ import PlaceholderPage from './PlaceholderPage'; // Kodesplitting per rute: forsiden laster ikke koden for søk og detaljside. const LandingPage = lazy(() => import('../features/landing/LandingPage')); const SearchPage = lazy(() => import('../features/search/SearchPage')); +const WinePage = lazy(() => import('../features/wine/WinePage')); /** BASE_URL kommer fra `base` i vite.config.ts (f.eks. «/project2/»). */ const basename = import.meta.env.BASE_URL.replace(/\/$/, '') || '/'; @@ -16,10 +17,7 @@ export function AppRoutes() { }> } /> } /> - } - /> + } />