Skip to content

Commit 899b08e

Browse files
committed
Refactor PageButton tests
1 parent 18611c8 commit 899b08e

File tree

2 files changed

+24
-67
lines changed

2 files changed

+24
-67
lines changed
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Story } from "@storybook/react";
2-
import { PaginationWidget, PaginationWidgetProps } from "./PaginationWidget";
1+
import { PaginationWidget } from "./PaginationWidget";
32
import { createPaginationRef } from "./utils";
3+
import type { Meta, StoryObj } from "@storybook/react";
44

5-
export default {
5+
const meta: Meta<typeof PaginationWidget> = {
66
title: "components/PaginationWidget",
77
component: PaginationWidget,
88
args: {
@@ -13,28 +13,31 @@ export default {
1313
},
1414
};
1515

16-
const Template: Story<PaginationWidgetProps> = (
17-
args: PaginationWidgetProps,
18-
) => <PaginationWidget {...args} />;
16+
export default meta;
17+
type Story = StoryObj<typeof PaginationWidget>;
1918

20-
export const LessThan8Pages = Template.bind({});
21-
LessThan8Pages.args = {
22-
numRecords: 84,
23-
};
19+
export const MoreThan8Pages: Story = {};
2420

25-
export const MoreThan8Pages = Template.bind({});
21+
export const LessThan8Pages: Story = {
22+
args: {
23+
numRecords: 84,
24+
},
25+
};
2626

27-
export const MoreThan7PagesWithActivePageCloseToStart = Template.bind({});
28-
MoreThan7PagesWithActivePageCloseToStart.args = {
29-
paginationRef: createPaginationRef({ page: 2, limit: 12 }),
27+
export const MoreThan7PagesWithActivePageCloseToStart: Story = {
28+
args: {
29+
paginationRef: createPaginationRef({ page: 2, limit: 12 }),
30+
},
3031
};
3132

32-
export const MoreThan7PagesWithActivePageFarFromBoundaries = Template.bind({});
33-
MoreThan7PagesWithActivePageFarFromBoundaries.args = {
34-
paginationRef: createPaginationRef({ page: 4, limit: 12 }),
33+
export const MoreThan7PagesWithActivePageFarFromBoundaries: Story = {
34+
args: {
35+
paginationRef: createPaginationRef({ page: 4, limit: 12 }),
36+
},
3537
};
3638

37-
export const MoreThan7PagesWithActivePageCloseToEnd = Template.bind({});
38-
MoreThan7PagesWithActivePageCloseToEnd.args = {
39-
paginationRef: createPaginationRef({ page: 17, limit: 12 }),
39+
export const MoreThan7PagesWithActivePageCloseToEnd: Story = {
40+
args: {
41+
paginationRef: createPaginationRef({ page: 17, limit: 12 }),
42+
},
4043
};

site/src/components/PaginationWidget/PaginationWidget.test.tsx

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,9 @@
11
import { screen } from "@testing-library/react";
2-
import { render } from "../../testHelpers/renderHelpers";
2+
import { render } from "testHelpers/renderHelpers";
33
import { PaginationWidget } from "./PaginationWidget";
44
import { createPaginationRef } from "./utils";
55

66
describe("PaginatedList", () => {
7-
it("displays an accessible previous and next button", () => {
8-
render(
9-
<PaginationWidget
10-
prevLabel="Previous"
11-
nextLabel="Next"
12-
paginationRef={createPaginationRef({ page: 2, limit: 12 })}
13-
numRecords={200}
14-
/>,
15-
);
16-
17-
expect(screen.getByRole("button", { name: "Previous page" })).toBeEnabled();
18-
expect(screen.getByRole("button", { name: "Next page" })).toBeEnabled();
19-
});
20-
21-
it("displays the expected number of pages with one ellipsis tile", () => {
22-
const { container } = render(
23-
<PaginationWidget
24-
prevLabel="Previous"
25-
nextLabel="Next"
26-
numRecords={200}
27-
paginationRef={createPaginationRef({ page: 1, limit: 12 })}
28-
/>,
29-
);
30-
31-
// 7 total spaces. 6 are page numbers, one is ellipsis
32-
expect(
33-
container.querySelectorAll(`button[name="Page button"]`),
34-
).toHaveLength(6);
35-
});
36-
37-
it("displays the expected number of pages with two ellipsis tiles", () => {
38-
const { container } = render(
39-
<PaginationWidget
40-
prevLabel="Previous"
41-
nextLabel="Next"
42-
numRecords={200}
43-
paginationRef={createPaginationRef({ page: 6, limit: 12 })}
44-
/>,
45-
);
46-
47-
// 7 total spaces. 2 sets of ellipsis on either side of the active page
48-
expect(
49-
container.querySelectorAll(`button[name="Page button"]`),
50-
).toHaveLength(5);
51-
});
52-
537
it("disables the previous button on the first page", () => {
548
render(
559
<PaginationWidget

0 commit comments

Comments
 (0)