Path: blob/main/components/dashboard/src/Pagination/getPagination.spec.ts
2500 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { getPaginationNumbers } from "./getPagination";78test("getPagination", () => {9expect(getPaginationNumbers(15, 1)).toStrictEqual([1, 2, 3, "...", 15]);1011expect(getPaginationNumbers(37, 4)).toStrictEqual([1, 2, 3, 4, 5, "...", 37]);1213// navigating 7 --> 414// ensure there is a selectable page next to current15expect(getPaginationNumbers(28, 7)).toStrictEqual([1, "...", 6, 7, 8, "...", 28]);16expect(getPaginationNumbers(28, 6)).toStrictEqual([1, "...", 5, 6, 7, "...", 28]);17expect(getPaginationNumbers(28, 5)).toStrictEqual([1, "...", 4, 5, 6, "...", 28]);18// ellipsis should not replace a single page number19expect(getPaginationNumbers(28, 4)).toStrictEqual([1, 2, 3, 4, 5, "...", 28]);2021// ensure there is a selectable page next to current22expect(getPaginationNumbers(28, 24)).toStrictEqual([1, "...", 23, 24, 25, "...", 28]);23expect(getPaginationNumbers(28, 25)).toStrictEqual([1, "...", 24, 25, 26, 27, 28]);2425expect(getPaginationNumbers(5, 1)).toStrictEqual([1, 2, 3, 4, 5]);2627expect(getPaginationNumbers(9, 2)).toStrictEqual([1, 2, 3, "...", 9]);28expect(getPaginationNumbers(9, 3)).toStrictEqual([1, 2, 3, 4, "...", 9]);29expect(getPaginationNumbers(6, 3)).toStrictEqual([1, 2, 3, 4, 5, 6]);30expect(getPaginationNumbers(7, 3)).toStrictEqual([1, 2, 3, 4, "...", 7]);31expect(getPaginationNumbers(7, 3)).toStrictEqual([1, 2, 3, 4, "...", 7]);3233expect(getPaginationNumbers(10, 8)).toStrictEqual([1, "...", 7, 8, 9, 10]);34expect(getPaginationNumbers(10, 7)).toStrictEqual([1, "...", 6, 7, 8, 9, 10]);35});363738