1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00
unleash.unleash/frontend/src/utils/paginate.test.ts
Gastón Fournier abe160eb7d
feat: Unleash v7 ESM migration (#9877)
We're migrating to ESM, which will allow us to import the latest
versions of our dependencies.

Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
2025-05-14 09:47:12 +02:00

35 lines
910 B
TypeScript

import { paginate } from './paginate.js';
const createInput = (count: number) => {
const result: number[] = [];
for (let i = 0; i < count; i++) {
result.push(i);
}
return result;
};
test('it creates the correct amount of pages when count is even', () => {
const input = createInput(20);
expect(input.length).toBe(20);
const paginationResult = paginate(input, 5);
expect(paginationResult.length).toBe(4);
expect(Array.isArray(paginationResult[0])).toBe(true);
});
test('it creates the correct amount of pages when count is uneven', () => {
const input = createInput(33);
expect(input.length).toBe(33);
const paginationResult = paginate(input, 9);
expect(paginationResult.length).toBe(4);
const paginationCount = paginationResult.reduce((acc, cur) => {
return acc + cur.length;
}, 0);
expect(paginationCount).toBe(33);
});