+ );
+}
diff --git a/frontend/src/features/wine/api/toWineDetails.test.ts b/frontend/src/features/wine/api/toWineDetails.test.ts
new file mode 100644
index 0000000..f544641
--- /dev/null
+++ b/frontend/src/features/wine/api/toWineDetails.test.ts
@@ -0,0 +1,89 @@
+import { describe, expect, it } from 'vitest';
+import { toWineDetails, type ApiWineDetails } from './toWineDetails';
+
+const apiWine: ApiWineDetails = {
+ 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, 2012],
+ communityRating: 4.1,
+ communityRatingCount: 12,
+};
+
+describe('toWineDetails', () => {
+ it('uses Norwegian text for what the user reads', () => {
+ expect(toWineDetails(apiWine)).toMatchObject({
+ country: 'Brasil',
+ body: 'Fyldig',
+ acidity: 'Middels',
+ style: 'Én drue',
+ });
+ });
+
+ it('keeps the API value of a food pairing for the search link', () => {
+ expect(toWineDetails(apiWine)?.foods[0]).toEqual({ value: 'Beef', label: 'Storfe' });
+ });
+
+ it('describes the vintages as a range', () => {
+ expect(toWineDetails(apiWine)?.vintages).toBe('2005–2020');
+ });
+
+ it('shows a single vintage as one year', () => {
+ expect(toWineDetails({ ...apiWine, vintages: [2019] })?.vintages).toBe('2019');
+ });
+
+ it('has no vintages text when the list is empty', () => {
+ expect(toWineDetails({ ...apiWine, vintages: [] })?.vintages).toBeNull();
+ });
+
+ it('handles missing optional fields', () => {
+ const wine = toWineDetails({
+ ...apiWine,
+ countryCode: null,
+ country: null,
+ body: null,
+ acidity: null,
+ elaborate: null,
+ abv: null,
+ regionName: null,
+ });
+ expect(wine).toMatchObject({
+ country: 'Ukjent land',
+ body: null,
+ acidity: null,
+ style: null,
+ abv: null,
+ region: null,
+ });
+ });
+
+ it('uses the country name from the API when the code is unknown', () => {
+ expect(toWineDetails({ ...apiWine, countryCode: '!!' })?.country).toBe('Brazil');
+ });
+
+ it.each(['javascript:alert(1)', 'ftp://example.com', 'www.example.com', ''])(
+ 'leaves out the unsafe or incomplete website %s',
+ (website) => {
+ expect(toWineDetails({ ...apiWine, website })?.website).toBeNull();
+ },
+ );
+
+ it('keeps a normal website', () => {
+ expect(toWineDetails(apiWine)?.website).toBe('http://www.casavalduga.com.br');
+ });
+
+ it('returns null for a wine with an unknown type', () => {
+ expect(toWineDetails({ ...apiWine, type: 'Orange' })).toBeNull();
+ });
+});
diff --git a/frontend/src/features/wine/api/toWineDetails.ts b/frontend/src/features/wine/api/toWineDetails.ts
new file mode 100644
index 0000000..b8410ea
--- /dev/null
+++ b/frontend/src/features/wine/api/toWineDetails.ts
@@ -0,0 +1,47 @@
+import { formatCountry } from '../../../lib/format';
+import { toWineSummary, type ApiWine } from '../../../lib/mapWine';
+import type { WineDetails } from '../../../lib/types';
+import { acidityLabel, bodyLabel, foodLabel, styleLabel } from '../../../lib/wineLabels';
+
+/** The wine fields WINE_QUERY reads from the API. */
+export interface ApiWineDetails extends ApiWine {
+ countryCode: string | null;
+ regionName: string | null;
+ website: string | null;
+ elaborate: string | null;
+ harmonize: string[];
+ abv: number | null;
+ body: string | null;
+ acidity: string | null;
+ vintages: number[];
+}
+
+/** One year, or a range when there are several. A wine can have more than 70 vintages. */
+function describeVintages(vintages: number[]): string | null {
+ if (vintages.length === 0) return null;
+ const first = Math.min(...vintages);
+ const last = Math.max(...vintages);
+ return first === last ? String(first) : `${first}–${last}`;
+}
+
+/** The website comes from the dataset, so only plain web addresses become links. */
+const safeWebsite = (url: string | null) => (url && /^https?:\/\//i.test(url) ? url : null);
+
+/** Returns null for a wine with an unknown type, like `toWineSummary`. */
+export function toWineDetails(wine: ApiWineDetails): WineDetails | null {
+ const summary = toWineSummary(wine);
+ if (!summary) return null;
+
+ return {
+ ...summary,
+ country: wine.countryCode ? formatCountry(wine.countryCode, summary.country) : summary.country,
+ region: wine.regionName,
+ abv: wine.abv,
+ body: wine.body && bodyLabel(wine.body),
+ acidity: wine.acidity && acidityLabel(wine.acidity),
+ style: wine.elaborate && styleLabel(wine.elaborate),
+ foods: wine.harmonize.map((value) => ({ value, label: foodLabel(value) })),
+ vintages: describeVintages(wine.vintages),
+ website: safeWebsite(wine.website),
+ };
+}
diff --git a/frontend/src/features/wine/api/useWine.ts b/frontend/src/features/wine/api/useWine.ts
new file mode 100644
index 0000000..60832d1
--- /dev/null
+++ b/frontend/src/features/wine/api/useWine.ts
@@ -0,0 +1,32 @@
+import { useQuery } from '@apollo/client/react';
+import type { WineDetails } from '../../../lib/types';
+import { toWineDetails, type ApiWineDetails } from './toWineDetails';
+import { WINE_QUERY } from './wineQuery';
+
+export interface WineResult {
+ wine: WineDetails | null;
+ loading: boolean;
+ error: Error | undefined;
+ refetch: () => void;
+}
+
+/**
+ * Wine ids are positive integers. Other values in the URL can never match a wine, and a
+ * number too large for the database would give a server error instead of "not found".
+ */
+const isWineId = (id: string) => /^\d{1,9}$/.test(id);
+
+export function useWine(id: string): WineResult {
+ const { data, loading, error, refetch } = useQuery<{ wine: ApiWineDetails | null }>(WINE_QUERY, {
+ variables: { id },
+ skip: !isWineId(id),
+ });
+
+ return {
+ wine: data?.wine ? toWineDetails(data.wine) : null,
+ loading,
+ error,
+ // A failed retry already shows up in `error`, so the rejected promise needs no handling.
+ refetch: () => void refetch().catch(() => undefined),
+ };
+}
diff --git a/frontend/src/features/wine/api/wineQuery.ts b/frontend/src/features/wine/api/wineQuery.ts
new file mode 100644
index 0000000..e217d21
--- /dev/null
+++ b/frontend/src/features/wine/api/wineQuery.ts
@@ -0,0 +1,25 @@
+import { gql } from '@apollo/client';
+
+export const WINE_QUERY = gql`
+ query Wine($id: ID!) {
+ wine(id: $id) {
+ id
+ name
+ type
+ grapes
+ country
+ countryCode
+ regionName
+ wineryName
+ website
+ elaborate
+ harmonize
+ abv
+ body
+ acidity
+ vintages
+ communityRating
+ communityRatingCount
+ }
+ }
+`;
diff --git a/frontend/src/lib/format.test.ts b/frontend/src/lib/format.test.ts
index e4ae91a..d23f3eb 100644
--- a/frontend/src/lib/format.test.ts
+++ b/frontend/src/lib/format.test.ts
@@ -1,6 +1,8 @@
import { describe, expect, it } from 'vitest';
import {
+ formatAbv,
formatCount,
+ formatCountry,
formatRating,
formatRatingSummary,
formatRelativeTime,
@@ -61,3 +63,21 @@ describe('formatRelativeTime', () => {
expect(formatRelativeTime('2026-10-29T12:00:00Z', now)).toBe('i går');
});
});
+
+describe('formatAbv', () => {
+ it('shows whole numbers without decimals and uses a Norwegian comma', () => {
+ expect(formatAbv(13)).toBe('13 %');
+ expect(formatAbv(12.5)).toBe('12,5 %');
+ });
+});
+
+describe('formatCountry', () => {
+ it('gives the Norwegian name for a country code', () => {
+ expect(formatCountry('IT', 'Italy')).toBe('Italia');
+ expect(formatCountry('de ', 'Germany')).toBe('Tyskland');
+ });
+
+ it('uses the fallback for a code that does not exist', () => {
+ expect(formatCountry('!!', 'Atlantis')).toBe('Atlantis');
+ });
+});
diff --git a/frontend/src/lib/format.ts b/frontend/src/lib/format.ts
index 4cb12de..7b81aac 100644
--- a/frontend/src/lib/format.ts
+++ b/frontend/src/lib/format.ts
@@ -12,6 +12,9 @@ const compactFormatter = new Intl.NumberFormat(LOCALE, {
maximumFractionDigits: 1,
});
+const abvFormatter = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 1 });
+const regionNames = new Intl.DisplayNames([LOCALE], { type: 'region', fallback: 'none' });
+
/** 4.56 → «4,6» */
export function formatRating(value: number): string {
return ratingFormatter.format(value);
@@ -27,6 +30,20 @@ export function formatCompact(value: number): string {
return compactFormatter.format(value);
}
+/** 13 → «13 %», 12.5 → «12,5 %» (med hardt mellomrom, som i norsk typografi). */
+export function formatAbv(value: number): string {
+ return `${abvFormatter.format(value)}\u00a0%`;
+}
+
+/** Landnavn på norsk fra landkoden. Ukjente koder gir `fallback`. */
+export function formatCountry(code: string, fallback: string): string {
+ try {
+ return regionNames.of(code.trim().toUpperCase()) ?? fallback;
+ } catch {
+ return fallback; // Intl kaster for koder som ikke har riktig form.
+ }
+}
+
/** Velger riktig entall/flertall: (1, 'dom', 'dommer') → «1 dom». */
export function pluralize(count: number, singular: string, plural: string): string {
return `${formatCount(count)} ${count === 1 ? singular : plural}`;
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts
index 5a87954..38462ec 100644
--- a/frontend/src/lib/types.ts
+++ b/frontend/src/lib/types.ts
@@ -26,6 +26,20 @@ export interface WineSummary {
students: RatingSummary | null;
}
+/** Everything the detail page shows. Text is translated, and missing values are `null`. */
+export interface WineDetails extends WineSummary {
+ region: string | null;
+ abv: number | null;
+ body: string | null;
+ acidity: string | null;
+ style: string | null;
+ /** `value` is what the API filters on, `label` is what the user reads. */
+ foods: { value: string; label: string }[];
+ /** «2005–2020». */
+ vintages: string | null;
+ website: string | null;
+}
+
export interface ReviewPreview {
id: string;
/** Terningkast 1–5 (samme skala som X-Wines, så snittene kan sammenlignes). */
diff --git a/frontend/src/lib/wineLabels.test.ts b/frontend/src/lib/wineLabels.test.ts
new file mode 100644
index 0000000..8be7c3f
--- /dev/null
+++ b/frontend/src/lib/wineLabels.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, it } from 'vitest';
+import { acidityLabel, bodyLabel, foodLabel, styleLabel } from './wineLabels';
+
+describe('wine labels', () => {
+ it.each([
+ ['Very light-bodied', 'Veldig lett'],
+ ['Medium-bodied', 'Middels fyldig'],
+ ['Very full-bodied', 'Veldig fyldig'],
+ ])('translates body %s', (value, expected) => {
+ expect(bodyLabel(value)).toBe(expected);
+ });
+
+ it('translates acidity', () => {
+ expect(acidityLabel('High')).toBe('Høy');
+ });
+
+ it.each([
+ ['Varietal/100%', 'Én drue'],
+ ['Varietal/>75%', 'Hovedsakelig én drue'],
+ ['Assemblage/Blend', 'Drueblanding'],
+ ['Assemblage/Bordeaux Red Blend', 'Drueblanding'],
+ ])('translates style %s', (value, expected) => {
+ expect(styleLabel(value)).toBe(expected);
+ });
+
+ it('translates food pairings', () => {
+ expect(foodLabel('Game Meat')).toBe('Vilt');
+ });
+
+ it('shows the original value when there is no translation, instead of nothing', () => {
+ expect(foodLabel('Sushi')).toBe('Sushi');
+ expect(bodyLabel('Chewy')).toBe('Chewy');
+ expect(acidityLabel('Odd')).toBe('Odd');
+ expect(styleLabel('Other')).toBe('Other');
+ });
+});
diff --git a/frontend/src/lib/wineLabels.ts b/frontend/src/lib/wineLabels.ts
new file mode 100644
index 0000000..9b89b21
--- /dev/null
+++ b/frontend/src/lib/wineLabels.ts
@@ -0,0 +1,73 @@
+/*
+ * X-Wines is in English, while everything users read is in Norwegian. The API values stay
+ * in the URL and the filters. Values we have no translation for are shown as they are,
+ * because the Full dataset can contain values that are not in the Test version.
+ */
+const BODY: Record = {
+ 'Very light-bodied': 'Veldig lett',
+ 'Light-bodied': 'Lett',
+ 'Medium-bodied': 'Middels fyldig',
+ 'Full-bodied': 'Fyldig',
+ 'Very full-bodied': 'Veldig fyldig',
+};
+
+const ACIDITY: Record = {
+ Low: 'Lav',
+ Medium: 'Middels',
+ High: 'Høy',
+};
+
+const FOOD: Record = {
+ Aperitif: 'Aperitiff',
+ Appetizer: 'Forrett',
+ Barbecue: 'Grillmat',
+ Beef: 'Storfe',
+ 'Blue Cheese': 'Blåmuggost',
+ Cake: 'Kake',
+ Chicken: 'Kylling',
+ Chocolate: 'Sjokolade',
+ 'Cold Cuts': 'Kjøttpålegg',
+ Cream: 'Fløtesauser',
+ 'Cured Meat': 'Spekemat',
+ Fish: 'Fisk',
+ 'French Fries': 'Pommes frites',
+ Fruit: 'Frukt',
+ 'Fruit Dessert': 'Fruktdessert',
+ 'Game Meat': 'Vilt',
+ 'Goat Cheese': 'Geitost',
+ Grilled: 'Grillet mat',
+ 'Hard Cheese': 'Hardost',
+ Lamb: 'Lam',
+ 'Lean Fish': 'Mager fisk',
+ 'Light Stews': 'Lette gryteretter',
+ 'Maturated Cheese': 'Modnet ost',
+ Mushrooms: 'Sopp',
+ Pasta: 'Pasta',
+ Pizza: 'Pizza',
+ Pork: 'Svin',
+ Poultry: 'Fjærkre',
+ 'Rich Fish': 'Fet fisk',
+ Risotto: 'Risotto',
+ Salad: 'Salat',
+ Seafood: 'Sjømat',
+ Shellfish: 'Skalldyr',
+ Snack: 'Snacks',
+ 'Soft Cheese': 'Myk ost',
+ 'Spicy Food': 'Krydret mat',
+ 'Sweet Dessert': 'Søt dessert',
+ 'Tomato Dishes': 'Tomatretter',
+ Veal: 'Kalv',
+ Vegetarian: 'Vegetar',
+};
+
+export const bodyLabel = (value: string) => BODY[value] ?? value;
+export const acidityLabel = (value: string) => ACIDITY[value] ?? value;
+export const foodLabel = (value: string) => FOOD[value] ?? value;
+
+/** "Assemblage/Bordeaux Red Blend" and similar are all blends, so one word is enough. */
+export function styleLabel(value: string): string {
+ if (value === 'Varietal/100%') return 'Én drue';
+ if (value.startsWith('Varietal/')) return 'Hovedsakelig én drue';
+ if (value.startsWith('Assemblage/')) return 'Drueblanding';
+ return value;
+}
From 2e12e059b7d57786a7ec50f0e0543dc3e4e01b27 Mon Sep 17 00:00:00 2001
From: Oscar Bakkeng
Date: Sat, 7 Nov 2026 17:38:54 +0100
Subject: [PATCH 4/4] docs(readme): update status after adding the detail page
Co-Authored-By: Claude Opus 5.5
---
README.md | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
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