FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tapper/tests/Unit/ScrollTest.php at master · tapperphp/tapper · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
tapperphp
/
tapper
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tapper
/
tests
/
Unit
/
ScrollTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
222 lines (173 loc) · 7.29 KB
Breadcrumbs
tapper
/
tests
/
Unit
/
ScrollTest.php
Copy path
File metadata and controls
222 lines (173 loc) · 7.29 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
declare
(strict_types=
1
);
use
Tapper
\
Console
\
State
\
AppState
;
use
Tapper
\
Console
\
Support
\
Scroll
;
beforeEach
(
function
() {
$
this
->
appState
=
new
AppState
;
$
this
->
scroll
=
new
Scroll
(
$
this
->
appState
);
});
describe
(
'
cursor movement
'
,
function
() {
it
(
'
cursor down
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
cursorDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
1
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
stops moving cursor at the end
'
,
function
() {
$
this
->
appState
->
cursor
=
9
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
cursorDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
9
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
5
);
});
it
(
'
move offset on cursor down
'
,
function
() {
$
this
->
appState
->
cursor
=
4
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
cursorDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
5
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
1
);
});
it
(
'
do not move cursor up if on top
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
cursorUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
0
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
move cursor up
'
,
function
() {
$
this
->
appState
->
cursor
=
1
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
cursorUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
0
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
do not move offset when cursor and offset is on bottom
'
,
function
() {
$
this
->
appState
->
cursor
=
9
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
cursorUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
8
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
5
);
});
it
(
'
move offset together with scroll
'
,
function
() {
$
this
->
appState
->
cursor
=
5
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
cursorUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
4
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
4
);
});
it
(
'
moves everything to bottom
'
,
function
() {
$
this
->
appState
->
cursor
=
5
;
$
this
->
appState
->
offset
=
2
;
$
this
->
scroll
->
scrollToBottom
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
9
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
5
);
});
});
describe
(
'
scroll movement
'
,
function
() {
it
(
'
scrolls down with cursor when on top
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
scrollDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
1
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
1
);
});
it
(
'
scrolls down but not move cursor if not on top
'
,
function
() {
$
this
->
appState
->
cursor
=
2
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
scrollDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
2
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
1
);
});
it
(
'
do not scroll if at the bottom
'
,
function
() {
$
this
->
appState
->
cursor
=
8
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
scrollDown
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
8
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
5
);
});
it
(
'
do not scroll if at the top
'
,
function
() {
$
this
->
appState
->
cursor
=
2
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
scrollUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
2
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
scrolls if in the middle
'
,
function
() {
$
this
->
appState
->
cursor
=
4
;
$
this
->
appState
->
offset
=
2
;
$
this
->
scroll
->
scrollUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
4
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
1
);
});
it
(
'
scrolls with cursor if on bottom
'
,
function
() {
$
this
->
appState
->
cursor
=
9
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
scrollUp
(count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
8
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
4
);
});
});
describe
(
'
scroll jumping
'
,
function
() {
it
(
'
jump to specific item
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
jump
(position:
2
, count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
2
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
moving offset up on jump
'
,
function
() {
$
this
->
appState
->
cursor
=
9
;
$
this
->
appState
->
offset
=
5
;
$
this
->
scroll
->
jump
(position:
2
, count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
2
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
2
);
});
it
(
'
moving offset down on jump
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
jump
(position:
7
, count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
7
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
3
);
});
it
(
'
jump to top if less than 0
'
,
function
() {
$
this
->
appState
->
cursor
=
4
;
$
this
->
appState
->
offset
=
2
;
$
this
->
scroll
->
jump
(position: -
2
, count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
0
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
0
);
});
it
(
'
jump to the end if more than count
'
,
function
() {
$
this
->
appState
->
cursor
=
0
;
$
this
->
appState
->
offset
=
0
;
$
this
->
scroll
->
jump
(position:
12
, count:
10
, visible:
5
);
expect
(
$
this
->
appState
->
cursor
)->
toBe
(
9
);
expect
(
$
this
->
appState
->
offset
)->
toBe
(
5
);
});
});
describe
(
'
proportional thumb
'
,
function
() {
it
(
'
returns null when everything already fits on screen
'
,
function
() {
expect
(Scroll::
proportionalThumb
(count:
5
, visible:
20
, offset:
0
, trackHeight:
20
))->
toBeNull
();
});
it
(
'
sizes the thumb against the true visible/count ratio, not scrollbarState
\'
s count-visible one
'
,
function
() {
// Regression: with count=13, visible=8, scrollbarState()'s contentLength is only
// 5 (count - visible), so feeding that into ScrollbarRenderer's size formula
// (viewport / contentLength) gives 8/5 > 1 — a thumb that fills the whole
// 8-row track even though barely more than half the content is visible.
[
$
start
,
$
end
] = Scroll::
proportionalThumb
(count:
13
, visible:
8
, offset:
0
, trackHeight:
8
);
expect
(
$
end
-
$
start
)->
toBe
((
int
)
round
((
8
/
13
) *
8
))
->
and
(
$
end
-
$
start
)->
toBeLessThan
(
8
);
});
it
(
'
starts the thumb at the top when offset is 0
'
,
function
() {
[
$
start
] = Scroll::
proportionalThumb
(count:
13
, visible:
8
, offset:
0
, trackHeight:
8
);
expect
(
$
start
)->
toBe
(
0
);
});
it
(
'
reaches the very bottom of the track at the max offset
'
,
function
() {
$
count
=
13
;
$
visible
=
8
;
$
trackHeight
=
8
;
$
maxOffset
=
$
count
-
$
visible
;
[,
$
end
] = Scroll::
proportionalThumb
(
$
count
,
$
visible
,
$
maxOffset
,
$
trackHeight
);
expect
(
$
end
)->
toBe
(
$
trackHeight
);
});
});
Back
|
FazBrowse Home
|
New Git URL