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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Kork & Krone

**Last updated:** 24 November 2026
**Last updated:** 24 November 2026
**Submission:** 4 (working system, ready for feedback on every aspect)
**Status:** In progress. See [Status for submission 4](#status-for-submission-4).
Expand Down Expand Up @@ -123,7 +124,8 @@ This section describes what users can do. "Backend" means the API supports the f

| Feature | Backend | UI | Description |
|---|---|---|---|
| Search | Done | Done | Ignores case and accents. Matches name, winery, region and grapes. Every word must match, in any order. Waits 300 ms after the last key press |
| Search | Done | Done | Ignores case and accents. Matches name, winery, region and grapes, with the words in any order, so «noir pinot» finds Pinot Noir. Waits 300 ms after the last key press |
| Search suggestions | Done | Done | On the landing page only: up to 5 wines while the user types, with arrow keys, Enter and Escape. The last choice opens all results on `/sok`. Enter without a chosen suggestion is a normal search |
| Filtering | Done | Done | Type, country, grapes, food pairing, minimum rating and alcohol range. Several values can be selected. The counts follow the search and the other filters. On small screens the filters open in a dialog |
| Sorting | Done | Done | Top rated, most rated, name and alcohol. Always sorts the whole result, not only the loaded page. «Best vurdert» puts wines with at least 50 ratings first, so a 5.0 from five people does not top the list |
| Pagination | Done | Done | Pages behind an opaque cursor that holds an offset. The user loads more results with a button, not with infinite scroll. Focus moves to the first new wine |
Expand Down Expand Up @@ -172,6 +174,7 @@ Each row explains what we chose, why, and what else we considered. Added as the
| Expired session | An Apollo link that fetches `me` again when the API says `UNAUTHENTICATED` | The whole page shows at once that the user is logged out, wherever the error came from | Checking for the error in each feature |
| Batched lookups | DataLoader for reviews and ratings per wine | A page of wines runs one query per field instead of one per wine (the N+1 problem) | One query per wine |
| Search state flow | Field text in React state, debounced into the URL, and the query reads only the URL | One source of truth for the search, so reload, shared links and the back button all give the same result | Sending a request directly from the input |
| Search suggestions | Downshift (`useCombobox`) | A tested implementation of the WAI-ARIA combobox pattern with no styling of its own, so it fits our design. Building our own risks subtle errors with keyboard and screen readers. It adds about 13 kB (gzip) to the landing page | Our own combobox, React Aria, Headless UI |
| Filter panel on small screens | Native `<dialog>` with `showModal()` | The browser handles focus trapping, Escape and returning focus, with no extra JavaScript | A dialog library |
| Filter counts | One count query per group that leaves out the group's own filter | The user can see what each choice gives before choosing, and values can be combined | Fixed counts for the whole catalogue |
| Testing | Vitest, React Testing Library, Playwright, axe | Vitest shares configuration with Vite. Playwright tests real browsers, also on mobile | Jest, Cypress |
Expand Down Expand Up @@ -462,6 +465,7 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a
### Some known issues

- Country is not part of the search text, because the country filter covers it.
- The search suggestions add about 13 kB (gzip) of JavaScript to the landing page, which is already over budget. Not measured on the VM yet.
- The cursors in the API hold an offset, which is slower deep into large results. To be solved together with the larger dataset.
- The database and its user are still called `vinmonopolet` and `vinmonopolet_app`, from before we switched dataset. Renaming would mean everyone rebuilding their database, so we kept the names.
- Reviews from before login have no account and are shown as «Anonym student». The old `student` table they belong to will be removed later.
Expand Down
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ https://doi.org/10.3390/bdcc7010020
with `Red` selected, `White` still shows what it would add. `grapes` and `harmonize` return the 40
most common values. Only the requested groups are counted.

Search is case and accent insensitive and matches name, winery, region and grapes.
Search is case and accent insensitive and matches name, winery, region and grapes. Each word must
be found, in any order, so «noir pinot» finds «Pinot Noir». Up to 10 words are used.
Several values in one filter list mean OR. Search and different filters are combined with AND.

```graphql
Expand Down
2 changes: 1 addition & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Open the local URL printed by Vite. Vite forwards `/project2/graphql` to the bac

To build and publish on the VM, run `./scripts/deploy.sh` from the repository root on the VM.
It builds for `/project2/` and uses `sudo` to copy the output into `/var/www/html/project2`.
See the [VM guide](../docs/vm.md).
See the [VM guide](../docs/vm.md).
2 changes: 1 addition & 1 deletion frontend/e2e/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test.describe('Forsiden', () => {
});

test('søk fra forsiden lander på søkesiden med søkeordet i URL-en', async ({ page }) => {
await page.getByRole('searchbox', { name: 'Hva har du lyst til å smake?' }).fill('riesling');
await page.getByRole('combobox', { name: 'Hva har du lyst til å smake?' }).fill('riesling');
await page.keyboard.press('Enter');
await expect(page).toHaveURL(/\/sok\?q=riesling$/);
await expect(page.getByRole('heading', { level: 1 })).toBeFocused();
Expand Down
131 changes: 131 additions & 0 deletions frontend/e2e/suggestions.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';
import { stubGraphQL } from './support/graphql';

/*
* E2E for the search suggestions on the landing page. Runs against `vite preview` with a
* stubbed GraphQL API. The landing page data itself is not stubbed: the suggestions must
* work no matter what the rest of the page does.
*/
const wine = (id: number, name: string) => ({
__typename: 'Wine',
id: String(id),
name,
type: 'Red',
wineryName: 'Produsent',
country: 'France',
countryCode: 'FR',
});

const WINES = [
wine(1, 'Pinot Noir Reserve'),
wine(2, 'Haven Pinot Noir'),
wine(3, 'Les Plateaux Pinot Noir'),
wine(4, 'Pinot Noir Estate'),
wine(5, 'Vieille Vigne Pinot Noir'),
];

async function stubSuggestions(page: Page) {
const operations = await stubGraphQL(page, {
WineSuggestions: () => ({
data: {
wines: {
__typename: 'WineConnection',
totalCount: 18,
edges: WINES.map((node) => ({ __typename: 'WineEdge', node })),
},
},
}),
Wine: () => ({ data: { wine: null } }),
});
return () => operations.filter((name) => name === 'WineSuggestions').length;
}

const combobox = (page: Page) =>
page.getByRole('combobox', { name: 'Hva har du lyst til å smake?' });

test.describe('Søkeforslag på forsiden', () => {
let suggestionRequests: () => number;

test.beforeEach(async ({ page }) => {
suggestionRequests = await stubSuggestions(page);
await page.goto('./');
});

test('skriv «noir pinot», velg en vin med piltastene og havn på vinsiden', async ({ page }) => {
await combobox(page).pressSequentially('noir pinot', { delay: 40 });

await expect(page.getByRole('option')).toHaveCount(6);
expect(suggestionRequests()).toBe(1);

await page.keyboard.press('ArrowDown');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');

await expect(page).toHaveURL(/\/vin\/2$/);
});

test('Enter uten valgt forslag er et vanlig søk', async ({ page }) => {
await combobox(page).pressSequentially('pinot', { delay: 40 });
await expect(page.getByRole('option')).toHaveCount(6);

await page.keyboard.press('Enter');

await expect(page).toHaveURL(/\/sok\?q=pinot$/);
});

test('alle forslagene er synlige og ikke skjult av siden rundt', async ({ page }) => {
// Tall enough that nothing needs to scroll: scrolling into view can move the content
// inside a clipping section, which would hide the very problem this test looks for.
const { width } = page.viewportSize() ?? { width: 1280 };
await page.setViewportSize({ width, height: 1400 });
await combobox(page).pressSequentially('pinot', { delay: 40 });
const last = page.getByRole('option', { name: 'Se alle 18 treff for «pinot»' });
await expect(last).toBeAttached();

// A clipped element still has a size, so check what is actually drawn on that spot.
const box = await last.boundingBox();
if (!box) throw new Error('The last option has no size.');
const drawn = await page.evaluate(
({ x, y }) => document.elementFromPoint(x, y)?.closest('[role="option"]')?.textContent,
{ x: box.x + box.width / 2, y: box.y + box.height / 2 },
);
expect(drawn).toContain('Se alle 18 treff');

await last.click();
await expect(page).toHaveURL(/\/sok\?q=pinot$/);
});

test('Escape lukker forslagene, og fokus blir i søkefeltet', async ({ page }) => {
await combobox(page).pressSequentially('pinot', { delay: 40 });
await expect(page.getByRole('option')).toHaveCount(6);

await page.keyboard.press('Escape');

await expect(page.getByRole('option')).toHaveCount(0);
await expect(combobox(page)).toBeFocused();
await expect(combobox(page)).toHaveValue('pinot');
});

test('har ingen axe-brudd med åpne forslag', async ({ page }) => {
await combobox(page).pressSequentially('pinot', { delay: 40 });
await expect(page.getByRole('option')).toHaveCount(6);

const axe = await new AxeBuilder({ page })
.include('form[role="search"]')
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
.analyze();
expect(axe.violations).toEqual([]);
});

test('har ingen horisontal scroll ved 320 px med åpne forslag', async ({ page }) => {
await page.setViewportSize({ width: 320, height: 640 });
await combobox(page).pressSequentially('pinot', { delay: 40 });
await expect(page.getByRole('option')).toHaveCount(6);

const overflow = await page.evaluate(
() => document.documentElement.scrollWidth > window.innerWidth,
);
expect(overflow).toBe(false);
});
});
69 changes: 67 additions & 2 deletions frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@apollo/client": "^4.3.7",
"downshift": "^9.5.0",
"graphql": "^16.15.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/landing/LandingView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('LandingView – innhold', () => {
it('har et stort søkefelt som sender til søkesiden', async () => {
const { user } = renderLoaded();
await user.type(
screen.getByRole('searchbox', { name: 'Hva har du lyst til å smake?' }),
screen.getByRole('combobox', { name: 'Hva har du lyst til å smake?' }),
'barolo{Enter}',
);
expect(screen.getByTestId('location')).toHaveTextContent('/sok?q=barolo');
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('LandingView – tilstander', () => {
renderWithRouter(<LandingView data={undefined} loading error={undefined} />);
expect(screen.getByRole('status')).toHaveTextContent('Laster viner');
expect(
screen.getByRole('searchbox', { name: 'Hva har du lyst til å smake?' }),
screen.getByRole('combobox', { name: 'Hva har du lyst til å smake?' }),
).toBeInTheDocument();
expect(screen.getAllByTestId('skeleton').length).toBeGreaterThan(0);
});
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/features/landing/api/suggestionsQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { gql } from '@apollo/client';

/** A few wines for the search suggestions, with only the fields the list shows. */
export const SUGGESTIONS_QUERY = gql`
query WineSuggestions($search: String!, $first: Int!) {
wines(search: $search, first: $first, sort: TOP_RATED) {
totalCount
edges {
node {
id
name
type
wineryName
country
countryCode
}
}
}
}
`;
Loading