forked from kirillzyusko/react-native-keyboard-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblankSpace.spec.ts
More file actions
137 lines (117 loc) · 3.74 KB
/
blankSpace.spec.ts
File metadata and controls
137 lines (117 loc) · 3.74 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { sv } from "../../../../__fixtures__/sv";
import {
createRender,
flushRAF,
mockScrollTo,
reactionEffect,
} from "../__fixtures__/setup";
describe("useExtraContentPadding — blankSpace floor", () => {
it("should skip scroll when blankSpace fully absorbs the change", () => {
const render = createRender();
render({
extraContentPadding: sv(20),
keyboardPadding: sv(0),
blankSpace: sv(500),
scroll: sv(100),
layout: sv({ width: 390, height: 800 }),
size: sv({ width: 390, height: 2000 }),
inverted: false,
keyboardLiftBehavior: "always",
freeze: false,
});
// previousTotal = max(500, 0+0) = 500
// currentTotal = max(500, 0+20) = 500
// effectiveDelta = 0 → skip
reactionEffect(20, 0);
expect(mockScrollTo).not.toHaveBeenCalled();
});
it("should scroll by effective delta when blankSpace partially absorbs", async () => {
const render = createRender();
render({
extraContentPadding: sv(300),
keyboardPadding: sv(200),
blankSpace: sv(400),
scroll: sv(100),
layout: sv({ width: 390, height: 800 }),
size: sv({ width: 390, height: 2000 }),
inverted: false,
keyboardLiftBehavior: "always",
freeze: false,
});
// previousTotal = max(400, 200+0) = 400
// currentTotal = max(400, 200+300) = 500
// effectiveDelta = 100
// maxScroll = max(2000 - 800 + 500, 0) = 1700
// target = min(100 + 100, 1700) = 200
reactionEffect(300, 0);
await flushRAF();
expect(mockScrollTo).toHaveBeenCalledWith(expect.anything(), 0, 200, false);
});
it("blankSpace=0 produces identical behavior to default", async () => {
const render = createRender();
render({
extraContentPadding: sv(20),
keyboardPadding: sv(300),
blankSpace: sv(0),
scroll: sv(1200),
layout: sv({ width: 390, height: 800 }),
size: sv({ width: 390, height: 2000 }),
inverted: false,
keyboardLiftBehavior: "always",
freeze: false,
});
// previousTotal = max(0, 300+0) = 300
// currentTotal = max(0, 300+20) = 320
// effectiveDelta = 20
// maxScroll = max(2000 - 800 + 320, 0) = 1520
// target = min(1200 + 20, 1520) = 1220
reactionEffect(20, 0);
await flushRAF();
expect(mockScrollTo).toHaveBeenCalledWith(
expect.anything(),
0,
1220,
false,
);
});
it("should use currentTotal for inverted clamp", () => {
const render = createRender();
render({
extraContentPadding: sv(20),
keyboardPadding: sv(300),
blankSpace: sv(400),
scroll: sv(5),
layout: sv({ width: 390, height: 800 }),
size: sv({ width: 390, height: 2000 }),
inverted: true,
keyboardLiftBehavior: "always",
freeze: false,
});
// previousTotal = max(400, 300+0) = 400
// currentTotal = max(400, 300+20) = 400
// effectiveDelta = 0 → skip (blankSpace floor absorbs)
reactionEffect(20, 0);
expect(mockScrollTo).not.toHaveBeenCalled();
});
it("should scroll when change exceeds blankSpace floor (inverted)", async () => {
const render = createRender();
render({
extraContentPadding: sv(200),
keyboardPadding: sv(300),
blankSpace: sv(400),
scroll: sv(5),
layout: sv({ width: 390, height: 800 }),
size: sv({ width: 390, height: 2000 }),
inverted: true,
keyboardLiftBehavior: "always",
freeze: false,
});
// previousTotal = max(400, 300+0) = 400
// currentTotal = max(400, 300+200) = 500
// effectiveDelta = 100
// target = max(5 - 100, -500) = max(-95, -500) = -95
reactionEffect(200, 0);
await flushRAF();
expect(mockScrollTo).toHaveBeenCalledWith(expect.anything(), 0, -95, false);
});
});