-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathchat-scroll.test.ts
More file actions
62 lines (56 loc) · 1.43 KB
/
chat-scroll.test.ts
File metadata and controls
62 lines (56 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, expect, it } from "vitest";
import { AUTO_SCROLL_BOTTOM_THRESHOLD_PX, isScrollContainerNearBottom } from "./chat-scroll";
describe("isScrollContainerNearBottom", () => {
it("returns true when already at bottom", () => {
expect(
isScrollContainerNearBottom({
scrollTop: 600,
clientHeight: 400,
scrollHeight: 1_000,
}),
).toBe(true);
});
it("returns true when within the auto-scroll threshold", () => {
expect(
isScrollContainerNearBottom({
scrollTop: 540,
clientHeight: 400,
scrollHeight: 1_000,
}),
).toBe(true);
});
it("returns false when the user is meaningfully above the bottom", () => {
expect(
isScrollContainerNearBottom({
scrollTop: 520,
clientHeight: 400,
scrollHeight: 1_000,
}),
).toBe(false);
});
it("clamps negative thresholds to zero", () => {
expect(
isScrollContainerNearBottom(
{
scrollTop: 539,
clientHeight: 400,
scrollHeight: 1_000,
},
-1,
),
).toBe(false);
});
it("falls back to the default threshold for non-finite values", () => {
expect(
isScrollContainerNearBottom(
{
scrollTop: 540,
clientHeight: 400,
scrollHeight: 1_000,
},
Number.NaN,
),
).toBe(true);
expect(AUTO_SCROLL_BOTTOM_THRESHOLD_PX).toBe(64);
});
});