Skip to content

Commit

Permalink
💚 - test: fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Apr 15, 2024
1 parent 4f9e18d commit 79a2380
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
67 changes: 30 additions & 37 deletions src/components/data/paginator/paginator.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ export const PaginatorComponentWithSpinner: Story = {
}

const canvas = within(canvasElement);
const pageInput = canvas.getByRole("spinbutton");
const previousButton = canvas.getByLabelText("Previous");
const nextButton = canvas.getByLabelText("Next");
const previousButton = canvas.getByText("Previous");
const nextButton = canvas.getByText("Next");
canvas.getByRole("navigation");
canvas.getByLabelText("Pagination");
canvas.getByText("Number of results");
canvas.getByText("Go to page");

// Click page size select.
const pageSizeSelect = canvas.getByRole("combobox");
Expand All @@ -80,9 +78,6 @@ export const PaginatorComponentWithSpinner: Story = {
// Wait for...
await waitFor(
async () => {
// ...page input to be reset to 1.
await expect(pageInput).toHaveValue(1);

// ...spinner to become visible.
await expect(await canvas.findByLabelText("Loading...")).toBeVisible();
},
Expand All @@ -99,41 +94,39 @@ export const PaginatorComponentWithSpinner: Story = {
{ timeout: 2000 },
);

// Type to "2" in pageInput.
await userEvent.click(pageInput, { delay: 10 });
await userEvent.clear(pageInput);
await userEvent.type(pageInput, "2");

// Click previous page.
await userEvent.click(previousButton);
await expect(pageInput).toHaveValue(1);
await expect(canvas.getByLabelText("go to page 1")).toHaveAttribute(
"aria-current",
);

// Click previous page again.
await userEvent.click(previousButton);
await expect(pageInput).toHaveValue(1);
await expect(previousButton).toBeDisabled();

// Click next page.
await userEvent.click(nextButton);
await expect(pageInput).toHaveValue(2);
await canvas.findByText("Result 11 to 20 of 13 pages");
await expect(canvas.getByLabelText("go to page 2")).toHaveAttribute(
"aria-current",
);

// Click next page until 13.
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await userEvent.click(nextButton);
await expect(pageInput).toHaveValue(13);
// Click previous page.
await userEvent.click(previousButton);
await expect(canvas.getByLabelText("go to page 1")).toHaveAttribute(
"aria-current",
);

// Click next page again.
await userEvent.click(nextButton);
await expect(pageInput).toHaveValue(13);
await canvas.findByText("Result 121 to 123 of 13 pages");
// Click next page until 13.
await userEvent.click(canvas.getByLabelText("go to page 2"));
await userEvent.click(canvas.getByLabelText("go to page 3"));
await userEvent.click(canvas.getByLabelText("go to page 4"));
await userEvent.click(canvas.getByLabelText("go to page 5"));
await userEvent.click(canvas.getByLabelText("go to page 6"));
await userEvent.click(canvas.getByLabelText("go to page 7"));
await userEvent.click(canvas.getByLabelText("go to page 8"));
await userEvent.click(canvas.getByLabelText("go to page 9"));
await userEvent.click(canvas.getByLabelText("go to page 10"));
await userEvent.click(canvas.getByLabelText("go to page 11"));
await userEvent.click(canvas.getByLabelText("go to page 12"));
await userEvent.click(canvas.getByLabelText("go to page 13"));

await expect(nextButton).toBeDisabled();
await canvas.getByTitle("Result 121 to 123 of 13 pages");
},
};
2 changes: 1 addition & 1 deletion src/lib/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"originalDefault": "resultaat {pageStart} t/m {pageEnd} van {pageCount} pagina's"
},
"mykn.components.Paginator.labelGoToPage": {
"defaultMessage": "go to page",
"defaultMessage": "go to page {page}",
"description": "mykn.components.Paginator: The go to page (accessible) label",
"originalDefault": "naar pagina {page}"
},
Expand Down

0 comments on commit 79a2380

Please sign in to comment.