diff --git a/docs/api.md b/docs/api.md index 9fa02fc..8bea25f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -335,9 +335,11 @@ Choices and why: Known limit: a rating can change while someone pages (a new review changes the shared rating). The wine then moves in the order, and the next page can miss it or have it again. The frontend leaves out a wine it already has when a page is added (`mergeWineConnection` in -`frontend/src/lib/apollo.ts`), so it is never shown twice, and a reload gives the right order. The list pages on «Min -side» do not use `sort` yet. When they do, add `sort` and `minRating` to `keyArgs` for -`User.wines` in `frontend/src/lib/apollo.ts`, so each order is kept apart in the cache. +`frontend/src/lib/apollo.ts`), so it is never shown twice, and a reload gives the right order. + +The list pages on «Min side» use `sort` (see [«Min side»](#min-side)). `keyArgs` for +`User.wines` in `frontend/src/lib/apollo.ts` is `['list', 'sort', 'minRating']`, so each order +of a list is kept apart in the cache. ### Tests @@ -373,12 +375,13 @@ The code is in `frontend/src/features/my/`. Every page is behind `RequireAuth`. | Address | What it shows | |---|---| | `/mine` | «Min side»: the username and «Medlem siden …», the top 4, the four newest wines on each list with «Se alle», and the four newest reviews. All in one request (`MyProfile`) | -| `/mine/favoritter`, `/mine/vil-prove`, `/mine/har-provd` | One whole list, newest first, 24 at a time with «Last inn flere». An unknown list shows «Fant ikke listen» | +| `/mine/favoritter`, `/mine/vil-prove`, `/mine/har-provd` | One whole list, 24 at a time with «Last inn flere». «Sorter etter»: «Sist lagt til» (the default), «Din dom», «Best vurdert» or «Navn A–Å», in the URL as `?sortering=din-dom`, `best-vurdert` or `navn`. An unknown list shows «Fant ikke listen» | | `/mine/dommer` | All the user's reviews, «Nyeste først» or «Eldste først» (`?sortering=eldste` in the URL), 10 at a time | | Part | What it does | |---|---| -| `useMyProfile` | The `MyProfile` query. The lists in it are stored by name (`User.wines` with `keyArgs: ['list']`), so they are the same ones the list pages show, and a button on a card updates both. While a list is fetched again, the page keeps what it had (`previousData`) | +| `useMyProfile` | The `MyProfile` query. The lists in it are stored by name (`User.wines` with `keyArgs: ['list', 'sort', 'minRating']`, without a sort), so they are the same ones the list pages show in the default order, and a button on a card updates both. While a list is fetched again, the page keeps what it had (`previousData`) | +| `listSort.ts` | The orders of the list pages, their labels and their values in `?sortering=`. A missing or unknown value is «Sist lagt til». `useMyWineList` leaves out `NEWEST`, the API's default, so that order shares the cache with «Min side». A change of order replaces the history entry, so the back button leaves the page, as on `/mine/dommer`. `updateListPages` changes every order of a list: a wine taken off goes from all of them, and a list a wine joined is fetched again in every order | | `TopFavourites` | The top 4 in its own frame: always four numbered places, «Ledig plass» for a free one, and «Endre topp 4» when the user has favourites | | `TopFavouritesEditor` | Choosing the top 4 with buttons only (no drag and drop): «Flytt opp», «Flytt ned», «Ta ut» and «Legg til», named with the wine («Flytt opp Origem Merlot»). Each change is read out in a live region, and focus stays on the button or moves to the nearest one when it is gone. Nothing is saved before «Lagre topp 4». The answer from `setTopFavourites` is the user, so «Min side» updates from it without a new request | | `topFavouritesDraft.ts` | The steps of the editor as pure functions, with at most four wines, the same limit as the API | diff --git a/docs/manual-testing.md b/docs/manual-testing.md index 4d48631..c211c5b 100644 --- a/docs/manual-testing.md +++ b/docs/manual-testing.md @@ -162,6 +162,12 @@ Log in as `demo` (see section 8), which has favourites, a top 4, both other list | Move a wine down, take one out, add another, «Lagre topp 4» | The new order in the frame, «Topp 4 er lagret.» is read, and focus is on «Endre topp 4». The same after a reload and in a private window | | Four wines chosen: «Legg til» on a fifth | Nothing happens, and the button is described by «Topp 4 er full …» | | Change something, then «Avbryt» | The top 4 as before | +| `/mine/vil-prove`: «Sorter etter» → «Navn A–Å», then reload | A to Z, `?sortering=navn` in the URL, and the same order after the reload | +| On a list page: change the order a few times, then the browser's back button | Back to «Min side», not to the previous order | +| On a list page: Tab to «Sorter etter», then the arrow keys (on a Mac they open the menu: choose with the arrow keys and Enter) | The order changes, focus stays on the select, and a screen reader reads «… viner, sortert etter …» when the list has loaded | +| After a change of order: «Last inn flere» | Focus moves to the first new wine. The screen reader reads nothing more | +| A list page sorted by «Din dom» | The wines you have reviewed, highest first, then the others | +| A wine on a list page sorted by name, then «Tilbake til listen» | The list, still sorted by name | | `/mine/dommer`: «Eldste først», then reload | The oldest first, `?sortering=eldste` in the URL, and the same order after the reload | | Edit an old review on its wine page, back to `/mine/dommer` | It keeps its place, with «Gitt … · endret …» | | `/mine/noe-annet` | «Fant ikke listen», with a link to «Min side» | diff --git a/frontend/e2e/lists.spec.ts b/frontend/e2e/lists.spec.ts index 62f86da..b07b5a6 100644 --- a/frontend/e2e/lists.spec.ts +++ b/frontend/e2e/lists.spec.ts @@ -1,6 +1,7 @@ import { expect, test, type Page } from '@playwright/test'; import { expectNoAxeViolations } from './support/axe'; import { fakeApi, loggedIn } from './support/fakeApi'; +import { skipWhereArrowKeysOpenSelect } from './support/select'; /* * E2E for the wine lists: the buttons on the wine cards and the wine page, the list pages, @@ -112,6 +113,56 @@ test.describe('Listene', () => { await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 1', 'Rødvin 2']); }); + /** Three wines on «Vil prøve», added 1, 2, 3, and the list page opened from «Min side». */ + async function openThreeWantToTry(page: Page) { + await fakeApi(page); + await page.goto('./sok'); + await loggedIn(page); + for (const id of ['1', '2', '3']) { + const bookmark = page.getByRole('button', { name: `Vil prøve Rødvin ${id}` }); + await bookmark.click(); + await expect(bookmark).toHaveAttribute('aria-pressed', 'true'); + } + await page.goto('./mine'); + await page.getByRole('link', { name: /Se alle 3 viner du vil prøve/ }).click(); + await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 3', 'Rødvin 2', 'Rødvin 1']); + return page.getByRole('combobox', { name: 'Sorter etter' }); + } + + test('sorteringen står i URL-en, beholdes ved ny lasting, og tilbake forlater siden', async ({ + page, + }) => { + const sort = await openThreeWantToTry(page); + + await sort.selectOption({ label: 'Best vurdert' }); + await expect(page).toHaveURL(/\/mine\/vil-prove\?sortering=best-vurdert$/); + await sort.selectOption({ label: 'Navn A–Å' }); + await expect(page).toHaveURL(/\/mine\/vil-prove\?sortering=navn$/); + await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 1', 'Rødvin 2', 'Rødvin 3']); + await expectNoAxeViolations(page); + + await page.reload(); + await expect(sort).toHaveValue('NAME'); + await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 1', 'Rødvin 2', 'Rødvin 3']); + + // Each change replaced the address, so one step back is «Min side». + await page.goBack(); + await expect(page).toHaveURL(/\/mine$/); + }); + + test('piltastene bytter sortering uten at et trykk går tapt', async ({ page, isMobile }) => { + skipWhereArrowKeysOpenSelect(isMobile); + const sort = await openThreeWantToTry(page); + + // Three presses at once: each must start where the one before ended. + await sort.focus(); + for (let step = 0; step < 3; step += 1) await page.keyboard.press('ArrowDown'); + + await expect(page).toHaveURL(/\/mine\/vil-prove\?sortering=navn$/); + await expect(myList(page).getByRole('link')).toHaveText(['Rødvin 1', 'Rødvin 2', 'Rødvin 3']); + await expect(sort).toBeFocused(); + }); + test('har ingen axe-brudd på en tom «Min side» og en tom liste', async ({ page }) => { await fakeApi(page); await page.goto('./mine'); diff --git a/frontend/e2e/profile.spec.ts b/frontend/e2e/profile.spec.ts index fda0ab1..5655c88 100644 --- a/frontend/e2e/profile.spec.ts +++ b/frontend/e2e/profile.spec.ts @@ -1,6 +1,7 @@ import { expect, test, type Page } from '@playwright/test'; import { expectNoAxeViolations } from './support/axe'; import { fakeApi, loggedIn } from './support/fakeApi'; +import { skipWhereArrowKeysOpenSelect } from './support/select'; /* * E2E for «Min side», the whole way a user goes: log in, add favourites, choose the top 4 with @@ -8,6 +9,8 @@ import { fakeApi, loggedIn } from './support/fakeApi'; * support/fakeApi.ts, which remembers the lists and the top 4 between page loads. */ +const myReviews = (page: Page) => page.getByRole('list', { name: 'Mine dommer' }).getByRole('link'); + const topPlaces = (page: Page) => page.getByRole('list', { name: 'Topp 4 favoritter' }).getByRole('link'); @@ -99,4 +102,49 @@ test.describe('Min side', () => { await expect(topPlaces(page)).toHaveText(['Rødvin 3']); }); + + /** «Mine dommer» with two reviews, opened after «Min side», so there is a page to go back to. */ + async function openMyReviews(page: Page) { + await fakeApi(page); + await page.goto('./mine'); + await page.goto('./mine/dommer'); + await expect(myReviews(page)).toHaveText(['Rødvin 2', 'Rødvin 1']); + return page.getByRole('combobox', { name: 'Rekkefølge' }); + } + + test('rekkefølgen på «Mine dommer» står i URL-en, beholdes ved ny lasting, og tilbake forlater siden', async ({ + page, + }) => { + const order = await openMyReviews(page); + + await order.selectOption({ label: 'Eldste først' }); + await expect(page).toHaveURL(/\/mine\/dommer\?sortering=eldste$/); + await expect(myReviews(page)).toHaveText(['Rødvin 1', 'Rødvin 2']); + + await page.reload(); + await expect(order).toHaveValue('OLDEST'); + await expect(myReviews(page)).toHaveText(['Rødvin 1', 'Rødvin 2']); + await page.goBack(); + await expect(page).toHaveURL(/\/mine$/); + }); + + test('piltastene bytter rekkefølgen på «Mine dommer» uten at et trykk går tapt', async ({ + page, + isMobile, + }) => { + skipWhereArrowKeysOpenSelect(isMobile); + const order = await openMyReviews(page); + + // Down and up again at once: the second press must start from «Eldste først». + await order.focus(); + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('ArrowUp'); + await expect(page).toHaveURL(/\/mine\/dommer$/); + await expect(order).toHaveValue('NEWEST'); + + await page.keyboard.press('ArrowDown'); + await expect(page).toHaveURL(/\/mine\/dommer\?sortering=eldste$/); + await expect(myReviews(page)).toHaveText(['Rødvin 1', 'Rødvin 2']); + await expect(order).toBeFocused(); + }); }); diff --git a/frontend/e2e/support/fakeApi.ts b/frontend/e2e/support/fakeApi.ts index cf579c3..90579d2 100644 --- a/frontend/e2e/support/fakeApi.ts +++ b/frontend/e2e/support/fakeApi.ts @@ -40,13 +40,26 @@ const details = { vintages: [], }; -const connection = (nodes: object[]) => ({ - __typename: 'WineConnection', +const connection = (nodes: object[], type = 'Wine') => ({ + __typename: `${type}Connection`, totalCount: nodes.length, - edges: nodes.map((node, index) => ({ __typename: 'WineEdge', cursor: String(index), node })), + edges: nodes.map((node, index) => ({ __typename: `${type}Edge`, cursor: String(index), node })), pageInfo: { __typename: 'PageInfo', hasNextPage: false, endCursor: null }, }); +const myReview = (wineId: string, givenAt: string) => ({ + __typename: 'Review', + id: `r${wineId}`, + rating: 4, + comment: null, + createdAt: givenAt, + updatedAt: givenAt, + wine: { __typename: 'Wine', id: wineId, name: `Rødvin ${wineId}`, type: 'Red' }, +}); + +/** Kari's reviews on «Mine dommer», newest first. */ +const MY_REVIEWS = [myReview('2', '2026-11-20T12:00:00Z'), myReview('1', '2026-11-18T12:00:00Z')]; + const emptyReviews = { __typename: 'ReviewConnection', totalCount: 0, @@ -115,7 +128,11 @@ export async function fakeApi(page: Page, { loggedIn = true } = {}) { data: { setTopFavourites: { ...KARI, topFavourites: top.map(wine) } }, }; }, - MyReviews: () => ({ data: { me: me && { ...me, reviews: emptyReviews } } }), + // Two fixed reviews for «Mine dommer», newest or oldest first. + MyReviews: ({ order }: { order: 'NEWEST' | 'OLDEST' }) => { + const reviews = order === 'OLDEST' ? [...MY_REVIEWS].reverse() : MY_REVIEWS; + return { data: { me: me && { ...me, reviews: connection(reviews, 'Review') } } }; + }, SearchWines: () => ({ data: { wines: connection(ids.map(wine)) } }), FilterOptions: () => ({ data: { filterOptions } }), Wine: ({ id }: { id: string }) => ({ data: { wine: { ...wine(id), ...details } } }), @@ -152,9 +169,12 @@ export async function fakeApi(page: Page, { loggedIn = true } = {}) { data: { setWineInList: { __typename: 'Wine', id: wineId, myLists: listsOf(wineId) } }, }; }, - MyWineList: ({ list }: { list: ListName }) => ({ - data: { me: me && { ...me, wines: connection(newestOn(list).map(wine)) } }, - }), + // Of the orders, only the name is faked: the newest first, unless `sort: NAME`. + MyWineList: ({ list, sort }: { list: ListName; sort?: string }) => { + const wines = newestOn(list).map(wine); + if (sort === 'NAME') wines.sort((a, b) => a.name.localeCompare(b.name, 'nb')); + return { data: { me: me && { ...me, wines: connection(wines) } } }; + }, MyProfile: ({ preview }: { preview: number }) => { const page = (list: ListName) => { const all = newestOn(list); diff --git a/frontend/e2e/support/select.ts b/frontend/e2e/support/select.ts new file mode 100644 index 0000000..6d410ad --- /dev/null +++ b/frontend/e2e/support/select.ts @@ -0,0 +1,15 @@ +import { test } from '@playwright/test'; + +/** + * Skips the rest of a test that changes a native select with the arrow keys, where that does + * not work. Chrome on a Mac desktop opens the select's menu on an arrow key instead of changing + * the value. On Windows and Linux, and in the mobile emulation, the value changes at once. + * Call it at the start of the test. Choose the value with `selectOption` in tests that should + * run everywhere. + */ +export function skipWhereArrowKeysOpenSelect(isMobile: boolean) { + test.skip( + process.platform === 'darwin' && !isMobile, + 'On macOS, the arrow keys open a native select instead of changing its value', + ); +} diff --git a/frontend/src/features/lists/api/listCache.test.ts b/frontend/src/features/lists/api/listCache.test.ts index 68ec28b..b27d5f1 100644 --- a/frontend/src/features/lists/api/listCache.test.ts +++ b/frontend/src/features/lists/api/listCache.test.ts @@ -5,10 +5,10 @@ import type { WineListName } from '../../../lib/wineLists'; import { updateListPages } from './listCache'; const LIST = gql` - query List($list: WineList!) { + query List($list: WineList!, $sort: WineListSort) { me { id - wines(list: $list) { + wines(list: $list, sort: $sort) { totalCount edges { cursor @@ -34,26 +34,34 @@ const TOP = gql` const wineRef = (id: string) => ({ __typename: 'Wine', id }); +/** A list in the cache as the API sent it, in one order (none: the newest first). */ +function writeList( + cache: ReturnType, + list: string, + ids: string[], + sort?: string, +) { + cache.writeQuery({ + query: LIST, + variables: { list, sort }, + data: { + me: { + __typename: 'User', + id: '1', + wines: { + __typename: 'WineConnection', + totalCount: ids.length, + edges: ids.map((id) => ({ __typename: 'WineEdge', cursor: id, node: wineRef(id) })), + }, + }, + }, + }); +} + /** A cache with the user's lists as the API last sent them. */ function cacheWith(lists: Partial>, top: string[] = []) { const cache = createApolloCache(); - for (const [list, ids] of Object.entries(lists)) { - cache.writeQuery({ - query: LIST, - variables: { list }, - data: { - me: { - __typename: 'User', - id: '1', - wines: { - __typename: 'WineConnection', - totalCount: ids.length, - edges: ids.map((id) => ({ __typename: 'WineEdge', cursor: id, node: wineRef(id) })), - }, - }, - }, - }); - } + for (const [list, ids] of Object.entries(lists)) writeList(cache, list, ids); cache.writeQuery({ query: TOP, data: { me: { __typename: 'User', id: '1', topFavourites: top.map(wineRef) } }, @@ -64,8 +72,8 @@ function cacheWith(lists: Partial>, top: string[] type ListData = { me: { wines: { totalCount: number; edges: { node: { id: string } }[] } } }; /** The ids on a cached list and its count, or null when the list is no longer in the cache. */ -function read(cache: ReturnType, list: WineListName) { - const data = cache.readQuery({ query: LIST, variables: { list } }); +function read(cache: ReturnType, list: WineListName, sort?: string) { + const data = cache.readQuery({ query: LIST, variables: { list, sort } }); if (!data) return null; return { ids: data.me.wines.edges.map((edge) => edge.node.id), @@ -102,6 +110,26 @@ describe('updateListPages', () => { expect(read(cache, 'FAVOURITE')).toEqual({ ids: ['8'], totalCount: 1 }); }); + it('changes every order of a list, as each is stored apart', () => { + const cache = cacheWith({ WANT_TO_TRY: ['7', '8'], FAVOURITE: ['8'] }); + writeList(cache, 'WANT_TO_TRY', ['8', '7'], 'NAME'); + writeList(cache, 'FAVOURITE', ['8'], 'COMMUNITY_RATING'); + + // Taken off «Vil prøve»: gone from both orders. Added to the favourites: where it belongs in + // an order is up to the API, so every order of the list is fetched again. + updateListPages(cache, { + userId: '1', + wineId: '7', + before: ['WANT_TO_TRY'], + after: ['FAVOURITE'], + }); + + expect(read(cache, 'WANT_TO_TRY')).toEqual({ ids: ['8'], totalCount: 1 }); + expect(read(cache, 'WANT_TO_TRY', 'NAME')).toEqual({ ids: ['8'], totalCount: 1 }); + expect(read(cache, 'FAVOURITE')).toBeNull(); + expect(read(cache, 'FAVOURITE', 'COMMUNITY_RATING')).toBeNull(); + }); + it('takes a wine out of the top 4 when it is no longer a favourite, and keeps the order', () => { const cache = cacheWith({ FAVOURITE: ['7', '8', '9'] }, ['9', '7', '8']); diff --git a/frontend/src/features/lists/api/listCache.ts b/frontend/src/features/lists/api/listCache.ts index 90d7203..26db626 100644 --- a/frontend/src/features/lists/api/listCache.ts +++ b/frontend/src/features/lists/api/listCache.ts @@ -2,7 +2,10 @@ import type { ApolloCache, Reference } from '@apollo/client'; import type { WineConnection } from '../../../lib/apollo'; import type { WineListName } from '../../../lib/wineLists'; -/** The list a cached `wines` field belongs to, from its key in the cache: wines:{"list":"TRIED"}. */ +/** + * The list a cached `wines` field belongs to, from its key in the cache: wines:{"list":"TRIED"}, + * or wines:{"list":"TRIED","sort":"NAME"} for another order of the same list. + */ function listOf(storeFieldName: string): string | null { return /"list":"([A-Z_]+)"/.exec(storeFieldName)?.[1] ?? null; } @@ -11,10 +14,13 @@ function listOf(storeFieldName: string): string | null { * Keeps the user's list pages in the cache in step with a change of one wine's lists, so a page * that shows them (such as «Min side» and the list pages) changes at once without a new request. * + * Each order of a list is stored apart, and every order is changed: + * * - A list the wine left: the wine is taken out, and the count goes down by one. Also from the * top 4 when it is no longer a favourite. - * - A list the wine joined: the new wine belongs at the top, with a cursor only the API can make. - * The cached list is removed instead, so it is fetched again the next time it is shown. + * - A list the wine joined: where the new wine belongs depends on the order, and needs a cursor + * only the API can make. The cached list is removed instead, so it is fetched again the next + * time it is shown. * * Runs in the mutation's `update`, also for the optimistic answer, so a failed change is undone * here too. diff --git a/frontend/src/features/lists/api/myWineListQuery.ts b/frontend/src/features/lists/api/myWineListQuery.ts index 58b79ff..1b741ab 100644 --- a/frontend/src/features/lists/api/myWineListQuery.ts +++ b/frontend/src/features/lists/api/myWineListQuery.ts @@ -2,15 +2,19 @@ import { gql } from '@apollo/client'; import type { ApiWine } from '../../../lib/mapWine'; import { WINE_CARD_FIELDS } from './wineCardFields'; +/** The same values as the GraphQL enum WineListSort. See docs/api.md. */ +export type WineListSort = 'NEWEST' | 'OWN_RATING' | 'COMMUNITY_RATING' | 'NAME'; + /** - * One page of one of the logged-in user's lists, newest first. The wine fields are the same as - * on the wine cards, with `myLists`, so the buttons on the cards know their state. + * One page of one of the logged-in user's lists, newest first unless `sort` says otherwise. The + * wine fields are the same as on the wine cards, with `myLists`, so the buttons on the cards + * know their state. */ export const MY_WINE_LIST_QUERY = gql` - query MyWineList($list: WineList!, $first: Int, $after: String) { + query MyWineList($list: WineList!, $sort: WineListSort, $first: Int, $after: String) { me { id - wines(list: $list, first: $first, after: $after) { + wines(list: $list, sort: $sort, first: $first, after: $after) { totalCount edges { cursor diff --git a/frontend/src/features/lists/api/useMyWineList.ts b/frontend/src/features/lists/api/useMyWineList.ts index 96bad02..4d6e696 100644 --- a/frontend/src/features/lists/api/useMyWineList.ts +++ b/frontend/src/features/lists/api/useMyWineList.ts @@ -4,7 +4,7 @@ import { useQuery } from '@apollo/client/react'; import { toWineSummary } from '../../../lib/mapWine'; import type { WineSummary } from '../../../lib/types'; import type { WineListName } from '../../../lib/wineLists'; -import { MY_WINE_LIST_QUERY, type MyWineListData } from './myWineListQuery'; +import { MY_WINE_LIST_QUERY, type MyWineListData, type WineListSort } from './myWineListQuery'; /** How many wines one page of a list has: the same as a page of search results. */ export const LIST_PAGE_SIZE = 24; @@ -24,15 +24,24 @@ export interface MyWineListResult { } /** - * The logged-in user's wines on one list, newest first, one page at a time. The pages are kept + * The variables for the first page of a list. NEWEST is the API's default and is left out, so + * the newest first is stored in the same place in the cache as the lists on «Min side», which + * ask without a sort. Each other order has its own place (keyArgs for User.wines in lib/apollo.ts). + */ +function listVariables(list: WineListName, sort: WineListSort) { + return { list, ...(sort !== 'NEWEST' && { sort }), first: LIST_PAGE_SIZE }; +} + +/** + * The logged-in user's wines on one list in one order, one page at a time. The pages are kept * together in the cache (User.wines in lib/apollo.ts), and a change made with the list buttons * updates them at once (updateListPages). */ -export function useMyWineList(list: WineListName): MyWineListResult { +export function useMyWineList(list: WineListName, sort: WineListSort = 'NEWEST'): MyWineListResult { const { data, error, networkStatus, fetchMore, refetch } = useQuery( MY_WINE_LIST_QUERY, { - variables: { list, first: LIST_PAGE_SIZE }, + variables: listVariables(list, sort), // «Min side» keeps the first four wines of each list in the same place in the cache. Show // those at once, but always ask for a whole page too, so a list of six shows all six. fetchPolicy: 'cache-and-network', diff --git a/frontend/src/features/my/MyListPage.test.tsx b/frontend/src/features/my/MyListPage.test.tsx index 42035af..e864da4 100644 --- a/frontend/src/features/my/MyListPage.test.tsx +++ b/frontend/src/features/my/MyListPage.test.tsx @@ -3,16 +3,17 @@ import { render, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { MockLink } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing/react'; -import { MemoryRouter, Route, Routes } from 'react-router'; +import { MemoryRouter, Route, Routes, useNavigate } from 'react-router'; import { axe } from 'vitest-axe'; import { createApolloCache } from '../../lib/apollo'; import { meMock, TEST_USER } from '../../test/authMocks'; import { AuthReady } from '../../test/AuthReady'; import { HELD_BACK } from '../../test/heldBack'; +import { LocationProbe } from '../../test/LocationProbe'; import { AuthProvider } from '../auth/AuthProvider'; import { SET_WINE_IN_LIST_MUTATION } from '../lists/api/listQueries'; import { LIST_PAGE_SIZE } from '../lists/api/useMyWineList'; -import { MY_WINE_LIST_QUERY } from '../lists/api/myWineListQuery'; +import { MY_WINE_LIST_QUERY, type WineListSort } from '../lists/api/myWineListQuery'; import MyListPage from './MyListPage'; const apiWine = (id: string, name: string) => ({ @@ -31,19 +32,28 @@ const apiWine = (id: string, name: string) => ({ type Saved = { id: string; name: string }; -/** One page of «Vil prøve», newest first, as the API sends it. */ +/** + * One page of «Vil prøve» in one order, as the API sends it. The newest first is asked for + * without a sort, so it shares the cache with «Min side». + */ function page( saved: Saved[], { totalCount = saved.length, + sort = 'NEWEST', after, next, - }: { totalCount?: number; after?: string; next?: string } = {}, + }: { totalCount?: number; sort?: WineListSort; after?: string; next?: string } = {}, ): MockLink.MockedResponse { return { request: { query: MY_WINE_LIST_QUERY, - variables: { list: 'WANT_TO_TRY', first: LIST_PAGE_SIZE, ...(after ? { after } : {}) }, + variables: { + list: 'WANT_TO_TRY', + ...(sort !== 'NEWEST' && { sort }), + first: LIST_PAGE_SIZE, + ...(after ? { after } : {}), + }, }, result: { data: { @@ -70,6 +80,17 @@ function page( }; } +/** The browser's back button. */ +function BackButton() { + const navigate = useNavigate(); + return ( + + ); +} + +/** The list page, opened from «Min side», so there is a page to go back to. */ function renderPage( mocks: MockLink.MockedResponse[], path = '/mine/vil-prove', @@ -78,12 +99,15 @@ function renderPage( const user = userEvent.setup(); const result = render( - + + Min side} /> } /> + + , @@ -92,6 +116,12 @@ function renderPage( } const list = () => screen.findByRole('list', { name: 'Viner du vil prøve' }); +const sortField = () => screen.getByRole('combobox', { name: 'Sorter etter' }); +const location = () => screen.getByTestId('location'); +const two: Saved[] = [ + { id: '1', name: 'Amarone' }, + { id: '2', name: 'Barolo' }, +]; const names = (element: HTMLElement) => within(element) .getAllByRole('link') @@ -103,6 +133,8 @@ describe('MyListPage', () => { expect(await screen.findByText(/Du har ikke lagret noen viner ennå/)).toBeInTheDocument(); expect(screen.getByRole('link', { name: 'Utforsk viner' })).toHaveAttribute('href', '/sok'); expect(document.title).toBe('Vil prøve – Kork & Krone'); + // Nothing to sort. + expect(screen.queryByRole('combobox')).not.toBeInTheDocument(); }); it('shows the whole list from the API, newest first, under a heading with its name', async () => { @@ -116,12 +148,133 @@ describe('MyListPage', () => { expect(names(await list())).toEqual(['Chianti', 'Origem Merlot']); expect(screen.getByRole('heading', { level: 1, name: 'Vil prøve' })).toBeInTheDocument(); expect(screen.getByText('2 viner')).toBeInTheDocument(); + expect(sortField()).toHaveDisplayValue('Sist lagt til'); + // Nothing to say on the first load: the page itself shows the list. + expect(screen.getByRole('status')).toBeEmptyDOMElement(); expect(screen.getByRole('link', { name: 'Tilbake til Min side' })).toHaveAttribute( 'href', '/mine', ); }); + describe('sorting', () => { + it('offers the four orders, newest added first', async () => { + renderPage([page(two)]); + await list(); + + expect( + within(sortField()) + .getAllByRole('option') + .map((option) => option.textContent), + ).toEqual(['Sist lagt til', 'Din dom', 'Best vurdert', 'Navn A–Å']); + expect(location()).toHaveTextContent(/^\/mine\/vil-prove$/); + }); + + it('opens in the order from the URL, as after a reload', async () => { + renderPage([page([...two].reverse(), { sort: 'NAME' })], '/mine/vil-prove?sortering=navn'); + + expect(names(await list())).toEqual(['Barolo', 'Amarone']); + expect(sortField()).toHaveDisplayValue('Navn A–Å'); + }); + + it('shows the newest first for an order it does not know', async () => { + renderPage([page(two)], '/mine/vil-prove?sortering=tull'); + + expect(names(await list())).toEqual(['Amarone', 'Barolo']); + expect(sortField()).toHaveDisplayValue('Sist lagt til'); + }); + + it('fetches the list in the chosen order, keeps the order in the URL and focus on the select', async () => { + const { user } = renderPage([ + page(two), + page([...two].reverse(), { sort: 'COMMUNITY_RATING' }), + ]); + await list(); + + await user.selectOptions(sortField(), 'Best vurdert'); + + await waitFor(() => expect(names(screen.getByRole('list'))).toEqual(['Barolo', 'Amarone'])); + expect(location()).toHaveTextContent('/mine/vil-prove?sortering=best-vurdert'); + expect(sortField()).toHaveFocus(); + expect(screen.getByRole('status')).toHaveTextContent('2 viner, best vurdert først'); + }); + + it('is reached with the Tab key, right after the back link', async () => { + const { user } = renderPage([page(two)]); + await list(); + + await user.tab(); + expect(screen.getByRole('link', { name: 'Tilbake til Min side' })).toHaveFocus(); + await user.tab(); + expect(sortField()).toHaveFocus(); + }); + + it('replaces the history entry, so the back button leaves the page after any number of changes', async () => { + const { user } = renderPage([ + page(two), + page(two, { sort: 'OWN_RATING' }), + page([...two].reverse(), { sort: 'NAME' }), + ]); + await list(); + + await user.selectOptions(sortField(), 'Din dom'); + await user.selectOptions(sortField(), 'Navn A–Å'); + await waitFor(() => expect(names(screen.getByRole('list'))).toEqual(['Barolo', 'Amarone'])); + + await user.click(screen.getByRole('button', { name: 'Nettleserens tilbakeknapp' })); + expect(location()).toHaveTextContent(/^\/mine$/); + }); + + it('goes back to the newest first, without a value in the URL, from the cache', async () => { + // Only one answer for the newest first: the second time, the cached list is shown at once. + const { user } = renderPage([ + page(two), + page([...two].reverse(), { sort: 'NAME' }), + { ...page(two), delay: HELD_BACK }, + ]); + await list(); + await user.selectOptions(sortField(), 'Navn A–Å'); + await waitFor(() => expect(names(screen.getByRole('list'))).toEqual(['Barolo', 'Amarone'])); + + await user.selectOptions(sortField(), 'Sist lagt til'); + + // The network answer is held back, so the list can only come from the cache. + await waitFor(() => expect(names(screen.getByRole('list'))).toEqual(['Amarone', 'Barolo'])); + expect(location()).toHaveTextContent(/^\/mine\/vil-prove$/); + }); + + it('loads more in the chosen order, and only speaks after the change of order', async () => { + const { user } = renderPage([ + page(two), + page([two[1]], { sort: 'NAME', totalCount: 2, next: 'n1' }), + page([two[0]], { sort: 'NAME', totalCount: 2, after: 'n1' }), + ]); + await list(); + + await user.selectOptions(sortField(), 'Navn A–Å'); + await waitFor(() => + expect(screen.getByRole('status')).toHaveTextContent( + 'Viser 1 av 2 viner, sortert etter navn', + ), + ); + await user.click(screen.getByRole('button', { name: 'Last inn flere' })); + + await waitFor(() => expect(screen.getByRole('link', { name: 'Amarone' })).toHaveFocus()); + expect(names(screen.getByRole('list'))).toEqual(['Barolo', 'Amarone']); + // Focus on the first new wine says enough: the live region is quiet. + expect(screen.getByRole('status')).toBeEmptyDOMElement(); + }); + + it('has no axe violations with an order chosen', async () => { + const { container } = renderPage( + [page(two, { sort: 'OWN_RATING' })], + '/mine/vil-prove?sortering=din-dom', + ); + await list(); + expect(await axe(container)).toHaveNoViolations(); + }); + }); + it('takes a wine off the list at once when its bookmark is clicked', async () => { const { user } = renderPage([ page([{ id: '100062', name: 'Origem Merlot' }]), diff --git a/frontend/src/features/my/MyListPage.tsx b/frontend/src/features/my/MyListPage.tsx index 091d614..976eabb 100644 --- a/frontend/src/features/my/MyListPage.tsx +++ b/frontend/src/features/my/MyListPage.tsx @@ -1,19 +1,49 @@ -import { Link, useParams } from 'react-router'; +import { useState } from 'react'; +import { Link, useParams, useSearchParams } from 'react-router'; import { EmptyState } from '../../components/ui/EmptyState'; import { useDocumentTitle } from '../../hooks/useDocumentTitle'; +import type { WineListSort } from '../lists/api/myWineListQuery'; import { useMyWineList } from '../lists/api/useMyWineList'; +import { paramsForSort, sortFromParams } from './listSort'; import { listBySlug, type MyListInfo } from './myLists'; import { MyListView } from './MyListView'; -/** Route component for `/mine/:list`, behind RequireAuth: one whole list, a page at a time. */ +/** + * Route component for `/mine/:list`, behind RequireAuth: one whole list, a page at a time. The + * order lives in the URL (`?sortering=navn`), like on `/mine/dommer`, so it survives a reload. + */ export default function MyListPage() { const info = listBySlug(useParams().list); - return info ? : ; + // The key gives another list its own state, read from its own URL. + return info ? : ; } function KnownList({ info }: { info: MyListInfo }) { useDocumentTitle(info.title); - return ; + const [params, setParams] = useSearchParams(); + /* + * The order is kept in state, not only in the URL. React Router changes the URL in a + * transition, a moment later. Until then React puts a select back to the value it was given, + * so a second arrow key press would start from the old order and be lost. The URL is read when + * the page opens (after a reload, or from a link) and written on every change. Nothing else + * changes `?sortering=` while the page is open, so the two cannot differ for long. + */ + const [sort, setSort] = useState(() => sortFromParams(params)); + + function changeSort(next: WineListSort) { + setSort(next); + // Replace, not push: the back button leaves the page instead of stepping through the orders. + setParams(paramsForSort(next), { replace: true }); + } + + return ( + + ); } function UnknownList() { diff --git a/frontend/src/features/my/MyListView.module.css b/frontend/src/features/my/MyListView.module.css index 3004cd7..5c16498 100644 --- a/frontend/src/features/my/MyListView.module.css +++ b/frontend/src/features/my/MyListView.module.css @@ -11,6 +11,23 @@ min-height: var(--tap-target); } +/* The same as the order on «Mine dommer». */ +.sort { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-2); +} + +.sort select { + min-height: var(--tap-target); + padding: 0 var(--space-2); + border: 1px solid var(--color-text-muted); + border-radius: var(--radius-sm); + background: var(--color-surface); + color: var(--color-text); +} + .count, .empty { color: var(--color-text-muted); diff --git a/frontend/src/features/my/MyListView.tsx b/frontend/src/features/my/MyListView.tsx index 89a2f7c..2289381 100644 --- a/frontend/src/features/my/MyListView.tsx +++ b/frontend/src/features/my/MyListView.tsx @@ -1,25 +1,61 @@ -import { useEffect, useRef } from 'react'; +import { useEffect, useId, 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 { formatCount, pluralize } from '../../lib/format'; import { buildSearchUrl } from '../../lib/searchParams'; +import type { WineListSort } from '../lists/api/myWineListQuery'; import type { MyWineListResult } from '../lists/api/useMyWineList'; +import { LIST_SORTS, sortOption } from './listSort'; import type { MyListInfo } from './myLists'; import { useRemovalMessage } from './useRemovalMessage'; import styles from './MyListView.module.css'; interface MyListViewProps { info: MyListInfo; + sort: WineListSort; + onChangeSort: (sort: WineListSort) => void; result: MyWineListResult; } -/** Presentation of one whole list of the user's, newest first, with «Last inn flere». */ -export function MyListView({ info, result }: MyListViewProps) { +/** «Viser 3 av 7 viner» while more can be loaded, otherwise «7 viner». */ +function countText(shown: number, total: number) { + return shown < total + ? `Viser ${formatCount(shown)} av ${pluralize(total, 'vin', 'viner')}` + : pluralize(total, 'vin', 'viner'); +} + +/** + * The text in the live region, which screen readers read when it changes. A removed wine is said + * first. After the user chose another order, it says how many and in what order once the list + * has loaded. Not after the first load or «Last inn flere», where the page and focus say enough. + */ +function describeStatus( + { wines, totalCount, loading, loadingMore }: MyWineListResult, + sort: WineListSort, + removal: string, + orderChosen: boolean, +) { + if (loading) return 'Laster viner …'; + if (loadingMore) return 'Laster flere viner …'; + if (removal || !orderChosen || !totalCount) return removal; + return `${countText(wines.length, totalCount)}, ${sortOption(sort).spoken}`; +} + +/** Presentation of one whole list of the user's, in the chosen order, with «Last inn flere». */ +export function MyListView({ info, sort, onChangeSort, result }: MyListViewProps) { const { wines, totalCount, loading, loadingMore, hasNextPage, error, loadMoreError } = result; const headingRef = useRef(null); const message = useRemovalMessage(totalCount, headingRef); + const sortId = useId(); + // Whether the last thing the user did was to choose an order, for the live region. + const [orderChosen, setOrderChosen] = useState(false); + + function changeSort(next: WineListSort) { + setOrderChosen(true); + onChangeSort(next); + } // «Last inn flere» can disappear after the last page, so focus moves to the first new wine, // where the user wants to go on reading. The same as on the search page. @@ -33,6 +69,7 @@ export function MyListView({ info, result }: MyListViewProps) { }, [loadingMore, wines.length]); function loadMore() { + setOrderChosen(false); firstNewWine.current = wines.length; void result.loadMore(); } @@ -46,9 +83,27 @@ export function MyListView({ info, result }: MyListViewProps) {

{info.title}

- {loading ? 'Laster viner …' : loadingMore ? 'Laster flere viner …' : message} + {describeStatus(result, sort, message, orderChosen)}

+ {/* Also while a new order loads, so the select keeps focus. Not for an empty list. */} + {totalCount !== 0 && ( +

+ + +

+ )} + {loading && } {error && !loading && wines.length === 0 && ( @@ -67,11 +122,7 @@ export function MyListView({ info, result }: MyListViewProps) { {totalCount !== undefined && totalCount > 0 && ( <> -

- {wines.length < totalCount - ? `Viser ${formatCount(wines.length)} av ${pluralize(totalCount, 'vin', 'viner')}` - : pluralize(totalCount, 'vin', 'viner')} -

+

{countText(wines.length, totalCount)}

)} diff --git a/frontend/src/features/my/MyReviewsPage.tsx b/frontend/src/features/my/MyReviewsPage.tsx index 85bebdc..ff049dc 100644 --- a/frontend/src/features/my/MyReviewsPage.tsx +++ b/frontend/src/features/my/MyReviewsPage.tsx @@ -1,3 +1,4 @@ +import { useState } from 'react'; import { useSearchParams } from 'react-router'; import { useDocumentTitle } from '../../hooks/useDocumentTitle'; import type { ReviewOrder } from './api/myReviewsQuery'; @@ -12,9 +13,14 @@ const OLDEST = 'eldste'; export default function MyReviewsPage() { useDocumentTitle('Mine dommer'); const [params, setParams] = useSearchParams(); - const order: ReviewOrder = params.get(ORDER_PARAM) === OLDEST ? 'OLDEST' : 'NEWEST'; + // In state as well as in the URL, so quick arrow key presses are not lost. See KnownList in + // MyListPage.tsx for why. + const [order, setOrder] = useState(() => + params.get(ORDER_PARAM) === OLDEST ? 'OLDEST' : 'NEWEST', + ); function changeOrder(next: ReviewOrder) { + setOrder(next); // Replace, not push: the back button leaves the page instead of stepping through the orders. setParams(next === 'OLDEST' ? { [ORDER_PARAM]: OLDEST } : {}, { replace: true }); } diff --git a/frontend/src/features/my/listSort.test.ts b/frontend/src/features/my/listSort.test.ts new file mode 100644 index 0000000..b06c5b5 --- /dev/null +++ b/frontend/src/features/my/listSort.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from 'vitest'; +import { LIST_SORTS, paramsForSort, sortFromParams } from './listSort'; + +const fromUrl = (search: string) => sortFromParams(new URLSearchParams(search)); + +describe('the order of a list page in the URL', () => { + it('is the newest first without a value, so the plain address stays the same', () => { + expect(fromUrl('')).toBe('NEWEST'); + expect(paramsForSort('NEWEST')).toEqual({}); + }); + + it.each(LIST_SORTS.map((option) => option.sort))('round-trips %s', (sort) => { + expect(fromUrl(new URLSearchParams(paramsForSort(sort)).toString())).toBe(sort); + }); + + it('reads the Norwegian values', () => { + expect(fromUrl('sortering=din-dom')).toBe('OWN_RATING'); + expect(fromUrl('sortering=best-vurdert')).toBe('COMMUNITY_RATING'); + expect(fromUrl('sortering=navn')).toBe('NAME'); + }); + + it('falls back to the newest first for a value it does not know', () => { + expect(fromUrl('sortering=tull')).toBe('NEWEST'); + expect(fromUrl('sortering=NAME')).toBe('NEWEST'); + expect(fromUrl('sortering=')).toBe('NEWEST'); + }); + + it('only uses values the back link on the wine page accepts', () => { + // WineView trusts /mine/... addresses with lowercase letters, digits, = & and - only. + for (const { param } of LIST_SORTS) { + if (param !== null) expect(param).toMatch(/^[a-z0-9-]+$/); + } + }); +}); diff --git a/frontend/src/features/my/listSort.ts b/frontend/src/features/my/listSort.ts new file mode 100644 index 0000000..0454a87 --- /dev/null +++ b/frontend/src/features/my/listSort.ts @@ -0,0 +1,43 @@ +import type { WineListSort } from '../lists/api/myWineListQuery'; + +/** + * The orders of the list pages on «Min side», in the order the select shows them. The order + * lives in the URL as `?sortering=`, in Norwegian like the other addresses on the site. The + * newest first is the default and has no value, so `/mine/favoritter` stays as it was. + */ +export const LIST_SORTS: { + sort: WineListSort; + /** The value in `?sortering=`. Only lowercase letters and dashes, as the wine page's back link expects. */ + param: string | null; + label: string; + /** How the live region says the order, after «Viser 3 av 7 viner, …». */ + spoken: string; +}[] = [ + { sort: 'NEWEST', param: null, label: 'Sist lagt til', spoken: 'sist lagt til først' }, + { sort: 'OWN_RATING', param: 'din-dom', label: 'Din dom', spoken: 'sortert etter din dom' }, + { + sort: 'COMMUNITY_RATING', + param: 'best-vurdert', + label: 'Best vurdert', + spoken: 'best vurdert først', + }, + { sort: 'NAME', param: 'navn', label: 'Navn A–Å', spoken: 'sortert etter navn' }, +]; + +export const SORT_PARAM = 'sortering'; + +/** The order in the URL. A missing or unknown value is the newest first. */ +export function sortFromParams(params: URLSearchParams): WineListSort { + const value = params.get(SORT_PARAM); + return LIST_SORTS.find((option) => value !== null && option.param === value)?.sort ?? 'NEWEST'; +} + +/** The search params for an order: none for the newest first. */ +export function paramsForSort(sort: WineListSort): Record { + const param = LIST_SORTS.find((option) => option.sort === sort)?.param; + return param ? { [SORT_PARAM]: param } : {}; +} + +export function sortOption(sort: WineListSort) { + return LIST_SORTS.find((option) => option.sort === sort) ?? LIST_SORTS[0]; +} diff --git a/frontend/src/lib/apollo.test.ts b/frontend/src/lib/apollo.test.ts index 1c50258..b4c6fb5 100644 --- a/frontend/src/lib/apollo.test.ts +++ b/frontend/src/lib/apollo.test.ts @@ -70,10 +70,10 @@ describe('createApolloCache', () => { describe('createApolloCache – User.wines', () => { const LIST = gql` - query List($list: WineList!, $after: String) { + query List($list: WineList!, $sort: WineListSort, $after: String) { me { id - wines(list: $list, after: $after) { + wines(list: $list, sort: $sort, after: $after) { totalCount edges { cursor @@ -89,9 +89,9 @@ describe('createApolloCache – User.wines', () => { } } `; - const page = (list: string, ids: string[], after?: string) => ({ + const page = (list: string, ids: string[], after?: string, sort?: string) => ({ query: LIST, - variables: { list, after }, + variables: { list, after, sort }, data: { me: { __typename: 'User', @@ -109,11 +109,11 @@ describe('createApolloCache – User.wines', () => { }, }, }); - const idsOn = (cache: ReturnType, list: string) => + const idsOn = (cache: ReturnType, list: string, sort?: string) => cache .readQuery<{ me: { wines: { edges: { node: { id: string } }[] } } }>({ query: LIST, - variables: { list }, + variables: { list, sort }, }) ?.me.wines.edges.map((edge) => edge.node.id); @@ -126,6 +126,26 @@ describe('createApolloCache – User.wines', () => { expect(idsOn(cache, 'FAVOURITE')).toEqual(['1', '2', '3']); expect(idsOn(cache, 'TRIED')).toEqual(['9']); }); + + it('keeps each order of a list apart, with its own pages', () => { + const cache = createApolloCache(); + cache.writeQuery(page('FAVOURITE', ['1', '2'])); + cache.writeQuery(page('FAVOURITE', ['2', '1'], undefined, 'NAME')); + cache.writeQuery(page('FAVOURITE', ['3'], '1', 'NAME')); + + expect(idsOn(cache, 'FAVOURITE')).toEqual(['1', '2']); + expect(idsOn(cache, 'FAVOURITE', 'NAME')).toEqual(['2', '1', '3']); + expect(idsOn(cache, 'FAVOURITE', 'OWN_RATING')).toBeUndefined(); + }); + + it('stores a list asked for without a sort in one place, so «Min side» and the list page share it', () => { + const cache = createApolloCache(); + cache.writeQuery(page('FAVOURITE', ['1', '2'])); + + // The list page leaves out NEWEST (listVariables), and finds what «Min side» stored. + expect(cache.extract()['User:1']).toHaveProperty(['wines:{"list":"FAVOURITE"}']); + expect(idsOn(cache, 'FAVOURITE')).toEqual(['1', '2']); + }); }); describe('createSessionLink', () => { diff --git a/frontend/src/lib/apollo.ts b/frontend/src/lib/apollo.ts index 705ce6a..2d7dfb8 100644 --- a/frontend/src/lib/apollo.ts +++ b/frontend/src/lib/apollo.ts @@ -38,10 +38,12 @@ export function createApolloCache() { FilterOptions: { merge: true }, User: { fields: { - // One list per name (FAVOURITE, WANT_TO_TRY, TRIED), with its pages added after each - // other like the search results. See also updateListPages in features/lists. + // One list per name (FAVOURITE, WANT_TO_TRY, TRIED) and order, with its pages added + // after each other like the search results. Without a sort, the list is the newest + // first, and «Min side» and the list page share it. See also updateListPages in + // features/lists, which changes every order of a list. wines: { - keyArgs: ['list'], + keyArgs: ['list', 'sort', 'minRating'], merge(existing: WineConnection | undefined, incoming: WineConnection, { args }) { return mergeWineConnection(existing, incoming, args?.after as string | undefined); },