hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import type { Page, PageParams } from "@/api/client"; |
| 2 | import { isTruncated, loadCappedList } from "./capped-list"; |
| 3 | |
| 4 | const page = (items: number[], total: number): Page<number> => ({ items, total, limit: null, offset: 0 }); |
| 5 | |
| 6 | it("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 | |
| 14 | it("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 | |
| 21 | it("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 | }); |