Skip to content

Commit 2ffefc3

Browse files
fix: Don't show pagination during workspaces load (#4743)
1 parent f622247 commit 2ffefc3

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@ import { render } from "../../testHelpers/renderHelpers"
33
import { PaginationWidget } from "./PaginationWidget"
44

55
describe("PaginatedList", () => {
6-
it("displays an accessible previous and next button regardless of the number of pages", async () => {
7-
const { container } = render(
6+
it("displays an accessible previous and next button", () => {
7+
render(
88
<PaginationWidget
99
prevLabel="Previous"
1010
nextLabel="Next"
11+
numRecords={200}
12+
numRecordsPerPage={12}
13+
activePage={1}
1114
onPrevClick={() => jest.fn()}
1215
onNextClick={() => jest.fn()}
1316
/>,
1417
)
1518

1619
expect(
17-
await screen.findByRole("button", { name: "Previous page" }),
18-
).toBeTruthy()
19-
expect(
20-
await screen.findByRole("button", { name: "Next page" }),
21-
).toBeTruthy()
22-
// Shouldn't render any pages if no records are passed in
20+
screen.getByRole("button", { name: "Previous page" }),
21+
).toBeInTheDocument()
2322
expect(
24-
await container.querySelectorAll(`button[name="Page button"]`),
25-
).toHaveLength(0)
23+
screen.getByRole("button", { name: "Next page" }),
24+
).toBeInTheDocument()
2625
})
2726

28-
it("displays the expected number of pages with one ellipsis tile", async () => {
27+
it("displays the expected number of pages with one ellipsis tile", () => {
2928
const { container } = render(
3029
<PaginationWidget
3130
prevLabel="Previous"
@@ -41,11 +40,11 @@ describe("PaginatedList", () => {
4140

4241
// 7 total spaces. 6 are page numbers, one is ellipsis
4342
expect(
44-
await container.querySelectorAll(`button[name="Page button"]`),
43+
container.querySelectorAll(`button[name="Page button"]`),
4544
).toHaveLength(6)
4645
})
4746

48-
it("displays the expected number of pages with two ellipsis tiles", async () => {
47+
it("displays the expected number of pages with two ellipsis tiles", () => {
4948
const { container } = render(
5049
<PaginationWidget
5150
prevLabel="Previous"
@@ -61,7 +60,7 @@ describe("PaginatedList", () => {
6160

6261
// 7 total spaces. 2 sets of ellipsis on either side of the active page
6362
expect(
64-
await container.querySelectorAll(`button[name="Page button"]`),
63+
container.querySelectorAll(`button[name="Page button"]`),
6564
).toHaveLength(5)
6665
})
6766
})

site/src/components/PaginationWidget/PaginationWidget.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export const PaginationWidget = ({
127127
const isMobile = useMediaQuery(theme.breakpoints.down("sm"))
128128
const styles = useStyles()
129129

130-
// No need to display any pagination if we know the number of pages is 1
131-
if (numPages === 1 || numRecords === 0) {
130+
// No need to display any pagination if we know the number of pages is 1 or 0
131+
if (numPages <= 1 || numRecords === 0) {
132132
return null
133133
}
134134

0 commit comments

Comments
 (0)