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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down Expand Up @@ -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 | |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion frontend/e2e/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
131 changes: 131 additions & 0 deletions frontend/e2e/wine.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion frontend/src/app/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(/\/$/, '') || '/';
Expand All @@ -16,10 +17,7 @@ export function AppRoutes() {
<Route element={<AppLayout />}>
<Route index element={<LandingPage />} />
<Route path="sok" element={<SearchPage />} />
<Route
path="vin/:id"
element={<PlaceholderPage title="Vin" text="Detaljsiden er under utvikling." />}
/>
<Route path="vin/:id" element={<WinePage />} />
<Route
path="mine"
element={
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/ui/HeartIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** The heart on the "Vil prøve" buttons. Decorative: the button has its own text or label. */
export function HeartIcon() {
return (
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M12 20.5s-7.5-4.6-9.3-9.4C1.4 7.6 3.6 4 7.2 4c2 0 3.6 1.1 4.8 2.8C13.2 5.1 14.8 4 16.8 4c3.6 0 5.8 3.6 4.5 7.1-1.8 4.8-9.3 9.4-9.3 9.4z" />
</svg>
);
}
17 changes: 17 additions & 0 deletions frontend/src/components/ui/WineCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { describe, expect, it } from 'vitest';
import { screen, within } from '@testing-library/react';
import { useLocation } from 'react-router';
import { axe } from 'vitest-axe';
import { renderWithRouter } from '../../test/render';
import type { WineSummary } from '../../lib/types';
import { WineCard } from './WineCard';

function StateProbe() {
return <span data-testid="state">{JSON.stringify(useLocation().state)}</span>;
}

const wine: WineSummary = {
id: '100062',
name: 'Mosel Riesling Kabinett',
Expand All @@ -26,6 +31,18 @@ describe('WineCard', () => {
).toBeInTheDocument();
});

it('husker hvor brukeren kom fra, så detaljsiden kan lenke tilbake', async () => {
const { user } = renderWithRouter(
<>
<WineCard wine={wine} />
<StateProbe />
</>,
{ route: '/sok?q=riesling' },
);
await user.click(screen.getByRole('link', { name: 'Mosel Riesling Kabinett' }));
expect(screen.getByTestId('state')).toHaveTextContent('{"from":"/sok?q=riesling"}');
});

it('viser vintype og vurderinger som tekst', () => {
renderWithRouter(<WineCard wine={wine} />);
const article = screen.getByRole('article');
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/ui/WineCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Link } from 'react-router';
import { Link, useLocation } from 'react-router';
import { useWishlist } from '../../hooks/useWishlist';
import { formatRatingSummary } from '../../lib/format';
import type { WineSummary } from '../../lib/types';
import { WINE_TYPES, wineTypeToken } from '../../lib/wineTypes';
import { Bottle } from './Bottle';
import { HeartIcon } from './HeartIcon';
import styles from './WineCard.module.css';

interface WineCardProps {
Expand All @@ -20,6 +21,7 @@ interface WineCardProps {
export function WineCard({ wine, headingLevel: Heading = 'h3' }: WineCardProps) {
const { isSaved, toggle } = useWishlist(wine.id);
const typeMeta = WINE_TYPES[wine.type];
const { pathname, search } = useLocation();

return (
<article
Expand All @@ -35,7 +37,7 @@ export function WineCard({ wine, headingLevel: Heading = 'h3' }: WineCardProps)
{typeMeta.label} · {wine.country}
</p>
<Heading className={styles.name}>
<Link to={`/vin/${wine.id}`} className={styles.link}>
<Link to={`/vin/${wine.id}`} state={{ from: pathname + search }} className={styles.link}>
{wine.name}
</Link>
</Heading>
Expand Down Expand Up @@ -64,9 +66,7 @@ export function WineCard({ wine, headingLevel: Heading = 'h3' }: WineCardProps)
aria-label={`Vil prøve ${wine.name}`}
onClick={toggle}
>
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M12 20.5s-7.5-4.6-9.3-9.4C1.4 7.6 3.6 4 7.2 4c2 0 3.6 1.1 4.8 2.8C13.2 5.1 14.8 4 16.8 4c3.6 0 5.8 3.6 4.5 7.1-1.8 4.8-9.3 9.4-9.3 9.4z" />
</svg>
<HeartIcon />
</button>
</article>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { Bottle } from './Bottle';
export { ChipLink } from './Chip';
export { DiceFace } from './DiceFace';
export { ErrorNotice } from './ErrorNotice';
export { HeartIcon } from './HeartIcon';
export { SearchForm } from './SearchForm';
export { Skeleton } from './Skeleton';
export { WineCard } from './WineCard';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/search/SearchView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
.moreButton {
min-height: var(--tap-target);
padding: 0 var(--space-6);
border: 2px solid var(--color-brand);
border: 2px solid var(--color-link);
border-radius: var(--radius-pill);
background: transparent;
color: var(--color-text);
Expand Down
Loading