From 32219a410e5f5095796e2b606752a66b2666acc3 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:33:32 +0100 Subject: [PATCH 1/2] test: filtering the books list does not reset the pagination --- pwa/tests/BooksList.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pwa/tests/BooksList.spec.ts b/pwa/tests/BooksList.spec.ts index da4a22db8..883f2f896 100644 --- a/pwa/tests/BooksList.spec.ts +++ b/pwa/tests/BooksList.spec.ts @@ -106,6 +106,25 @@ test.describe("Books list", () => { await expect(page.getByTestId("nb-books")).toHaveText(`${totalBooks} book(s) found`); await expect(page.getByTestId("book").or(page.getByTestId("loading"))).toHaveCount(30); + // filtering must reset the pagination + await page.getByLabel("Go to next page").click(); + await expect(page).toHaveURL(/\/books\?page=2$/); + await expect(page.getByTestId("book").or(page.getByTestId("loading"))).toHaveCount(30); + await expect(await bookPage.getDefaultBook()).not.toBeVisible(); + await bookPage.filter({ author: "Dan Simmons" }); + await expect(page).toHaveURL(/\/books\?author=Dan\+Simmons/); + await expect(page.getByTestId("nb-books")).toHaveText("1 book(s) found"); + await expect(page.getByTestId("book").or(page.getByTestId("loading"))).toHaveCount(1); + await expect(page.getByTestId("pagination")).toHaveCount(0); + await expect(await bookPage.getDefaultBook()).toBeVisible(); + + // clear author field + await page.getByTestId("filter-author").clear(); + await expect(page.getByTestId("filter-author")).toHaveValue(""); + await expect(page).toHaveURL(/\/books$/); + await expect(page.getByTestId("nb-books")).toHaveText(`${totalBooks} book(s) found`); + await expect(page.getByTestId("book").or(page.getByTestId("loading"))).toHaveCount(30); + // filter by title, author and condition await bookPage.filter({ author: "Dan Simmons", title: "Hyperion", condition: "Used" }); await expect(page).toHaveURL(/\/books\?author=Dan\+Simmons&title=Hyperion&condition%5B%5D=https%3A%2F%2Fschema\.org%2FUsedCondition$/); From bb86845bc7b51d753fdbeede4155aa31d7b85825 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:41:14 +0100 Subject: [PATCH 2/2] fix: filtering the books list resets the pagination --- pwa/components/book/Filters.tsx | 2 +- pwa/components/book/List.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pwa/components/book/Filters.tsx b/pwa/components/book/Filters.tsx index 3f5c511bc..c4954c916 100644 --- a/pwa/components/book/Filters.tsx +++ b/pwa/components/book/Filters.tsx @@ -19,7 +19,7 @@ export const Filters: FunctionComponent = ({ filters, mutation }) => ( enableReinitialize={true} onSubmit={(values, { setSubmitting, setStatus, setErrors }) => { mutation.mutate( - values, + { ...values, page: 1 }, { onSuccess: () => { setStatus({ diff --git a/pwa/components/book/List.tsx b/pwa/components/book/List.tsx index 6dabfb958..ca37d7a0c 100644 --- a/pwa/components/book/List.tsx +++ b/pwa/components/book/List.tsx @@ -62,7 +62,7 @@ export const List: NextPage = ({ data, hubURL, filters, page }) => { value={filters.order?.title ?? ""} displayEmpty onChange={(event) => { - filtersMutation.mutate({ ...filters, order: event.target.value ? { title: event.target.value } : undefined }); + filtersMutation.mutate({ ...filters, page: 1, order: event.target.value ? { title: event.target.value } : undefined }); }} > Relevance