diff --git a/README.md b/README.md
index 972db5e..44799c6 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Kork & Krone
-**Last updated:** 16 November 2026
+**Last updated:** 17 November 2026
**Submission:** 4 (working system, ready for feedback on every aspect)
**Status:** In progress. See [Status for submission 4](#status-for-submission-4).
@@ -230,10 +230,11 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing,
- Playwright with axe-core against WCAG 2.1 A and AA, on desktop and mobile.
- An automated test for reflow at 320 px.
- Manual testing with only the keyboard.
+- Screen reader flows: Playwright steps through the flows and checks where focus goes and what the live regions say, for example after removing a filter, a failed login or saving a review. See [screen reader testing](docs/screen-reader.md) for what we found and fixed, and the script for testing by hand with VoiceOver.
### Some known gaps
-- We have not tested with a screen reader yet.
+- VoiceOver has been run automated (11 of 15 steps passed, see the [VoiceOver report](docs/voiceover-report.md)), but not yet by hand. Empty required fields are read as «invalid data» before the user has done anything. See [screen reader testing](docs/screen-reader.md).
- eslint-plugin-jsx-a11y is not set up yet.
## Sustainability
@@ -411,5 +412,6 @@ Remove known issues as they are fixed.
- [VM](docs/vm.md): deployment, Apache and running the backend with `nohup`
- [API](docs/api.md): GraphQL queries, user accounts, reviews, database tests and the X-Wines citation
- [Manual testing](docs/manual-testing.md): how to test login, reviews and other user data by hand
+- [Screen reader testing](docs/screen-reader.md): what we found, what we fixed and the VoiceOver script
- [Workflow](docs/workflow.md): branches, reviews and checks
- [Tasks](docs/tasks.md): requirements and sketches
\ No newline at end of file
diff --git a/docs/screen-reader.md b/docs/screen-reader.md
new file mode 100644
index 0000000..ec73deb
--- /dev/null
+++ b/docs/screen-reader.md
@@ -0,0 +1,106 @@
+# Screen reader testing
+
+How we test Kork & Krone with a screen reader, what we found, and what is still left to check. Issue #47.
+
+## How we test
+
+Three parts, because none is enough on its own.
+
+1. **The accessibility tree, automated.** A screen reader reads the accessibility tree that the browser builds from the page, not the page itself. We read that tree for every page and step through each flow in Chromium (Playwright), and record after every action where focus is and what the live regions say. The flows that matter are in `frontend/e2e/screenreader.spec.ts`, so they stay fixed.
+2. **The real VoiceOver, automated.** `npm run voiceover` runs the script below with VoiceOver and records what it says. The result is in the [VoiceOver report](voiceover-report.md). This shows how VoiceOver phrases things and whether live regions are announced, which the accessibility tree cannot.
+3. **A person with VoiceOver.** The automated run cannot judge whether something is understandable, too long or annoying. Someone in the group goes through the script by hand before each submission.
+
+## What we found and fixed
+
+Found by stepping through the flows. Each one has a test that fails without the fix.
+
+| Where | Problem | Fix |
+| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
+| Search: active filters | Removing a filter removed the link the user was on. Focus fell back to the top of the page, so the screen reader started from the top again. | Focus moves to the next filter, or to the h1 when none are left. |
+| Search: «Nullstill filtre» and the links when nothing matched | Same: the link disappears with the click. | Focus moves to the h1, and the live region reads the new result. |
+| Wine page: saving or deleting a review | The buttons are disabled while saving, and the form is rebuilt after the first save. Focus was lost both times. | Focus goes back to the submit button once the result has been announced. |
+| Wine page: saving a review | The page announced «Laster vin …» while it refreshed, and showed a skeleton above the wine. | Only the first load is announced and shown. |
+| Login | The button was disabled while logging in, so focus was lost when the login failed. | `aria-disabled` instead of `disabled`, so focus stays on the button. Double clicks are still ignored. |
+| Login: «Lag bruker» / «Logg inn» | The form changed, but focus stayed on the switch button, so nothing told the user which form they were in. | Focus moves to the new h1, and the page title changes with it. |
+| Lag bruker: the password field | «Minst 8 tegn.» was shown under the field but not read with it. Only the username had its hint linked. | `aria-describedby` on the password field too. |
+| Mine anmeldelser: removing a wine from «Vil prøve» | The card disappeared with the button, focus was lost, and nothing was announced. | The live region says «Fjernet fra listen. 1 vin igjen.», and focus moves to the list heading. |
+| All pages, in development only | React StrictMode runs effects twice, so focus jumped to the h1 on the very first load. Production did not do this, so testing on the dev server gave a different result. | The layout compares with the previous path instead of counting renders. |
+
+Checked and fine: landmarks, one h1 per page, focus on the h1 after navigation, page titles, names on all buttons and form fields, «Vil prøve» as a toggle button (`aria-pressed`), the star rating as ten radio buttons, star ratings as text, the filter dialog (focus inside, Escape closes, focus back to the button), «Last inn flere» (focus on the first new wine), and the live regions for search results, loading and errors.
+
+## Automated test with VoiceOver
+
+[Guidepup](https://www.guidepup.dev/) controls VoiceOver and records every phrase it says. Playwright opens the app in WebKit, the engine in Safari, and moves focus and presses keys like a keyboard user. Each step in the script below has the phrases we expect, and the report marks the steps that did not say them. Only on macOS.
+
+Once per machine, in your own terminal, from `frontend/` after `npm install`:
+
+ npx @guidepup/setup setup
+ npx @guidepup/setup install voiceover
+
+The first command lets VoiceOver be controlled with AppleScript, and asks for Accessibility and Automation permission for the terminal (or the app that runs the command). The second downloads the VoiceOver settings that Guidepup uses during the run, and only works where `@guidepup/guidepup` is installed, which is why it runs from `frontend/`. Your own VoiceOver settings are put back afterwards.
+
+Then start the backend and the dev server, and run from `frontend/`:
+
+ npm run voiceover # all steps
+ npm run voiceover -- 5,9 # only steps 5 and 9
+
+VoiceOver talks while it runs, and the keyboard and mouse should be left alone until it is done. The report is written to [docs/voiceover-report.md](voiceover-report.md). Commit it, so the latest result is in the repository.
+
+## Manual test with VoiceOver
+
+Use VoiceOver on macOS with **Safari**, the combination most VoiceOver users have. Test against the dev server with the backend running, or against the VM. `npm run preview` has no API proxy, so the data does not load there.
+
+- Turn VoiceOver on and off: Cmd + F5 .
+- VO is Ctrl + Option . VO + arrow keys read the next or previous item.
+- VO + U opens the rotor, with lists of headings, links, landmarks and form controls.
+- Tab moves between controls. Space or Enter uses them.
+
+For each step, write down what VoiceOver says if it differs from the expected result.
+
+| # | Step | Expected |
+| --- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
+| 1 | Open the front page. Open the rotor and look at landmarks and headings. | Banner, «Hovedmeny», main and footer. One h1, then h2 for each section. |
+| 2 | Tab once from the top. | «Hopp til hovedinnhold, lenke». Enter goes to the main content. |
+| 3 | Type «pinot» in the search field and press Enter . | The new page is announced with its h1, «Utforsk viner». Then «Viser … viner for «pinot»». |
+| 4 | Go to the first wine card with VO + arrows. | Type and country, the name as a heading and link, the winery, «Fellesskapet 4,9 av 5 · 8 vurderinger», and «Vil prøve …, toggle button». |
+| 5 | Tick «Rødvin» in the filters with Space . | «Rødvin, 11 viner, checked» (not «unchecked»), then the new number of hits. |
+| 6 | Tab to «Fjern filteret Rødvin» and press Enter . | Focus on the next filter, or on «Utforsk viner» if it was the last. Then the new number of hits. |
+| 7 | Search for «finnesikke». | «Ingen treff», and the text that explains why, with the suggestions. |
+| 8 | Open a wine. Find «Gi din dom» and use the arrow keys in the stars. | «0,5 av 5 stjerner, radio button, 1 of 10», and so on up to 5. |
+| 9 | Choose 4 stars, write a comment, press «Lagre dommen». | «Dommen er lagret.» Focus on «Oppdater dommen». |
+| 10 | Press «Slett dommen». | «Dommen er slettet.» Focus on «Lagre dommen». |
+| 11 | Press «Vil prøve» on the wine page, then go to «Mine anmeldelser» and press it again on the card. | «Fjernet fra listen. Listen er tom.» Focus on «Vil prøve, heading level 2». |
+| 12 | Go to «Logg inn», log in with a wrong password. | «Feil brukernavn eller passord.» Focus still on «Logg inn». |
+| 13 | Press «Lag bruker». | «Lag bruker, heading level 1». The field hints are read with the fields. |
+| 14 | On a phone-sized window: open «Filtrer», choose a filter, close with «Vis … viner». | The dialog is announced with its heading, and focus goes back to «Filtrer (1 valgt)». |
+| 15 | Turn off the network (Wi-Fi) and search. | «Du er frakoblet …», and the error message says what is wrong. |
+
+### Results
+
+| Date | How | Browser and screen reader | Result |
+| ----------- | ------------------------------ | ----------------------------------- | ------------------------------------------------------------- |
+| 16 Nov 2026 | Automated, `npm run voiceover` | WebKit 27.2 + VoiceOver, macOS 26.6 | 11 of 15 steps passed. See the [report](voiceover-report.md). |
+| | By hand | Safari + VoiceOver (macOS) | Not run yet |
+
+## What the VoiceOver run found
+
+Fixed:
+
+- **Lists were not read as lists.** Safari and VoiceOver ignore the list role on a `
` or `` without bullets (`list-style: none`), unless it is inside `` or has `role="list"`. The suggestions on the front page were read as «group» instead of «list, 5 items», and the same went for search results, filters, reviews and categories. All 11 lists now have `role="list"`, and `src/test/listRoles.test.ts` fails if a new list does not.
+
+Confirmed with VoiceOver: the focus fixes above work. After removing the last filter, VoiceOver says «heading level 1, Utforsk viner», then the new number of hits. After saving a review it says «Oppdater dommen, button», then «Dommen er lagret.» The live regions for search results, reviews, «Vil prøve» and failed login are all read. The field rules are read with the fields: «Brukernavn, 3–30 tegn: små bokstaver, tall og understrek.»
+
+The four steps that failed, and what they mean:
+
+| Step | What happened | What it means |
+| ------------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| 2. Tab from the top | Tab went to the search field, not to «Hopp til hovedinnhold». | Safari's default: Tab skips links unless «Press Tab to highlight each item» is on, or the user presses Option + Tab. VoiceOver users move with VO + arrows, where the skip link is the first item (step 1). Not a bug in the app. |
+| 3. Search and press Enter | VoiceOver read «Viser 18 av 18 viner for «pinot»», but the h1 «Utforsk viner» was not recorded. | The h1 gets focus (the e2e test checks it, and step 6 hears it). The live region probably cut the heading off, or the script missed a short phrase. Check by hand. |
+| 5. Tick «Rødvin» | «unchecked» was heard, but from moving focus to the box before Space. After Space only the new number of hits was recorded. | The script is too strict. In the dialog (step 14) VoiceOver says «checked, Rødvin, 11 viner» after Space, so the state is read. Check by hand in the sidebar. |
+| 15. Offline | The banner «Du er frakoblet» was not recorded. The error «Du er ikke koblet til internett» and «Du er på nett igjen.» were. | The user is told about the problem when it matters. Check by hand whether the banner is announced when the network goes. |
+
+Not fixed yet:
+
+- **«invalid data» before the user has done anything.** Fields with `required` are read as «required, invalid data» while they are still empty, for example the star rating and the login fields. That can make a user think they did something wrong. One fix is to check the fields ourselves on submit instead of using `required`, and set `aria-invalid` only after a failed attempt.
+
+If there is time, also test with NVDA and Firefox on Windows, and VoiceOver on an iPhone.
diff --git a/docs/voiceover-report.md b/docs/voiceover-report.md
new file mode 100644
index 0000000..58acecd
--- /dev/null
+++ b/docs/voiceover-report.md
@@ -0,0 +1,233 @@
+# VoiceOver report
+
+Generated by `npm run voiceover` in `frontend/`. Do not edit by hand: run it again.
+The steps and how to read them are in [screen reader testing](screen-reader.md).
+
+- **Date:** 2026-11-16 22:43 UTC
+- **Screen reader:** VoiceOver on macOS 26.6.2 (Darwin 25.6.0)
+- **Browser:** WebKit 27.2 from Playwright, the engine in Safari
+- **Address:** http://localhost:5173/project2/
+- **Result:** 11 of 15 steps passed
+
+| # | Step | Expected | Result |
+| --- | --- | --- | --- |
+| 1 | Front page: landmarks and headings | From the top: the skip link, «Hovedmeny», the h1, then the sections with their headings. | Passed |
+| 2 | Tab once from the top | «Hopp til hovedinnhold, lenke». | **Failed** |
+| 3 | Search «pinot» and press Enter | The new page with its h1, «Utforsk viner», then «Viser … viner for «pinot»». | **Failed** |
+| 4 | The first wine card, item by item | The name as a heading and link, the winery, «Fellesskapet … av 5 · … vurderinger», and «Vil prøve …» as a toggle button. | Passed |
+| 5 | Tick «Rødvin» with Space | «Rødvin, 11 viner, checked» (not «unchecked»), then the new number of hits. | **Failed** |
+| 6 | Remove the filter chip with Enter | Focus on the next filter or on «Utforsk viner», then the new number of hits. | Passed |
+| 7 | Search «finnesikke» | «Ingen treff». | Passed |
+| 8 | Wine page: arrow keys in the stars | «0,5 av 5 stjerner, radio button, 1 of 10», then 1 and 1,5. | Passed |
+| 9 | Choose 4 stars, write a comment, «Lagre dommen» | «Dommen er lagret.» Focus on «Oppdater dommen». | Passed |
+| 10 | «Slett dommen» | «Dommen er slettet.» Focus on «Lagre dommen». | Passed |
+| 11 | «Vil prøve» on the wine page, then remove it on «Mine anmeldelser» | «Fjernet fra listen. Listen er tom.» Focus on «Vil prøve, heading level 2». | Passed |
+| 12 | Log in with a wrong password | «Feil brukernavn eller passord.» Focus still on «Logg inn». | Passed |
+| 13 | «Lag bruker», then the two fields | «Lag bruker, heading level 1». The rules are read with the fields. | Passed |
+| 14 | Phone size: the filter dialog | The dialog with its heading. After «Vis … viner», focus back on «Filtrer (1 valgt)». | Passed |
+| 15 | Offline, then search | «Du er frakoblet …», and an error that says what is wrong. | **Failed** |
+
+## What VoiceOver said
+
+### 1. Front page: landmarks and headings – passed
+
+- From the top: banner → Kork & Krone link → Hovedmeny navigation → list → Utforsk link → Mine anmeldelser link → Logg inn link → list → Hovedmeny navigation → banner → main → Finn vinen medstudentene dine faktisk liker region → VINREGISTER DREVET AV STUDENTER → Finn vinen medstudentene dine faktisk liker heading level 1 → Kork & Krone samler over 100 000 viner med vurderinger fra et stort vinfellesskap – og dommene fra studenter som deg. Søk, se hva andre mener, og gi din egen dom. → Søk etter vin search → Hva har du lyst til å smake? → Hva har du lyst til å smake? Navn, drue, region eller vingård search text field → Søk button → Søk etter vin search → Forslag til søk heading level 2 → Forslag til søk list → Til pizza link → Riesling link → Italiensk rødvin link → Bobler til feiring link → Best likt av studenter link → Forslag til søk list → Finn vinen medstudentene dine faktisk liker region → description list → viner å utforske → 100 → land representert → 17 → description list → Slik fungerer Kork & Krone region → Slik fungerer Kork & Krone heading level 2 → list → Søk heading level 3 → Finn vin etter navn, drue, region, type eller hva du skal spise. → Sammenlign heading level 3 → Se fellesskapets vurderinger side om side med hva medstudenter mener. → Gi din dom heading level 3 → Gi vinen 1 til 5 stjerner, skriv en kort kommentar og hjelp neste student. → list → Slik fungerer Kork & Krone region → Utforsk etter type region → Utforsk etter type heading level 2 → Se alle viner link → list
+
+> Playwright 🎭 Playwright: Kork & Krone – vin anmeldt av studenter window Kork & Krone – vin anmeldt av studenter web content has keyboard focus
+> link Hopp til hovedinnhold
+> banner
+> link Kork & Krone
+> list 3 items
+> link Utforsk 1 of 3
+> link Mine anmeldelser 2 of 3
+> link Logg inn 3 of 3
+> end of list
+> end of Hovedmeny navigation
+> end of banner
+> main
+> Finn vinen medstudentene dine faktisk liker region
+> VINREGISTER DREVET AV STUDENTER
+> heading level 1 Finn vinen medstudentene dine faktisk liker
+> Kork & Krone samler over 100 000 viner med vurderinger fra et stort vinfellesskap – og dommene fra studenter som deg. Søk, se hva andre mener, og gi din egen dom.
+> Søk etter vin search
+> Hva har du lyst til å smake?
+> Hva har du lyst til å smake? Navn, drue, region eller vingård search text field
+> Søk button
+> end of Søk etter vin search
+> heading level 2 Forslag til søk
+> list Forslag til søk 5 items
+> link Til pizza 1 of 5
+> link Riesling 2 of 5
+> link Italiensk rødvin 3 of 5
+> link Bobler til feiring 4 of 5
+> link Best likt av studenter 5 of 5
+> end of Finn vinen medstudentene dine faktisk liker region
+> description list 2 items
+> viner å utforske 1 of 4
+> 100 2 of 4
+> land representert 3 of 4
+> 17 4 of 4
+> end of description list
+> Slik fungerer Kork & Krone region
+> heading level 2 Slik fungerer Kork & Krone
+> list 3 items
+> heading level 3 Søk 1 of 3
+> Finn vin etter navn, drue, region, type eller hva du skal spise.
+> heading level 3 Sammenlign 2 of 3
+> Se fellesskapets vurderinger side om side med hva medstudenter mener.
+> heading level 3 Gi din dom 3 of 3
+> Gi vinen 1 til 5 stjerner, skriv en kort kommentar og hjelp neste student.
+> end of list
+> end of Slik fungerer Kork & Krone region
+> Utforsk etter type region
+> heading level 2 Utforsk etter type
+> link Se alle viner
+> list 6 items
+> Kork & Krone link
+> Hovedmeny navigation
+> list
+> Utforsk link
+> Mine anmeldelser link
+> Logg inn link
+> list
+> Hovedmeny navigation
+> Finn vinen medstudentene dine faktisk liker heading level 1
+> Forslag til søk heading level 2
+> Forslag til søk list
+> Til pizza link
+> Riesling link
+> Italiensk rødvin link
+> Bobler til feiring link
+> Best likt av studenter link
+> Forslag til søk list
+> description list
+> viner å utforske
+> 100
+> land representert
+> 17
+> description list
+> Slik fungerer Kork & Krone heading level 2
+> list
+> Søk heading level 3
+> Sammenlign heading level 3
+> Gi din dom heading level 3
+> list
+> Utforsk etter type heading level 2
+> Se alle viner link
+> list
+
+### 2. Tab once from the top – failed
+
+- Not said: `hopp til hovedinnhold`
+
+> Kork & Krone – vin anmeldt av studenter web content
+> Hva har du lyst til å smake? Navn, drue, region eller vingård search text field Søk etter vin search
+
+### 3. Search «pinot» and press Enter – failed
+
+- Not said: `utforsk viner`
+
+> Kork & Krone – vin anmeldt av studenter web content
+> t
+> Viser 18 av 18 viner for «pinot»
+
+### 4. The first wine card, item by item – passed
+
+- Items: Domaine Drouhin → description list → Fellesskapet → 4,9 av 5 · 8 vurderinger → description list → Vil prøve Lauréne Pinot Noir toggle button
+
+> link Lauréne Pinot Noir Lauréne Pinot Noir article
+> Domaine Drouhin
+> description list 1 item
+> Fellesskapet 1 of 2
+> 4,9 av 5 · 8 vurderinger 2 of 2
+> end of description list
+> Vil prøve Lauréne Pinot Noir toggle button
+> description list
+> Fellesskapet
+> 4,9 av 5 · 8 vurderinger
+> description list
+
+### 5. Tick «Rødvin» with Space – failed
+
+- Said, but should not: `unchecked|ikke avkrysset|ikke markert`
+
+> Rødvin, 11 viner unchecked checkbox list 4 items
+> Viser 11 av 11 viner for «pinot»
+
+### 6. Remove the filter chip with Enter – passed
+
+> link Fjern filteret Rødvin list Aktive filtre 1 item
+> heading level 1 Utforsk viner main
+> Viser 18 av 18 viner for «pinot»
+
+### 7. Search «finnesikke» – passed
+
+> e
+> Ingen treff
+> finnesikke
+> You are currently on a text field. To enter text in this field, type.
+
+### 8. Wine page: arrow keys in the stars – passed
+
+> Kork & Krone – vin anmeldt av studenter web content
+> 0,5 av 5 stjerner required invalid data radio button, 1 of 10 Gi din dom group
+> 1 av 5 stjerner required selected radio button, 2 of 10
+> 1,5 av 5 stjerner required selected radio button, 3 of 10
+
+### 9. Choose 4 stars, write a comment, «Lagre dommen» – passed
+
+> Lagre dommen button Vurderinger region
+> Oppdater dommen button
+> Dommen er lagret.
+> You are currently on a button. To click this button, press Control-Option-Space.
+
+### 10. «Slett dommen» – passed
+
+> Slett dommen button
+> Lagre dommen button
+> Dommen er slettet.
+> You are currently on a button. To click this button, press Control-Option-Space.
+
+### 11. «Vil prøve» on the wine page, then remove it on «Mine anmeldelser» – passed
+
+> Vil prøve toggle button Lauréne Pinot Noir article
+> Kork & Krone – vin anmeldt av studenter web content
+> Vil prøve Lauréne Pinot Noir selected toggle button Lauréne Pinot Noir article
+> heading level 2 Vil prøve Vil prøve region
+> Fjernet fra listen. Listen er tom.
+
+### 12. Log in with a wrong password – passed
+
+> Kork & Krone – vin anmeldt av studenter web content
+> finnesikke
+> Feil brukernavn eller passord.
+
+### 13. «Lag bruker», then the two fields – passed
+
+> Lag bruker button
+> heading level 1 Lag bruker
+> Brukernavn 3–30 tegn: små bokstaver, tall og understrek. required invalid data edit text
+> Passord Minst 8 tegn. required invalid data secure text field
+
+### 14. Phone size: the filter dialog – passed
+
+> Kork & Krone – vin anmeldt av studenter web content
+> Filtrer dialog pop up button main
+> Filtrer web dialog with 11 items Lukk button
+> Rødvin, 11 viner unchecked checkbox list 4 items
+> checked Rødvin, 11 viner checkbox
+> Vis 11 viner button
+> Filtrer (1 valgt) dialog pop up button main
+
+### 15. Offline, then search – failed
+
+- Not said: `frakoblet`
+
+> no action available web content
+> Kork & Krone – vin anmeldt av studenter web content
+> You are currently on web content. To enter the web area, press Control-Option-Shift-Down Arrow.
+> g
+> Vi fikk ikke søkt akkurat nå. Du er ikke koblet til internett. Sjekk tilkoblingen og prøv igjen. Prøv igjen
+> riesling
+> You are currently on a text field. To enter text in this field, type.
+> Du er på nett igjen.
diff --git a/frontend/e2e/screenreader.spec.ts b/frontend/e2e/screenreader.spec.ts
new file mode 100644
index 0000000..39d59ae
--- /dev/null
+++ b/frontend/e2e/screenreader.spec.ts
@@ -0,0 +1,156 @@
+import AxeBuilder from '@axe-core/playwright';
+import { expect, test, type Page } from '@playwright/test';
+
+/*
+ * E2E for what a screen reader user depends on beyond the markup: where focus goes when the
+ * element the user was on disappears, and what the live regions say. jsdom keeps focus on
+ * a disabled button, so these flows are only tested properly in a real browser.
+ * Runs against `vite preview` with a stubbed GraphQL API.
+ */
+interface Variables {
+ filter?: { types?: string[] };
+}
+
+const wine = (id: number, type: string) => ({
+ __typename: 'Wine',
+ id: String(id),
+ name: `${type} ${id}`,
+ type,
+ grapes: ['Merlot'],
+ country: 'Italy',
+ countryCode: 'IT',
+ wineryName: 'Testprodusent',
+ communityRating: 4,
+ communityRatingCount: 10,
+});
+
+function winesResponse({ filter }: Variables, search?: string) {
+ const types = search === 'finnesikke' ? [] : (filter?.types ?? ['Red', 'White']);
+ const wines = types.map((type, index) => wine(index + 1, type));
+ return {
+ data: {
+ wines: {
+ __typename: 'WineConnection',
+ totalCount: wines.length,
+ edges: wines.map((node) => ({ __typename: 'WineEdge', cursor: node.id, node })),
+ pageInfo: { __typename: 'PageInfo', hasNextPage: false, endCursor: null },
+ },
+ },
+ };
+}
+
+const option = (value: string, count: number) => ({
+ __typename: 'FilterOption',
+ value,
+ label: value,
+ count,
+});
+
+const filterResponse = {
+ data: {
+ filterOptions: {
+ __typename: 'FilterOptions',
+ types: [option('Red', 53), option('White', 19)],
+ countries: [option('IT', 25)],
+ grapes: [option('Merlot', 9)],
+ harmonize: [option('Beef', 53)],
+ },
+ },
+};
+
+async function stubApi(page: Page) {
+ await page.route('**/project2/graphql', (route) => {
+ const { operationName, variables } = route.request().postDataJSON() as {
+ operationName: string;
+ variables: Variables & { search?: string };
+ };
+ switch (operationName) {
+ case 'Me':
+ return route.fulfill({ json: { data: { me: null } } });
+ case 'Login':
+ return route.fulfill({
+ json: {
+ errors: [
+ { message: 'Invalid credentials', extensions: { code: 'INVALID_CREDENTIALS' } },
+ ],
+ },
+ });
+ case 'FilterOptions':
+ return route.fulfill({ json: filterResponse });
+ case 'SearchWines':
+ return route.fulfill({ json: winesResponse(variables, variables.search) });
+ default:
+ return route.abort();
+ }
+ });
+}
+
+const heading = (page: Page) => page.getByRole('heading', { level: 1 });
+// Scoped to : the layout has its own live region for the connection banner.
+const mainStatus = (page: Page) => page.getByRole('main').getByRole('status');
+
+async function expectNoAxeViolations(page: Page) {
+ const axe = await new AxeBuilder({ page })
+ .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
+ .analyze();
+ expect(axe.violations).toEqual([]);
+}
+
+test.describe('Skjermleser og fokus', () => {
+ test.beforeEach(async ({ page }) => {
+ await stubApi(page);
+ });
+
+ test('fokus går til neste filter når et filter fjernes, og til h1 når alle er borte', async ({
+ page,
+ }) => {
+ await page.goto('./sok?type=rodvin&type=hvitvin');
+ const removeRed = page.getByRole('link', { name: 'Fjern filteret Rødvin' });
+ await removeRed.focus();
+ await page.keyboard.press('Enter');
+
+ await expect(page).toHaveURL(/\/sok\?type=hvitvin$/);
+ const removeWhite = page.getByRole('link', { name: 'Fjern filteret Hvitvin' });
+ await expect(removeWhite).toBeFocused();
+ await expect(mainStatus(page)).toHaveText('Viser 1 av 1 vin');
+
+ await page.keyboard.press('Enter');
+ await expect(page).toHaveURL(/\/sok$/);
+ await expect(heading(page)).toBeFocused();
+ await expect(mainStatus(page)).toHaveText('Viser 2 av 2 viner');
+ });
+
+ test('fokus blir på knappen når innloggingen feiler, og feilen leses opp', async ({ page }) => {
+ await page.goto('./konto');
+ await page.getByRole('textbox', { name: 'Brukernavn' }).fill('ola');
+ await page.getByLabel('Passord').fill('feilpassord');
+ const submit = page.getByRole('main').getByRole('button', { name: 'Logg inn' });
+ await submit.focus();
+ await page.keyboard.press('Enter');
+
+ await expect(page.getByRole('alert')).toHaveText('Feil brukernavn eller passord.');
+ await expect(submit).toBeFocused();
+ });
+
+ test('fokus går til overskriften når skjemaet byttes til «Lag bruker»', async ({ page }) => {
+ await page.goto('./konto');
+ await page.getByRole('button', { name: 'Lag bruker' }).click();
+
+ await expect(heading(page)).toHaveText('Lag bruker');
+ await expect(heading(page)).toBeFocused();
+ await expect(page).toHaveTitle('Lag bruker – Kork & Krone');
+ });
+
+ for (const [name, path, title] of [
+ ['innlogging', './konto', 'Logg inn'],
+ ['Mine anmeldelser uten lagrede viner', './mine', 'Mine anmeldelser'],
+ ['søk uten treff', './sok?q=finnesikke', 'Utforsk viner'],
+ ['siden som ikke finnes', './finnesikke', 'Fant ikke siden'],
+ ]) {
+ test(`har ingen axe-brudd: ${name}`, async ({ page }) => {
+ await page.goto(path);
+ await expect(heading(page)).toHaveText(title);
+ await expectNoAxeViolations(page);
+ });
+ }
+});
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index f20ef88..3b936cc 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -18,6 +18,7 @@
"@axe-core/playwright": "^4.14.0",
"@babel/core": "^7.29.7",
"@eslint/js": "^10.0.1",
+ "@guidepup/guidepup": "^0.40.0",
"@playwright/test": "^1.64.1",
"@rolldown/plugin-babel": "^0.2.3",
"@testing-library/jest-dom": "^7.0.1",
@@ -749,6 +750,18 @@
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
}
},
+ "node_modules/@guidepup/guidepup": {
+ "version": "0.40.0",
+ "resolved": "https://registry.npmjs.org/@guidepup/guidepup/-/guidepup-0.40.0.tgz",
+ "integrity": "sha512-Rnrs6FCOa+v9q2jMyXeBTOHNIaMv3lCcE8Uq1HN8JIymbqpx59wct3VRyvhQYIStqW7uhmSjHiFE8ERCV3cc0w==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "dbus-native": "^0.15.1",
+ "debug": "^4.4.3",
+ "plist": "^4.0.0"
+ }
+ },
"node_modules/@humanfs/core": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz",
@@ -1867,6 +1880,16 @@
"node": ">=8"
}
},
+ "node_modules/@xmldom/xmldom": {
+ "version": "0.9.12",
+ "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.9.12.tgz",
+ "integrity": "sha512-5AXjrcMClTryPe9LgZrygpB1lj7s0S9E0+W+AHaVKAVyHanafK86iPSvG5xHVSp/jC+VH1UXu0TAEmY279xH7A==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.6"
+ }
+ },
"node_modules/acorn": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz",
@@ -2198,6 +2221,22 @@
"node": "^22.14.0 || >=24.0.0"
}
},
+ "node_modules/dbus-native": {
+ "version": "0.15.2",
+ "resolved": "https://registry.npmjs.org/dbus-native/-/dbus-native-0.15.2.tgz",
+ "integrity": "sha512-J1IBi4LmbqrFhroN66Dj1tCCTP6TVbZgUKhWQZf3uS6t93yRWEcRRDjOZV9N6boGRhOp/BOjLliFm9vWu1QZOA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "xml2js": "^0.6.2"
+ },
+ "bin": {
+ "dbus-native": "bin/dbus-native.js"
+ },
+ "engines": {
+ "node": ">=22.12.0"
+ }
+ },
"node_modules/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
@@ -3485,6 +3524,20 @@
"node": ">=20"
}
},
+ "node_modules/plist": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/plist/-/plist-4.0.0.tgz",
+ "integrity": "sha512-4dOqNo0Y2NpfSf9q4+zr4bh7pzNWeckIam34Z0KYJhg8qtNNfh59VbD+Yna5SjwcxawVvLKx5w5FtuCijpEF4Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@xmldom/xmldom": "^0.9.10",
+ "xmlbuilder": "^15.1.1"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/postcss": {
"version": "8.5.32",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz",
@@ -3712,6 +3765,16 @@
"tslib": "^2.1.0"
}
},
+ "node_modules/sax": {
+ "version": "1.6.1",
+ "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
+ "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
+ "dev": true,
+ "license": "BlueOak-1.0.0",
+ "engines": {
+ "node": ">=11.0.0"
+ }
+ },
"node_modules/saxes": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz",
@@ -4290,6 +4353,40 @@
"node": ">=18"
}
},
+ "node_modules/xml2js": {
+ "version": "0.6.2",
+ "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
+ "integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "sax": ">=0.6.0",
+ "xmlbuilder": "~11.0.0"
+ },
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ },
+ "node_modules/xml2js/node_modules/xmlbuilder": {
+ "version": "11.0.1",
+ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
+ "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=4.0"
+ }
+ },
+ "node_modules/xmlbuilder": {
+ "version": "15.1.1",
+ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz",
+ "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=8.0"
+ }
+ },
"node_modules/xmlchars": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index 41b8b8d..6658415 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -15,7 +15,8 @@
"test:run": "vitest run",
"test:coverage": "node scripts/coverage.mjs",
"typecheck": "tsc -b --noEmit",
- "e2e": "playwright test"
+ "e2e": "playwright test",
+ "voiceover": "node scripts/voiceover.mjs"
},
"dependencies": {
"@apollo/client": "^4.3.7",
@@ -28,6 +29,7 @@
"@axe-core/playwright": "^4.14.0",
"@babel/core": "^7.29.7",
"@eslint/js": "^10.0.1",
+ "@guidepup/guidepup": "^0.40.0",
"@playwright/test": "^1.64.1",
"@rolldown/plugin-babel": "^0.2.3",
"@testing-library/jest-dom": "^7.0.1",
diff --git a/frontend/scripts/voiceover.mjs b/frontend/scripts/voiceover.mjs
new file mode 100644
index 0000000..5cadf53
--- /dev/null
+++ b/frontend/scripts/voiceover.mjs
@@ -0,0 +1,387 @@
+// `npm run voiceover`: runs the screen reader script in docs/screen-reader.md with the real
+// VoiceOver, and writes what it said to docs/voiceover-report.md.
+//
+// Playwright opens the app in WebKit, the engine in Safari, and moves focus and presses keys
+// like a keyboard user. VoiceOver follows the focus and reads live regions, and Guidepup
+// records every phrase it says. Each step has the phrases we expect, so the report says which
+// steps passed. Only on macOS, and only after the one-time setup in docs/screen-reader.md.
+//
+// Needs the dev server (port 5173) and the backend running. BASE= tests another address.
+// `npm run voiceover -- 5,9` runs only steps 5 and 9.
+import { voiceOver } from '@guidepup/guidepup';
+import { webkit } from '@playwright/test';
+import { execFile, execFileSync } from 'node:child_process';
+import { promisify } from 'node:util';
+import { writeFileSync } from 'node:fs';
+import { release } from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const BASE = process.env.BASE ?? 'http://localhost:5173/project2/';
+const REPORT = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ '../../docs/voiceover-report.md',
+);
+const only = process.argv[2] ? process.argv[2].split(',').map(Number) : null;
+
+const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
+const run = promisify(execFile);
+
+/**
+ * The last thing VoiceOver said, asked from VoiceOver itself. Guidepup's lastSpokenPhrase()
+ * only knows what its own commands caused, not what VoiceOver says when focus moves or a
+ * live region changes.
+ */
+async function lastPhrase() {
+ try {
+ const { stdout } = await run('/usr/bin/osascript', [
+ '-e',
+ 'tell application "VoiceOver" to return content of last phrase',
+ ]);
+ return stdout.trim();
+ } catch {
+ return '';
+ }
+}
+
+/** Collects every new phrase VoiceOver says while `action` runs and for `ms` after it starts. */
+async function record(action, ms) {
+ const phrases = [];
+ let last = await lastPhrase();
+ let done = false;
+ const listening = (async () => {
+ const end = Date.now() + ms;
+ // Until the step is done and at least `ms` has passed, so late live regions are heard too.
+ while (!done || Date.now() < end) {
+ const phrase = await lastPhrase();
+ if (phrase && phrase !== last) {
+ phrases.push(phrase);
+ last = phrase;
+ }
+ await wait(120);
+ }
+ })();
+ await action();
+ done = true;
+ await listening;
+ return phrases;
+}
+
+/** What VoiceOver reads item by item when the user moves on with VO + Right arrow. */
+async function readOn(count) {
+ const items = [];
+ for (let i = 0; i < count; i++) {
+ await voiceOver.next();
+ items.push((await voiceOver.itemText()).trim());
+ }
+ return items;
+}
+
+const browser = await webkit.launch({ headless: false });
+const context = await browser.newContext({ viewport: { width: 1280, height: 860 } });
+const page = await context.newPage();
+const main = () => page.getByRole('main');
+
+/**
+ * Makes the WebKit window the active app in macOS, so VoiceOver reads it and not the terminal.
+ * Playwright's bringToFront() only fronts the tab. AppKit is used instead of AppleScript, so
+ * no Automation permission is needed.
+ */
+function activateBrowser() {
+ const pid = execFileSync('pgrep', ['-n', '-f', 'Playwright.app/Contents/MacOS/Playwright'], {
+ encoding: 'utf8',
+ }).trim();
+ execFileSync('/usr/bin/osascript', [
+ '-l',
+ 'JavaScript',
+ '-e',
+ `ObjC.import('AppKit'); $.NSRunningApplication.runningApplicationWithProcessIdentifier(${pid})` +
+ '.activateWithOptions($.NSApplicationActivateAllWindows | $.NSApplicationActivateIgnoringOtherApps)',
+ ]);
+}
+
+async function go(urlPath) {
+ await page.goto(BASE + urlPath);
+ await page.waitForLoadState('networkidle');
+ activateBrowser();
+ await wait(2000);
+}
+
+/** Focus first, then wait, so VoiceOver has read the control before the key press. */
+async function press(locator, key) {
+ await locator.focus();
+ await wait(1500);
+ await page.keyboard.press(key);
+}
+
+/*
+ * The steps from docs/screen-reader.md. `expect` lists what VoiceOver must say at some point
+ * during the step, as regular expressions. VoiceOver says roles in the language of macOS,
+ * so the patterns accept English and Norwegian.
+ */
+const STEPS = [
+ {
+ title: 'Front page: landmarks and headings',
+ expected:
+ 'From the top: the skip link, «Hovedmeny», the h1, then the sections with their headings.',
+ expect: [/hovedmeny/i, /finn vinen medstudentene dine faktisk liker/i, /slik fungerer/i],
+ ms: 500,
+ // VO + Right arrow from the top, item by item. The commands that jump to the next
+ // heading or landmark are key presses, which need Automation permission for System Events.
+ async run(notes) {
+ await go('');
+ await page.getByRole('link', { name: 'Hopp til hovedinnhold' }).focus();
+ await wait(1500);
+ const items = await readOn(50);
+ notes.push(`From the top: ${items.join(' → ')}`);
+ return items;
+ },
+ },
+ {
+ title: 'Tab once from the top',
+ expected: '«Hopp til hovedinnhold, lenke».',
+ expect: [/hopp til hovedinnhold/i],
+ async run() {
+ await go('');
+ await page.keyboard.press('Tab');
+ },
+ },
+ {
+ title: 'Search «pinot» and press Enter',
+ expected: 'The new page with its h1, «Utforsk viner», then «Viser … viner for «pinot»».',
+ expect: [/utforsk viner/i, /viser \d+ av \d+ viner for .?pinot/i],
+ ms: 6000,
+ async run() {
+ await go('');
+ await page.getByRole('searchbox').first().focus();
+ await page.keyboard.type('pinot');
+ await page.keyboard.press('Enter');
+ },
+ },
+ {
+ title: 'The first wine card, item by item',
+ expected:
+ 'The name as a heading and link, the winery, «Fellesskapet … av 5 · … vurderinger», and «Vil prøve …» as a toggle button.',
+ expect: [/fellesskapet/i, /av 5/i, /vil prøve/i],
+ ms: 500,
+ async run(notes) {
+ await page.getByRole('list', { name: 'Søkeresultater' }).getByRole('link').first().focus();
+ await wait(1500);
+ const items = await readOn(6);
+ notes.push(`Items: ${items.join(' → ')}`);
+ return items;
+ },
+ },
+ {
+ title: 'Tick «Rødvin» with Space',
+ expected: '«Rødvin, 11 viner, checked» (not «unchecked»), then the new number of hits.',
+ expect: [/rødvin/i, /viser \d+ av \d+ vin/i],
+ reject: [/unchecked|ikke avkrysset|ikke markert/i],
+ ms: 5000,
+ async run() {
+ await press(page.getByRole('checkbox', { name: /^Rødvin/ }), 'Space');
+ },
+ },
+ {
+ title: 'Remove the filter chip with Enter',
+ expected: 'Focus on the next filter or on «Utforsk viner», then the new number of hits.',
+ expect: [/utforsk viner|fjern filteret/i, /viser \d+ av \d+ vin/i],
+ ms: 5000,
+ async run() {
+ await press(page.getByRole('link', { name: /^Fjern filteret/ }).first(), 'Enter');
+ },
+ },
+ {
+ title: 'Search «finnesikke»',
+ expected: '«Ingen treff».',
+ expect: [/ingen treff/i],
+ ms: 6000,
+ async run() {
+ const box = page.getByRole('searchbox', { name: 'Søk etter vin' });
+ await box.fill('');
+ await box.focus();
+ await page.keyboard.type('finnesikke');
+ },
+ },
+ {
+ title: 'Wine page: arrow keys in the stars',
+ expected: '«0,5 av 5 stjerner, radio button, 1 of 10», then 1 and 1,5.',
+ expect: [/0,5 av 5 stjerner/i, /1 av 5 stjerner/i, /1,5 av 5 stjerner/i],
+ ms: 6000,
+ async run() {
+ await go('vin/181199');
+ await press(page.getByRole('radio', { name: '0,5 av 5 stjerner' }), 'ArrowRight');
+ await wait(1500);
+ await page.keyboard.press('ArrowRight');
+ },
+ },
+ {
+ title: 'Choose 4 stars, write a comment, «Lagre dommen»',
+ expected: '«Dommen er lagret.» Focus on «Oppdater dommen».',
+ expect: [/dommen er lagret/i, /oppdater dommen/i],
+ ms: 6000,
+ async run() {
+ await page.getByRole('radio', { name: '4 av 5 stjerner' }).check();
+ await page.getByRole('textbox', { name: /Kommentar/ }).fill('Fin og frisk');
+ await press(main().getByRole('button', { name: 'Lagre dommen' }), 'Space');
+ },
+ },
+ {
+ title: '«Slett dommen»',
+ expected: '«Dommen er slettet.» Focus on «Lagre dommen».',
+ expect: [/dommen er slettet/i, /lagre dommen/i],
+ ms: 6000,
+ async run() {
+ await press(main().getByRole('button', { name: 'Slett dommen' }), 'Space');
+ },
+ },
+ {
+ title: '«Vil prøve» on the wine page, then remove it on «Mine anmeldelser»',
+ expected: '«Fjernet fra listen. Listen er tom.» Focus on «Vil prøve, heading level 2».',
+ expect: [/fjernet fra listen/i, /vil prøve/i],
+ ms: 10000,
+ async run() {
+ await press(main().getByRole('button', { name: 'Vil prøve', exact: true }), 'Space');
+ await wait(1500);
+ await go('mine');
+ await press(
+ main()
+ .getByRole('button', { name: /^Vil prøve/ })
+ .first(),
+ 'Space',
+ );
+ },
+ },
+ {
+ title: 'Log in with a wrong password',
+ expected: '«Feil brukernavn eller passord.» Focus still on «Logg inn».',
+ expect: [/feil brukernavn eller passord/i],
+ ms: 6000,
+ async run() {
+ await go('konto');
+ await page.getByRole('textbox', { name: 'Brukernavn' }).fill('finnesikke');
+ await page.getByLabel('Passord').fill('feilpassord1');
+ await press(main().getByRole('button', { name: 'Logg inn' }), 'Space');
+ },
+ },
+ {
+ title: '«Lag bruker», then the two fields',
+ expected: '«Lag bruker, heading level 1». The rules are read with the fields.',
+ expect: [/lag bruker/i, /3.30 tegn/i, /minst 8 tegn/i],
+ ms: 13000,
+ async run() {
+ await press(main().getByRole('button', { name: 'Lag bruker' }), 'Space');
+ await wait(3000);
+ await page.getByRole('textbox', { name: 'Brukernavn' }).focus();
+ await wait(4000);
+ await page.getByLabel('Passord').focus();
+ },
+ },
+ {
+ title: 'Phone size: the filter dialog',
+ expected:
+ 'The dialog with its heading. After «Vis … viner», focus back on «Filtrer (1 valgt)».',
+ expect: [/filtrer/i, /rødvin/i, /1 valgt/i],
+ ms: 15000,
+ async run() {
+ await page.setViewportSize({ width: 390, height: 844 });
+ await go('sok?q=pinot');
+ await press(page.getByRole('button', { name: /^Filtrer/ }), 'Space');
+ await wait(3000);
+ await press(page.getByRole('dialog').getByRole('checkbox', { name: /^Rødvin/ }), 'Space');
+ await wait(3000);
+ await press(page.getByRole('dialog').getByRole('button', { name: /^Vis \d/ }), 'Space');
+ },
+ },
+ {
+ title: 'Offline, then search',
+ expected: '«Du er frakoblet …», and an error that says what is wrong.',
+ expect: [/frakoblet/i],
+ ms: 11000,
+ async run() {
+ await page.setViewportSize({ width: 1280, height: 860 });
+ await go('sok');
+ await context.setOffline(true);
+ await wait(3000);
+ await page.getByRole('searchbox', { name: 'Søk etter vin' }).focus();
+ await page.keyboard.type('riesling');
+ await wait(4000);
+ await context.setOffline(false);
+ },
+ },
+];
+
+const results = [];
+try {
+ await voiceOver.start();
+ for (const [index, step] of STEPS.entries()) {
+ const n = index + 1;
+ if (only && !only.includes(n)) continue;
+ const notes = [];
+ let heard = [];
+ activateBrowser();
+ let error;
+ try {
+ let read = [];
+ heard = await record(async () => {
+ read = (await step.run(notes)) ?? [];
+ }, step.ms ?? 4000);
+ heard = [...heard, ...read.filter((item) => item && !heard.includes(item))];
+ } catch (cause) {
+ error = cause instanceof Error ? cause.message.split('\n')[0] : String(cause);
+ }
+ const text = heard.join('\n');
+ const missing = step.expect.filter((pattern) => !pattern.test(text));
+ const unwanted = (step.reject ?? []).filter((pattern) => pattern.test(text));
+ const passed = !error && missing.length === 0 && unwanted.length === 0;
+ results.push({ n, step, heard, notes, error, missing, unwanted, passed });
+ console.log(`${passed ? '✓' : '✗'} ${n}. ${step.title}`);
+ for (const phrase of heard) console.log(` ${phrase}`);
+ }
+} finally {
+ await browser.close();
+ await voiceOver.stop().catch(() => undefined);
+}
+
+const macOS = execFileSync('sw_vers', ['-productVersion'], { encoding: 'utf8' }).trim();
+const passedCount = results.filter((result) => result.passed).length;
+const cell = (text) => text.replaceAll('|', '\\|').replaceAll('\n', ' ');
+
+const report = [
+ '# VoiceOver report',
+ '',
+ 'Generated by `npm run voiceover` in `frontend/`. Do not edit by hand: run it again.',
+ 'The steps and how to read them are in [screen reader testing](screen-reader.md).',
+ '',
+ `- **Date:** ${new Date().toISOString().slice(0, 16).replace('T', ' ')} UTC`,
+ `- **Screen reader:** VoiceOver on macOS ${macOS} (Darwin ${release()})`,
+ `- **Browser:** WebKit ${browser.version()} from Playwright, the engine in Safari`,
+ `- **Address:** ${BASE}`,
+ `- **Result:** ${passedCount} of ${results.length} steps passed${only ? ` (only steps ${only.join(', ')} were run)` : ''}`,
+ '',
+ '| # | Step | Expected | Result |',
+ '| --- | --- | --- | --- |',
+ ...results.map(
+ ({ n, step, passed }) =>
+ `| ${n} | ${cell(step.title)} | ${cell(step.expected)} | ${passed ? 'Passed' : '**Failed**'} |`,
+ ),
+ '',
+ '## What VoiceOver said',
+ '',
+ ...results.flatMap(({ n, step, heard, notes, error, missing, unwanted, passed }) => [
+ `### ${n}. ${step.title} – ${passed ? 'passed' : 'failed'}`,
+ '',
+ ...(error ? [`The step stopped: ${error}`, ''] : []),
+ ...missing.map((pattern) => `- Not said: \`${pattern.source}\``),
+ ...unwanted.map((pattern) => `- Said, but should not: \`${pattern.source}\``),
+ ...(missing.length || unwanted.length ? [''] : []),
+ ...notes.map((note) => `- ${note}`),
+ ...(notes.length ? [''] : []),
+ ...(heard.length ? heard.map((phrase) => `> ${cell(phrase)} `) : ['> (nothing)']),
+ '',
+ ]),
+].join('\n');
+
+writeFileSync(REPORT, report);
+console.log(`\n${passedCount} of ${results.length} steps passed. Report: ${REPORT}`);
+process.exit(passedCount === results.length ? 0 : 1);
diff --git a/frontend/src/components/layout/AppLayout.tsx b/frontend/src/components/layout/AppLayout.tsx
index 7f4b993..0c94d9c 100644
--- a/frontend/src/components/layout/AppLayout.tsx
+++ b/frontend/src/components/layout/AppLayout.tsx
@@ -14,15 +14,15 @@ import styles from './AppLayout.module.css';
*/
export function AppLayout() {
const { pathname } = useLocation();
- const isFirstRender = useRef(true);
+ // Compared with the previous path instead of counting renders. StrictMode runs effects
+ // twice in development, and a counter would then move focus on the very first load.
+ const previousPathname = useRef(pathname);
const mainRef = useRef(null);
useEffect(() => {
- if (isFirstRender.current) {
- isFirstRender.current = false;
- return;
- }
+ if (previousPathname.current === pathname) return;
+ previousPathname.current = pathname;
const main = mainRef.current;
if (!main) return;
return focusHeadingWhenReady(main);
diff --git a/frontend/src/components/ui/Chip.tsx b/frontend/src/components/ui/Chip.tsx
index ed0eb8c..95d4594 100644
--- a/frontend/src/components/ui/Chip.tsx
+++ b/frontend/src/components/ui/Chip.tsx
@@ -9,15 +9,16 @@ interface ChipLinkProps {
tone?: 'default' | 'onBrand';
/** Replaces the visible text for screen readers when it says too little on its own. */
label?: string;
+ onClick?: () => void;
}
/**
* Chip som navigerer (forslag, kategorier, aktive filtre som lenker).
* Det er en lenke – ikke en knapp – fordi den endrer side/URL.
*/
-export function ChipLink({ to, children, tone = 'default', label }: ChipLinkProps) {
+export function ChipLink({ to, children, tone = 'default', label, onClick }: ChipLinkProps) {
return (
-
+
{children}
);
diff --git a/frontend/src/components/ui/WineList.tsx b/frontend/src/components/ui/WineList.tsx
index ae2be86..27b92f2 100644
--- a/frontend/src/components/ui/WineList.tsx
+++ b/frontend/src/components/ui/WineList.tsx
@@ -10,10 +10,16 @@ interface WineListProps {
ref?: Ref;
}
-/** Wine cards in a grid: one, two or three columns depending on the available width. */
+/**
+ * Wine cards in a grid: one, two or three columns depending on the available width.
+ *
+ * role="list" is not redundant: Safari and VoiceOver stop treating a list without bullets
+ * (list-style: none) as a list, so «list, 24 items» is never read. The same goes for the
+ * other lists without bullets in the app. Lists inside keep their role.
+ */
export function WineList({ wines, headingLevel, label, ref }: WineListProps) {
return (
-
+
{wines.map((wine) => (
diff --git a/frontend/src/features/auth/AccountPage.test.tsx b/frontend/src/features/auth/AccountPage.test.tsx
index 3540ef0..5d344b8 100644
--- a/frontend/src/features/auth/AccountPage.test.tsx
+++ b/frontend/src/features/auth/AccountPage.test.tsx
@@ -83,6 +83,22 @@ describe('AccountPage', () => {
await waitFor(() =>
expect(screen.getByRole('alert')).toHaveTextContent('Feil brukernavn eller passord.'),
);
+ // The button is never disabled, so the user is still in the form and can try again.
+ expect(screen.getByRole('button', { name: 'Logg inn' })).toHaveFocus();
+ });
+
+ it('moves focus to the new heading when switching to «Lag bruker»', async () => {
+ const { user } = renderPage([me(null)]);
+
+ await user.click(await screen.findByRole('button', { name: 'Lag bruker' }));
+
+ expect(screen.getByRole('heading', { level: 1, name: 'Lag bruker' })).toHaveFocus();
+ expect(document.title).toBe('Lag bruker – Kork & Krone');
+ // The rules are read together with the fields, not only seen under them.
+ expect(screen.getByLabelText('Brukernavn')).toHaveAccessibleDescription(
+ '3–30 tegn: bokstavene a–z, tall og understrek. Store bokstaver blir små.',
+ );
+ expect(screen.getByLabelText('Passord')).toHaveAccessibleDescription('Minst 8 tegn.');
});
it('explains which rule the username broke', async () => {
diff --git a/frontend/src/features/auth/AccountPage.tsx b/frontend/src/features/auth/AccountPage.tsx
index 97a3b2f..a41e67c 100644
--- a/frontend/src/features/auth/AccountPage.tsx
+++ b/frontend/src/features/auth/AccountPage.tsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { useNavigate, useLocation, Link } from 'react-router';
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
import type { AuthFailure } from './api/authMessages';
@@ -18,10 +18,22 @@ function nextPage(state: unknown): string {
export default function AccountPage() {
const [logoutError, setLogoutError] = useState('');
const [mode, setMode] = useState<'login' | 'register'>('login');
+ const headingRef = useRef(null);
+ const previousMode = useRef(mode);
const { user, loading, login, register, logout } = useAuth();
const navigate = useNavigate();
const location = useLocation();
- useDocumentTitle(user ? 'Min konto' : 'Logg inn');
+ useDocumentTitle(user ? 'Min konto' : mode === 'login' ? 'Logg inn' : 'Lag bruker');
+
+ // Switching between logging in and creating a user replaces the form, like a new page.
+ // Focus moves to the new heading, so screen reader users hear which form they are in.
+ useEffect(() => {
+ if (previousMode.current === mode) return;
+ previousMode.current = mode;
+ const heading = headingRef.current;
+ heading?.setAttribute('tabindex', '-1');
+ heading?.focus();
+ }, [mode]);
async function handleSubmit(credentials: Credentials): Promise {
const failure = await (mode === 'login' ? login : register)(credentials);
@@ -64,7 +76,7 @@ export default function AccountPage() {
return (
-
{mode === 'login' ? 'Logg inn' : 'Lag bruker'}
+
{mode === 'login' ? 'Logg inn' : 'Lag bruker'}
{mode === 'login'
? 'Logg inn for å ta vare på dommene og listene dine.'
diff --git a/frontend/src/features/landing/components/CategoryList.tsx b/frontend/src/features/landing/components/CategoryList.tsx
index 7d6934e..f15376a 100644
--- a/frontend/src/features/landing/components/CategoryList.tsx
+++ b/frontend/src/features/landing/components/CategoryList.tsx
@@ -16,7 +16,7 @@ export function CategoryList({ categories }: { categories: CategoryCount[] }) {
return (
// data-scroll-x: scroller horisontalt med vilje på mobil (brukes av E2E-reflow-testen).
-
+
{visible.map((type) => {
const count = byType.get(type) ?? 0;
return (
diff --git a/frontend/src/features/landing/components/Hero.tsx b/frontend/src/features/landing/components/Hero.tsx
index 8a6396d..5808dd6 100644
--- a/frontend/src/features/landing/components/Hero.tsx
+++ b/frontend/src/features/landing/components/Hero.tsx
@@ -31,7 +31,7 @@ export function Hero() {
Forslag til søk
-
+
{SUGGESTIONS.map((s) => (
diff --git a/frontend/src/features/landing/components/HowItWorks.tsx b/frontend/src/features/landing/components/HowItWorks.tsx
index 67b8e63..165fb13 100644
--- a/frontend/src/features/landing/components/HowItWorks.tsx
+++ b/frontend/src/features/landing/components/HowItWorks.tsx
@@ -22,7 +22,7 @@ export function HowItWorks() {
Slik fungerer Kork & Krone
-
+
{STEPS.map((step, i) => (
diff --git a/frontend/src/features/landing/components/RecentReviews.tsx b/frontend/src/features/landing/components/RecentReviews.tsx
index 077a33d..93a302f 100644
--- a/frontend/src/features/landing/components/RecentReviews.tsx
+++ b/frontend/src/features/landing/components/RecentReviews.tsx
@@ -18,7 +18,7 @@ export function RecentReviews({ reviews, now }: RecentReviewsProps) {
}
return (
-
+
{reviews.map((review) => (
diff --git a/frontend/src/features/my/MyPage.test.tsx b/frontend/src/features/my/MyPage.test.tsx
index b620865..b4eb6ee 100644
--- a/frontend/src/features/my/MyPage.test.tsx
+++ b/frontend/src/features/my/MyPage.test.tsx
@@ -88,6 +88,10 @@ describe('MyPage', () => {
await user.click(await screen.findByRole('button', { name: 'Vil prøve Origem Merlot' }));
expect(screen.getByText(/Du har ikke lagret noen viner ennå/)).toBeInTheDocument();
+ // The button the user clicked is gone. The live region says what happened,
+ // and focus moves to the heading of the list instead of the top of the page.
+ expect(screen.getByRole('status')).toHaveTextContent('Fjernet fra listen. Listen er tom.');
+ expect(screen.getByRole('heading', { level: 2, name: 'Vil prøve' })).toHaveFocus();
});
it('offers a new attempt when the wines cannot be fetched', async () => {
diff --git a/frontend/src/features/my/MyView.tsx b/frontend/src/features/my/MyView.tsx
index ac1f5f4..360906b 100644
--- a/frontend/src/features/my/MyView.tsx
+++ b/frontend/src/features/my/MyView.tsx
@@ -1,7 +1,9 @@
+import { useEffect, useRef, useState } from 'react';
import { Link } from 'react-router';
import { ErrorNotice } from '../../components/ui/ErrorNotice';
import { Skeleton } from '../../components/ui/Skeleton';
import { WineList } from '../../components/ui/WineList';
+import { focusIfLost } from '../../lib/focus';
import { pluralize } from '../../lib/format';
import { buildSearchUrl } from '../../lib/searchParams';
import type { WishlistResult } from './api/useWishlistWines';
@@ -9,15 +11,40 @@ import styles from './MyView.module.css';
/** Presentation of «Mine anmeldelser». The list lives in the browser until we have login. */
export function MyView({ wines, savedCount, loading, error, refetch }: WishlistResult) {
+ const headingRef = useRef(null);
+ const [previousCount, setPreviousCount] = useState(savedCount);
+ const [message, setMessage] = useState('');
+
+ // A wine removed with its heart disappears from the list, and the button with it.
+ // Saying so in the live region tells screen reader users that the click worked.
+ if (savedCount !== previousCount) {
+ setPreviousCount(savedCount);
+ setMessage(
+ savedCount < previousCount
+ ? `Fjernet fra listen. ${savedCount === 0 ? 'Listen er tom.' : `${pluralize(savedCount, 'vin', 'viner')} igjen.`}`
+ : '',
+ );
+ }
+
+ // The removed card had focus, so it moves to the heading of the list.
+ const countBefore = useRef(savedCount);
+ useEffect(() => {
+ const removed = savedCount < countBefore.current;
+ countBefore.current = savedCount;
+ if (removed) focusIfLost(headingRef.current);
+ }, [savedCount]);
+
return (
Mine anmeldelser
- Vil prøve
+
+ Vil prøve
+
- {loading ? 'Laster viner …' : ''}
+ {loading ? 'Laster viner …' : message}
{savedCount === 0 ? (
diff --git a/frontend/src/features/search/SearchFilters.test.tsx b/frontend/src/features/search/SearchFilters.test.tsx
index f22ac27..e581ec4 100644
--- a/frontend/src/features/search/SearchFilters.test.tsx
+++ b/frontend/src/features/search/SearchFilters.test.tsx
@@ -210,6 +210,26 @@ describe('Aktive filtre', () => {
);
});
+ it('flytter fokus til neste filter når et filter fjernes', async () => {
+ const { user } = renderPage(
+ [searchMock(() => 3).mock, filterOptionsMock().mock],
+ '/sok?q=pinot&type=rodvin&land=IT',
+ );
+ await user.click(await screen.findByRole('link', { name: 'Fjern filteret Rødvin' }));
+ await waitFor(() => expect(location()).toHaveTextContent('/sok?q=pinot&land=IT'));
+ expect(screen.getByRole('link', { name: 'Fjern filteret Italia' })).toHaveFocus();
+ });
+
+ it('flytter fokus til h1 når det siste filteret fjernes', async () => {
+ const { user } = renderPage(
+ [searchMock(() => 3).mock, filterOptionsMock().mock],
+ '/sok?q=pinot&type=rodvin&land=IT',
+ );
+ await user.click(await screen.findByRole('link', { name: 'Nullstill filtre' }));
+ await waitFor(() => expect(location()).toHaveTextContent('/sok?q=pinot'));
+ expect(screen.getByRole('heading', { level: 1, name: 'Utforsk viner' })).toHaveFocus();
+ });
+
it('vises ikke uten filtre', async () => {
renderPage([searchMock(() => 3).mock, filterOptionsMock().mock], '/sok?q=pinot');
await screen.findByRole('list', { name: 'Søkeresultater' });
diff --git a/frontend/src/features/search/SearchPage.test.tsx b/frontend/src/features/search/SearchPage.test.tsx
index c4ad75f..12c72a4 100644
--- a/frontend/src/features/search/SearchPage.test.tsx
+++ b/frontend/src/features/search/SearchPage.test.tsx
@@ -289,6 +289,21 @@ describe('SearchPage – states', () => {
expect(screen.getByRole('link', { name: 'Se alle viner' })).toHaveAttribute('href', '/sok');
});
+ it('moves focus to the h1 when a no-hits link disappears after the click', async () => {
+ const { user } = renderPage([searchMock(({ search }) => (search ? 0 : 3)).mock], '/sok?q=zzz');
+ await user.click(await screen.findByRole('link', { name: 'Se alle viner' }));
+ expect(await results()).toBeInTheDocument();
+ expect(screen.getByRole('heading', { level: 1, name: 'Utforsk viner' })).toHaveFocus();
+ });
+
+ it('keeps focus in the search field while the user types', async () => {
+ const { user } = renderPage([searchMock(() => 3).mock]);
+ await results();
+ await user.type(searchbox(), 'pinot');
+ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('q=pinot'));
+ expect(searchbox()).toHaveFocus();
+ });
+
it('shows its own text when filters without a search word have no hits', async () => {
renderPage([searchMock(() => 0).mock], '/sok?type=rodvin');
expect(await screen.findByText('Ingen viner passer til valgene dine.')).toBeInTheDocument();
diff --git a/frontend/src/features/search/SearchView.tsx b/frontend/src/features/search/SearchView.tsx
index 16f1525..e6be315 100644
--- a/frontend/src/features/search/SearchView.tsx
+++ b/frontend/src/features/search/SearchView.tsx
@@ -1,9 +1,11 @@
import { useEffect, useRef, useId } from 'react';
+import { useLocation } from 'react-router';
import { ErrorNotice } from '../../components/ui/ErrorNotice';
import { SearchForm } from '../../components/ui/SearchForm';
import { Skeleton } from '../../components/ui/Skeleton';
import { WineList } from '../../components/ui/WineList';
import { useMediaQuery } from '../../hooks/useMediaQuery';
+import { focusIfLost } from '../../lib/focus';
import { formatCount, pluralize } from '../../lib/format';
import { activeFilterCount, type SearchState, type SortOption } from '../../lib/searchParams';
import type { FilterGroup } from './api/toFilterGroups';
@@ -62,6 +64,18 @@ export function SearchView(props: SearchViewProps) {
const listRef = useRef(null);
const firstNewWine = useRef(null);
+ const headingRef = useRef(null);
+ const { search } = useLocation();
+ const previousSearch = useRef(search);
+
+ // Links on this page change the URL and are often gone afterwards: a removed filter,
+ // «Nullstill filtre», a suggestion when nothing matched. The route stays the same, so
+ // the layout does not move focus. The h1 takes it, and the live region reads the result.
+ useEffect(() => {
+ if (previousSearch.current === search) return;
+ previousSearch.current = search;
+ focusIfLost(headingRef.current);
+ }, [search]);
// The button can disappear after the last page, so keyboard and screen
// reader users continue from the first new wine instead of losing their place.
@@ -90,7 +104,9 @@ export function SearchView(props: SearchViewProps) {
return (
-
Utforsk viner
+
+ Utforsk viner
+
(null);
+ const removedIndex = useRef(null);
+
+ // The removed chip is gone, so focus moves to the one that took its place, or to the
+ // one before it. With no chips left, the search page moves focus to its h1.
+ useEffect(() => {
+ const index = removedIndex.current;
+ if (index === null) return;
+ removedIndex.current = null;
+ const links = listRef.current?.querySelectorAll('a');
+ if (!links?.length || !isFocusLost()) return;
+ links[Math.min(index, links.length - 1)].focus();
+ });
+
if (chips.length === 0) return null;
return (
-
- {chips.map(({ label, without }) => (
+
+ {chips.map(({ label, without }, index) => (
{
+ removedIndex.current = index;
+ }}
>
{label} ×
diff --git a/frontend/src/features/search/components/FilterPanel.tsx b/frontend/src/features/search/components/FilterPanel.tsx
index d222e50..6c033a2 100644
--- a/frontend/src/features/search/components/FilterPanel.tsx
+++ b/frontend/src/features/search/components/FilterPanel.tsx
@@ -83,7 +83,7 @@ function FilterGroup({ group, onToggle }: { group: Group; onToggle: (value: stri
return (
{legend}
-
+
{visible.map((option) => (
diff --git a/frontend/src/features/search/components/NoResults.tsx b/frontend/src/features/search/components/NoResults.tsx
index 4f179ba..35d3e72 100644
--- a/frontend/src/features/search/components/NoResults.tsx
+++ b/frontend/src/features/search/components/NoResults.tsx
@@ -39,7 +39,7 @@ export function NoResults({ state }: { state: SearchState }) {
kortere ord.
Eller start med et av disse:
-
+
{SUGGESTIONS.map(({ label, search }) => (
{label}
diff --git a/frontend/src/features/wine/WineView.tsx b/frontend/src/features/wine/WineView.tsx
index 7642ab9..c32f3ae 100644
--- a/frontend/src/features/wine/WineView.tsx
+++ b/frontend/src/features/wine/WineView.tsx
@@ -37,6 +37,8 @@ function backLink(state: unknown) {
export function WineView({ wine, loading, error, refetch, notFound }: WineViewProps) {
const location = useLocation();
const back = backLink(location.state);
+ // Saving a review fetches the wine again. Only the first load is shown and announced.
+ const firstLoad = loading && !wine;
return (
@@ -45,10 +47,10 @@ export function WineView({ wine, loading, error, refetch, notFound }: WineViewPr
- {loading ? 'Laster vin …' : ''}
+ {firstLoad ? 'Laster vin …' : ''}
- {loading &&
}
+ {firstLoad &&
}
{error && (
<>
@@ -143,7 +145,7 @@ function WineDetailsView({ wine }: { wine: WineDetails }) {
{wine.foods.length > 0 && (