Skip to content
Source
Sign inSign up
Open History to see the last commit

paginatedBranches.test.ts

46 lines1.2 KB

1import type { VcsListRefsResult } from "@t3tools/contracts";
2import { AsyncResult } from "effect/reactivity";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { isPaginatedBranchesNextPagePending } from "./paginatedBranches";
6​
7const FIRST_PAGE: VcsListRefsResult = {
8 refs: [],
9 isRepo: true,
10 hasPrimaryRemote: true,
11 nextCursor: 100,
12 totalCount: 150,
13};
14​
15const LAST_PAGE: VcsListRefsResult = {
16 ...FIRST_PAGE,
17 nextCursor: null,
18};
19​
20describe("paginated branch loading state", () => {
21 it("does not label a first-page background refresh as loading more refs", () => {
22 expect(
23 isPaginatedBranchesNextPagePending([
24 AsyncResult.success(FIRST_PAGE, {
25 waiting: true,
26 }),
27 ]),
28 ).toBe(false);
29 });
30​
31 it("only reports loading more while a new cursor has no value", () => {
32 expect(
33 isPaginatedBranchesNextPagePending([
34 AsyncResult.success(FIRST_PAGE),
35 AsyncResult.initial<VcsListRefsResult>(true),
36 ]),
37 ).toBe(true);
38​
39 expect(
40 isPaginatedBranchesNextPagePending([
41 AsyncResult.success(FIRST_PAGE),
42 AsyncResult.success(LAST_PAGE),
43 ]),
44 ).toBe(false);
45 });
46});