diff --git a/README.md b/README.md index a82e338..c741aed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kork & Krone -**Last updated:** 23 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). @@ -131,7 +131,7 @@ This section describes what users can do. "Backend" means the API supports the f | 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 | Done | Done | 0.5–5 stars in half stars and an optional comment, stored in PostgreSQL. Hover the left half of a star for half a star, or use the arrow keys. The page updates at once without a reload. One review per student per wine | | Shared average and distribution | Done | Done | Student reviews count in the average together with X-Wines, also when sorting and filtering. The wine page shows how many gave each score | -| Wine lists: favourite, «Vil prøve» and «Har prøvd» | Done | Done | Stored per user and public, so they follow the user between browsers. Heart and bookmark on the wine cards, all three on the wine page, and each list on «Min side». The buttons change at once and go back with a message if saving fails. Visitors are sent to log in and back. «Har prøvd» takes a wine off «Vil prøve», and a saved review marks the wine as tried. A «Vil prøve» list from before login moves to the user once. See [API](docs/api.md#wine-lists) | +| Wine lists: favourite, «Vil prøve» and «Har prøvd» | Done | Done | Stored per user and public, so they follow the user between browsers. Heart and bookmark on the wine cards, all three on the wine page, and each list on «Min side». The buttons change at once and go back with a message if saving fails. Visitors are sent to log in and back. «Har prøvd» takes a wine off «Vil prøve», and a saved review marks the wine as tried. A tried wine can still go back on «Vil prøve», and is then on both, as explained behind «Slik virker listene» on the wine page. See [«Vil prøve» and «Har prøvd»](#vil-prøve-and-har-prøvd). A «Vil prøve» list from before login moves to the user once. See [API](docs/api.md#wine-lists) | | Top 4 favourites | Done | Done | Shown in its own frame on «Min side», with four numbered places. «Endre topp 4» chooses and orders them with buttons that work with the keyboard and a screen reader, without drag and drop | | «Min side» | Done | Done | `/mine` with the top 4, the lists and the reviews, a page for each list at `/mine/favoritter`, `/mine/vil-prove` and `/mine/har-provd`, and `/mine/dommer`, newest or oldest first. Behind login | | User accounts | Done | Done | Register, log in and log out at `/konto`. Errors are shown next to the field they are about, in Norwegian. Sessions in PostgreSQL with an `httpOnly` cookie | diff --git a/docs/api.md b/docs/api.md index d4556bc..ca63f8e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -238,7 +238,7 @@ The table `user_wine` has one row per user, list and wine: `id`, `user_id`, `win |---|---| | A wine is at most once on each list | `UNIQUE (user_id, list, wine_id)`. Adding it again changes nothing | | A wine can be on several lists, such as a favourite that is also tried | No rule against it | -| A tried wine can go back on «Vil prøve», and is then on both | A choice: the user may want to taste it again, for example another vintage. Only putting a wine on «Har prøvd» moves it, not the other way. Tested in `lists-api.db.test.ts` and `lib/wineLists.test.ts` | +| A tried wine can go back on «Vil prøve», and is then on both | A choice: the user may want to taste it again, for example another vintage. Only putting a wine on «Har prøvd» moves it, not the other way. Because this is not obvious, the wine page explains it behind the button «Slik virker listene» under the list buttons (`WineListButtons.tsx`). Tested in `lists-api.db.test.ts`, `lib/wineLists.test.ts`, `WineListButtons.test.tsx` and `e2e/lists.spec.ts` | | «Har prøvd» takes the wine off «Vil prøve» | `setWineInList` in `wine-lists.ts`, in the same transaction | | A saved review puts the wine on «Har prøvd» | `saveReview`, in the same transaction as the review. Deleting the review keeps the wine on «Har prøvd» | | The top 4 has at most four wines, each once, all favourites | `setTopFavourites` checks and gives a clear error. The database checks it too: `top_position BETWEEN 1 AND 4`, a unique index on `(user_id, top_position)`, and `CHECK (top_position IS NULL OR list = 'FAVOURITE')` | diff --git a/docs/manual-testing.md b/docs/manual-testing.md index e91200d..4d48631 100644 --- a/docs/manual-testing.md +++ b/docs/manual-testing.md @@ -98,6 +98,8 @@ Things that should fail: | Logged out: press the heart on a wine card | You are sent to `/konto`. After logging in, you come back to the same page | | Logged in: press the heart and the bookmark on a card | Both fill in at once. The same wine elsewhere on the page, and on the wine page, shows the same | | On the wine page: «Vil prøve», then «Har prøvd» | «Vil prøve» turns off at once | +| On the wine page: «Har prøvd», then «Vil prøve» | Both stay on. The wine is on `/mine/vil-prove` and on `/mine/har-provd` | +| On the wine page, logged in and out: press «Slik virker listene» | The note «"Har prøvd" tar vinen av "Vil prøve" …» opens under it, and closes on the next press. A screen reader says if the button is expanded or collapsed | | `/mine/vil-prove` | The wines with a bookmark, newest first. Logged out, the page sends you to `/konto` | | On `/mine/vil-prove`: press the bookmark on a wine | The card goes at once, «Fjernet fra listen …» is read, and focus moves to the heading «Vil prøve» | | The same user in a private window | The same lists: they are stored on the user, not in the browser | diff --git a/frontend/e2e/lists.spec.ts b/frontend/e2e/lists.spec.ts index 62f3bc1..62f86da 100644 --- a/frontend/e2e/lists.spec.ts +++ b/frontend/e2e/lists.spec.ts @@ -56,6 +56,27 @@ test.describe('Listene', () => { await expect(page.getByText(/Du har ikke lagret noen viner ennå/)).toBeVisible(); }); + test('en prøvd vin kan legges på «Vil prøve» igjen, og står da på begge', async ({ page }) => { + await fakeApi(page); + await page.goto('./vin/1'); + await loggedIn(page); + const wantToTry = page.getByRole('button', { name: 'Vil prøve', exact: true }); + const tried = page.getByRole('button', { name: 'Har prøvd', exact: true }); + const note = page.getByText(/Vil du smake den igjen, kan du legge den på «Vil prøve» på nytt/); + await expect(note).toBeHidden(); + await page.getByRole('button', { name: 'Slik virker listene' }).click(); + await expect(note).toBeVisible(); + + await tried.click(); + await expect(tried).toHaveAttribute('aria-pressed', 'true'); + await wantToTry.click(); + + await expect(wantToTry).toHaveAttribute('aria-pressed', 'true'); + await expect(tried).toHaveAttribute('aria-pressed', 'true'); + await page.goto('./mine/vil-prove'); + await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 1']); + }); + test('en besøkende logger inn og kommer tilbake til søket', async ({ page }) => { await fakeApi(page, { loggedIn: false }); await page.goto('./sok?q=rod'); diff --git a/frontend/src/components/ui/InfoIcon.tsx b/frontend/src/components/ui/InfoIcon.tsx new file mode 100644 index 0000000..39fe21d --- /dev/null +++ b/frontend/src/components/ui/InfoIcon.tsx @@ -0,0 +1,9 @@ +/** An «i» in a circle, on buttons that show more. Decorative: the button has its own text. */ +export function InfoIcon() { + return ( + + ); +} diff --git a/frontend/src/components/ui/index.ts b/frontend/src/components/ui/index.ts index 693ec0e..9ff4fff 100644 --- a/frontend/src/components/ui/index.ts +++ b/frontend/src/components/ui/index.ts @@ -6,6 +6,7 @@ export { StarIcon, Stars } from './Stars'; export { EmptyState } from './EmptyState'; export { ErrorNotice } from './ErrorNotice'; export { HeartIcon } from './HeartIcon'; +export { InfoIcon } from './InfoIcon'; export { SearchForm } from './SearchForm'; export { Skeleton } from './Skeleton'; export { WineCard } from './WineCard'; diff --git a/frontend/src/features/lists/components/WineListButtons.module.css b/frontend/src/features/lists/components/WineListButtons.module.css index 0a02eab..88a78ca 100644 --- a/frontend/src/features/lists/components/WineListButtons.module.css +++ b/frontend/src/features/lists/components/WineListButtons.module.css @@ -51,6 +51,40 @@ stroke: var(--color-surface); } +.infoToggle { + display: inline-flex; + align-items: center; + justify-self: start; + gap: var(--space-1); + min-height: var(--tap-target); + padding: 0; + border: 0; + background: none; + color: var(--color-link); + font: inherit; + font-size: var(--text-sm); + text-decoration: underline; + text-underline-offset: 0.2em; + cursor: pointer; +} + +.infoToggle svg { + width: 1.125rem; + height: 1.125rem; + fill: none; + stroke: currentColor; + stroke-width: 2; + stroke-linecap: round; +} + +.note { + max-width: 40rem; + padding: var(--space-3) var(--space-4); + border-radius: var(--radius-md); + background: var(--color-surface-muted); + font-size: var(--text-sm); +} + .hint { font-size: var(--text-sm); color: var(--color-text-muted); diff --git a/frontend/src/features/lists/components/WineListButtons.test.tsx b/frontend/src/features/lists/components/WineListButtons.test.tsx index a95601c..446712a 100644 --- a/frontend/src/features/lists/components/WineListButtons.test.tsx +++ b/frontend/src/features/lists/components/WineListButtons.test.tsx @@ -70,6 +70,37 @@ describe('WineListButtons', () => { expect(button('Har prøvd')).toHaveAttribute('aria-pressed', 'true'); }); + it('shows how the lists work behind a button, closed at first', async () => { + const { user } = renderButtons([]); + const toggle = await screen.findByRole('button', { name: 'Slik virker listene' }); + const note = screen.getByText(/Vil du smake den igjen/); + + expect(toggle).toHaveAttribute('aria-expanded', 'false'); + expect(note).not.toBeVisible(); + + await user.click(toggle); + expect(toggle).toHaveAttribute('aria-expanded', 'true'); + expect(note).toBeVisible(); + expect(note).toHaveTextContent( + '«Har prøvd» tar vinen av «Vil prøve». Vil du smake den igjen, kan du legge den på «Vil prøve» på nytt. Da står den på begge listene.', + ); + + await user.click(toggle); + expect(note).not.toBeVisible(); + }); + + it('keeps a tried wine on «Har prøvd» when it goes back on «Vil prøve»', async () => { + const { user } = renderButtons([setWineInList('WANT_TO_TRY', true, ['WANT_TO_TRY', 'TRIED'])], { + lists: ['TRIED'], + }); + await waitFor(() => expect(button('Har prøvd')).toHaveAttribute('aria-pressed', 'true')); + + await user.click(button('Vil prøve')); + + expect(button('Vil prøve')).toHaveAttribute('aria-pressed', 'true'); + expect(button('Har prøvd')).toHaveAttribute('aria-pressed', 'true'); + }); + it('can be used with the keyboard: Tab to a button, then Space or Enter', async () => { const { user } = renderButtons( [ diff --git a/frontend/src/features/lists/components/WineListButtons.tsx b/frontend/src/features/lists/components/WineListButtons.tsx index 28802a2..58998a4 100644 --- a/frontend/src/features/lists/components/WineListButtons.tsx +++ b/frontend/src/features/lists/components/WineListButtons.tsx @@ -1,3 +1,5 @@ +import { useId, useState } from 'react'; +import { InfoIcon } from '../../../components/ui/InfoIcon'; import type { WineListName } from '../../../lib/wineLists'; import { useAuth } from '../../auth/useAuth'; import { useWineList } from '../useWineList'; @@ -14,9 +16,16 @@ interface WineListButtonsProps { * The three list buttons on the wine page: «Favoritt», «Vil prøve» and «Har prøvd». * Each is a toggle button (aria-pressed) with a visible name, so screen readers say * «Favoritt, toggle button, pressed» and voice control can use the word on the button. + * + * A small «Slik virker listene» button under them shows how «Vil prøve» and «Har prøvd» work + * together, because that is not obvious from the buttons alone: «Har prøvd» takes the wine off + * «Vil prøve», but a tried wine can go back on «Vil prøve» (to taste it again), and is then on + * both lists. The note is hidden until asked for, to keep the page calm. See docs/api.md#rules. */ export function WineListButtons({ wineId }: WineListButtonsProps) { const { user, loading } = useAuth(); + const noteId = useId(); + const [showNote, setShowNote] = useState(false); return (
+ «Har prøvd» tar vinen av «Vil prøve». Vil du smake den igjen, kan du legge den på «Vil + prøve» på nytt. Da står den på begge listene. +
{!loading && !user && (Logg inn for å lagre vinen. Du kommer tilbake hit etterpå.
)}