Open History to see the last commit
1import type { VcsListRefsResult } from "@t3tools/contracts";
2import { AsyncResult } from "effect/reactivity";
3import { describe, expect, it } from "vite-plus/test";
4
5import {
6 isPaginatedBranchesNextPagePending,
7 shouldLoadNextBranchPageAfterScroll,
8} from "./paginatedBranches";
9
10const FIRST_PAGE: VcsListRefsResult = {
11 refs: [],
12 isRepo: true,
13 hasPrimaryRemote: true,
14 nextCursor: 100,
15 totalCount: 150,
16};
17
18const LAST_PAGE: VcsListRefsResult = {
19 ...FIRST_PAGE,
20 nextCursor: null,
21};
22
23describe("paginated branch loading state", () => {
24 it("does not label a first-page background refresh as loading more refs", () => {
25 expect(
26 isPaginatedBranchesNextPagePending([
27 AsyncResult.success(FIRST_PAGE, {
28 waiting: true,
29 }),
30 ]),
31 ).toBe(false);
32 });
33
34 it("only reports loading more while a new cursor has no value", () => {
35 expect(
36 isPaginatedBranchesNextPagePending([
37 AsyncResult.success(FIRST_PAGE),
38 AsyncResult.initial<VcsListRefsResult>(true),
39 ]),
40 ).toBe(true);
41
42 expect(
43 isPaginatedBranchesNextPagePending([
44 AsyncResult.success(FIRST_PAGE),
45 AsyncResult.success(LAST_PAGE),
46 ]),
47 ).toBe(false);
48 });
49});
50
51describe("paginated branch scroll trigger", () => {
52 it("does not load from mount, layout, or an unchanged scroll position", () => {
53 expect(
54 shouldLoadNextBranchPageAfterScroll({
55 previousScrollTop: null,
56 scrollTop: 0,
57 scrollHeight: 224,
58 clientHeight: 224,
59 }),
60 ).toBe(false);
61
62 expect(
63 shouldLoadNextBranchPageAfterScroll({
64 previousScrollTop: 120,
65 scrollTop: 120,
66 scrollHeight: 344,
67 clientHeight: 224,
68 }),
69 ).toBe(false);
70 });
71
72 it("loads only after a downward scroll reaches the end threshold", () => {
73 expect(
74 shouldLoadNextBranchPageAfterScroll({
75 previousScrollTop: 0,
76 scrollTop: 100,
77 scrollHeight: 800,
78 clientHeight: 224,
79 }),
80 ).toBe(false);
81
82 expect(
83 shouldLoadNextBranchPageAfterScroll({
84 previousScrollTop: 100,
85 scrollTop: 500,
86 scrollHeight: 800,
87 clientHeight: 224,
88 }),
89 ).toBe(true);
90
91 expect(
92 shouldLoadNextBranchPageAfterScroll({
93 previousScrollTop: 499.5,
94 scrollTop: 500,
95 scrollHeight: 800,
96 clientHeight: 224,
97 }),
98 ).toBe(true);
99 });
100});