Skip to content

Commit

Permalink
test: filtering the books list does not reset the pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Dec 18, 2023
1 parent 29bb32f commit 32219a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pwa/tests/BooksList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$/);
Expand Down

0 comments on commit 32219a4

Please sign in to comment.