This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / components / profile / pagination.test.ts
1.3 kB 36 lines
1import { describe, expect, it } from "vitest"; 2import { createCursorPager, discoveredPageCount, pageCount } from "./pagination.svelte"; 3 4describe("profile pagination counts", () => { 5 it("uses the known total for profile lists", () => { 6 expect(pageCount(4, 30)).toBe(1); 7 expect(pageCount(30, 30)).toBe(1); 8 expect(pageCount(31, 30)).toBe(2); 9 }); 10 11 it("only discovers an extra page when totals are unavailable", () => { 12 expect(discoveredPageCount(1, false)).toBe(1); 13 expect(discoveredPageCount(1, true)).toBe(2); 14 expect(discoveredPageCount(2, true)).toBe(3); 15 }); 16 17 it("keeps pager lifecycle in one state", async () => { 18 let release!: (page: { items: string[] }) => void; 19 const pager = createCursorPager( 20 { items: ["first"], cursor: "next" }, 21 () => new Promise<{ items: string[] }>((resolve) => (release = resolve)) 22 ); 23 24 const loading = pager.select(2); 25 expect(pager.state).toEqual({ kind: "loading", page: 1 }); 26 release({ items: ["second"] }); 27 await loading; 28 expect(pager.state).toEqual({ kind: "at-page", page: 2 }); 29 30 const failing = createCursorPager({ items: ["first"], cursor: "next" }, async () => { 31 throw new Error("nope"); 32 }); 33 await failing.select(2); 34 expect(failing.state).toEqual({ kind: "failed", page: 1 }); 35 }); 36});