Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/Pagination/getPagination.spec.ts
2500 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { getPaginationNumbers } from "./getPagination";
8
9
test("getPagination", () => {
10
expect(getPaginationNumbers(15, 1)).toStrictEqual([1, 2, 3, "...", 15]);
11
12
expect(getPaginationNumbers(37, 4)).toStrictEqual([1, 2, 3, 4, 5, "...", 37]);
13
14
// navigating 7 --> 4
15
// ensure there is a selectable page next to current
16
expect(getPaginationNumbers(28, 7)).toStrictEqual([1, "...", 6, 7, 8, "...", 28]);
17
expect(getPaginationNumbers(28, 6)).toStrictEqual([1, "...", 5, 6, 7, "...", 28]);
18
expect(getPaginationNumbers(28, 5)).toStrictEqual([1, "...", 4, 5, 6, "...", 28]);
19
// ellipsis should not replace a single page number
20
expect(getPaginationNumbers(28, 4)).toStrictEqual([1, 2, 3, 4, 5, "...", 28]);
21
22
// ensure there is a selectable page next to current
23
expect(getPaginationNumbers(28, 24)).toStrictEqual([1, "...", 23, 24, 25, "...", 28]);
24
expect(getPaginationNumbers(28, 25)).toStrictEqual([1, "...", 24, 25, 26, 27, 28]);
25
26
expect(getPaginationNumbers(5, 1)).toStrictEqual([1, 2, 3, 4, 5]);
27
28
expect(getPaginationNumbers(9, 2)).toStrictEqual([1, 2, 3, "...", 9]);
29
expect(getPaginationNumbers(9, 3)).toStrictEqual([1, 2, 3, 4, "...", 9]);
30
expect(getPaginationNumbers(6, 3)).toStrictEqual([1, 2, 3, 4, 5, 6]);
31
expect(getPaginationNumbers(7, 3)).toStrictEqual([1, 2, 3, 4, "...", 7]);
32
expect(getPaginationNumbers(7, 3)).toStrictEqual([1, 2, 3, 4, "...", 7]);
33
34
expect(getPaginationNumbers(10, 8)).toStrictEqual([1, "...", 7, 8, 9, 10]);
35
expect(getPaginationNumbers(10, 7)).toStrictEqual([1, "...", 6, 7, 8, 9, 10]);
36
});
37
38