-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: data table pagination with arrows
- Loading branch information
Showing
2 changed files
with
234 additions
and
28 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
frontend/src/components/data-table/__test__/pagination.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { expect, test } from "vitest"; | ||
import { render } from "@testing-library/react"; | ||
import { PageSelector } from "../pagination"; | ||
import { Functions } from "@/utils/functions"; | ||
|
||
function getOptions(currentPage: number) { | ||
const { container } = render( | ||
<PageSelector | ||
currentPage={currentPage} | ||
totalPages={200} | ||
onPageChange={Functions.NOOP} | ||
/>, | ||
); | ||
|
||
const options = container.querySelectorAll("option"); | ||
const optionValues = [...options].map((option) => option.textContent); | ||
return optionValues; | ||
} | ||
|
||
test("pagination start / middle / end", () => { | ||
expect(getOptions(1)).toMatchInlineSnapshot(` | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9", | ||
"10", | ||
"...", | ||
"96", | ||
"97", | ||
"98", | ||
"99", | ||
"100", | ||
"101", | ||
"102", | ||
"103", | ||
"104", | ||
"105", | ||
"...", | ||
"191", | ||
"192", | ||
"193", | ||
"194", | ||
"195", | ||
"196", | ||
"197", | ||
"198", | ||
"199", | ||
"200", | ||
] | ||
`); | ||
|
||
// all fall in the top/middle/bottom 10 | ||
expect(getOptions(1)).toEqual(getOptions(10)); | ||
expect(getOptions(96)).toEqual(getOptions(105)); | ||
expect(getOptions(191)).toEqual(getOptions(200)); | ||
|
||
// Check off by one | ||
expect(getOptions(1)).not.toEqual(getOptions(11)); | ||
expect(getOptions(1)).not.toEqual(getOptions(95)); | ||
expect(getOptions(1)).not.toEqual(getOptions(106)); | ||
expect(getOptions(1)).not.toEqual(getOptions(190)); | ||
}); | ||
|
||
test("pagination lower middle", () => { | ||
expect(getOptions(50)).toMatchInlineSnapshot(` | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9", | ||
"10", | ||
"...", | ||
"50", | ||
"...", | ||
"96", | ||
"97", | ||
"98", | ||
"99", | ||
"100", | ||
"101", | ||
"102", | ||
"103", | ||
"104", | ||
"105", | ||
"...", | ||
"191", | ||
"192", | ||
"193", | ||
"194", | ||
"195", | ||
"196", | ||
"197", | ||
"198", | ||
"199", | ||
"200", | ||
] | ||
`); | ||
}); | ||
|
||
test("pagination upper middle", () => { | ||
expect(getOptions(150)).toMatchInlineSnapshot(` | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9", | ||
"10", | ||
"...", | ||
"96", | ||
"97", | ||
"98", | ||
"99", | ||
"100", | ||
"101", | ||
"102", | ||
"103", | ||
"104", | ||
"105", | ||
"...", | ||
"150", | ||
"...", | ||
"191", | ||
"192", | ||
"193", | ||
"194", | ||
"195", | ||
"196", | ||
"197", | ||
"198", | ||
"199", | ||
"200", | ||
] | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters