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

thread-feed-live-follow.test.ts

70 lines1.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveThreadFeedLiveFollow } from "./thread-feed-live-follow";
4​
5describe("resolveThreadFeedLiveFollow", () => {
6 it("pauses immediately when the user starts scrolling", () => {
7 expect(resolveThreadFeedLiveFollow(true, { type: "user-scroll-begin" })).toBe(false);
8 });
9​
10 it("stays paused away from the actual end", () => {
11 expect(
12 resolveThreadFeedLiveFollow(false, {
13 type: "scroll",
14 isAtEnd: false,
15 userScrollSessionActive: true,
16 }),
17 ).toBe(false);
18 });
19​
20 it("does not mistake programmatic layout compensation for a user scroll", () => {
21 expect(
22 resolveThreadFeedLiveFollow(true, {
23 type: "scroll",
24 isAtEnd: false,
25 userScrollSessionActive: false,
26 }),
27 ).toBe(true);
28 });
29​
30 it("does not re-arm at the end while a user scroll session is active", () => {
31 expect(
32 resolveThreadFeedLiveFollow(false, {
33 type: "scroll",
34 isAtEnd: true,
35 userScrollSessionActive: true,
36 }),
37 ).toBe(false);
38 });
39​
40 it("re-arms at the actual end only after the user scroll session ends", () => {
41 expect(
42 resolveThreadFeedLiveFollow(false, {
43 type: "user-scroll-end",
44 isAtEnd: true,
45 userScrollSessionActive: true,
46 }),
47 ).toBe(true);
48 expect(
49 resolveThreadFeedLiveFollow(false, {
50 type: "user-scroll-end",
51 isAtEnd: false,
52 userScrollSessionActive: true,
53 }),
54 ).toBe(false);
55 });
56​
57 it("ignores momentum-end events from programmatic scrolling", () => {
58 expect(
59 resolveThreadFeedLiveFollow(true, {
60 type: "user-scroll-end",
61 isAtEnd: false,
62 userScrollSessionActive: false,
63 }),
64 ).toBe(true);
65 });
66​
67 it("re-arms after an explicit reset", () => {
68 expect(resolveThreadFeedLiveFollow(false, { type: "reset" })).toBe(true);
69 });
70});