forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

capped-list.test.ts25 lines, 1.1 KiBHistoryRawDownload
1import type { Page, PageParams } from "@/api/client";
2import { isTruncated, loadCappedList } from "./capped-list";
3
4const page = (items: number[], total: number): Page<number> => ({ items, total, limit: null, offset: 0 });
5
6it("asks for the cap and reports the server total", async () => {
7 const fetch = vi.fn(async (_params?: PageParams) => page([1, 2], 5));
8 const list = await loadCappedList(fetch, 2, false);
9 expect(fetch).toHaveBeenCalledWith({ limit: 2 });
10 expect(list).toEqual({ items: [1, 2], total: 5 });
11 expect(isTruncated(list)).toBe(true);
12});
13
14it("fetches every row without a limit when asked for all", async () => {
15 const fetch = vi.fn(async (_params?: PageParams) => page([1, 2, 3, 4, 5], 5));
16 const list = await loadCappedList(fetch, 2, true);
17 expect(fetch).toHaveBeenCalledWith(undefined);
18 expect(isTruncated(list)).toBe(false);
19});
20
21it("never reports a total below the rows it holds", async () => {
22 const list = await loadCappedList(async () => page([1, 2, 3], 1), 10, false);
23 expect(list.total).toBe(3);
24 expect(isTruncated(undefined)).toBe(false);
25});