Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import { AUTO_SCROLL_BOTTOM_THRESHOLD_PX, isScrollContainerNearBottom } from "./chat-scroll";
4
5describe("isScrollContainerNearBottom", () => {
6 it("returns true when already at bottom", () => {
7 expect(
8 isScrollContainerNearBottom({
9 scrollTop: 600,
10 clientHeight: 400,
11 scrollHeight: 1_000,
12 }),
13 ).toBe(true);
14 });
15
16 it("returns true when within the auto-scroll threshold", () => {
17 expect(
18 isScrollContainerNearBottom({
19 scrollTop: 540,
20 clientHeight: 400,
21 scrollHeight: 1_000,
22 }),
23 ).toBe(true);
24 });
25
26 it("returns false when the user is meaningfully above the bottom", () => {
27 expect(
28 isScrollContainerNearBottom({
29 scrollTop: 520,
30 clientHeight: 400,
31 scrollHeight: 1_000,
32 }),
33 ).toBe(false);
34 });
35
36 it("clamps negative thresholds to zero", () => {
37 expect(
38 isScrollContainerNearBottom(
39 {
40 scrollTop: 539,
41 clientHeight: 400,
42 scrollHeight: 1_000,
43 },
44 -1,
45 ),
46 ).toBe(false);
47 });
48
49 it("falls back to the default threshold for non-finite values", () => {
50 expect(
51 isScrollContainerNearBottom(
52 {
53 scrollTop: 540,
54 clientHeight: 400,
55 scrollHeight: 1_000,
56 },
57 Number.NaN,
58 ),
59 ).toBe(true);
60 expect(AUTO_SCROLL_BOTTOM_THRESHOLD_PX).toBe(64);
61 });
62});