@@ -32,6 +32,8 @@ module('Unit | Radar Utils | Scroll Handler');
32
32
33
33
test ( 'We can add, trigger, and remove a scroll handler' , ( assert ) => {
34
34
let scrollHandlers = new ScrollHandler ( ) ;
35
+ scrollHandlers . isUsingPassive = true ;
36
+
35
37
let done = assert . async ( 2 ) ;
36
38
let scrollable = createScrollable ( ) ;
37
39
let handler = ( ) => {
@@ -44,31 +46,81 @@ test('We can add, trigger, and remove a scroll handler', (assert) => {
44
46
// test adding a single handler
45
47
scrollHandlers . addScrollHandler ( scrollable , handler ) ;
46
48
47
- assert . equal ( scrollHandlers . length , 1 , `We have one element to watch.` ) ;
49
+ assert . strictEqual ( scrollHandlers . length , 1 , `We have one element to watch.` ) ;
50
+ assert . false ( scrollHandlers . isPolling , 'polling is inactive, using a passive handler' ) ;
48
51
49
52
let scrollableIndex = scrollHandlers . elements . indexOf ( scrollable ) ;
50
- assert . ok ( scrollableIndex !== - 1 , `The scrollable was added to the watched elements list.` ) ;
53
+ assert . true ( scrollableIndex !== - 1 , `The scrollable was added to the watched elements list.` ) ;
51
54
let cache = scrollHandlers . handlers [ scrollableIndex ] ;
52
- assert . ok ( cache . handlers . length === 1 ) ;
55
+ assert . strictEqual ( cache . handlers . length , 1 ) ;
53
56
54
57
// test triggering that handler
55
- assert . equal ( scrollable . scrollTop , 0 , `The scrollable is initially unscrolled` ) ;
58
+ assert . strictEqual ( scrollable . scrollTop , 0 , `The scrollable is initially unscrolled` ) ;
56
59
57
60
afterNextScrollUpdate ( ( ) => {
58
61
scrollable . scrollTop = 10 ;
59
- assert . equal ( scrollable . scrollTop , 10 , `We updated the scrollable's scroll position` ) ;
62
+ assert . strictEqual ( scrollable . scrollTop , 10 , `We updated the scrollable's scroll position` ) ;
60
63
61
64
afterNextScrollUpdate ( ( ) => {
62
65
// test removing that handler
63
66
scrollHandlers . removeScrollHandler ( scrollable , handler ) ;
64
67
let newScrollableIndex = scrollHandlers . elements . indexOf ( scrollable ) ;
65
68
66
- assert . ok ( cache . handlers . length === 0 , `The handler was removed from the listener cache.` ) ;
67
- assert . ok ( newScrollableIndex === - 1 , `Removing the last handler removed the element from the watched elements list.` ) ;
68
- assert . ok ( scrollHandlers . handlers . indexOf ( cache ) === - 1 , `Removing the last handler removed the cache.` ) ;
69
+ assert . strictEqual ( cache . handlers . length , 0 , `The handler was removed from the listener cache.` ) ;
70
+ assert . strictEqual ( newScrollableIndex , - 1 , `Removing the last handler removed the element from the watched elements list.` ) ;
71
+ assert . strictEqual ( scrollHandlers . handlers . indexOf ( cache ) , - 1 , `Removing the last handler removed the cache.` ) ;
69
72
70
- assert . equal ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
71
- assert . equal ( scrollHandlers . isPolling , false , `We are no longer polling the elements.` ) ;
73
+ assert . strictEqual ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
74
+ assert . false ( scrollHandlers . isPolling , `polling is still inactive` ) ;
75
+
76
+ destroyScrollable ( scrollable ) ;
77
+ done ( ) ;
78
+ } ) ;
79
+ } ) ;
80
+ } ) ;
81
+
82
+ test ( 'Polling' , ( assert ) => {
83
+ let scrollHandlers = new ScrollHandler ( ) ;
84
+ scrollHandlers . isUsingPassive = false ;
85
+
86
+ let done = assert . async ( 2 ) ;
87
+ let scrollable = createScrollable ( ) ;
88
+ let handler = ( ) => {
89
+ assert . ok ( 'handler was triggered' ) ;
90
+ done ( ) ;
91
+ } ;
92
+
93
+ assert . strictEqual ( scrollHandlers . length , 0 , `We initially have no elements to watch.` ) ;
94
+
95
+ // test adding a single handler
96
+ scrollHandlers . addScrollHandler ( scrollable , handler ) ;
97
+
98
+ assert . strictEqual ( scrollHandlers . length , 1 , `We have one element to watch.` ) ;
99
+ assert . true ( scrollHandlers . isPolling , 'polling is active' ) ;
100
+
101
+ let scrollableIndex = scrollHandlers . elements . indexOf ( scrollable ) ;
102
+ assert . true ( scrollableIndex !== - 1 , `The scrollable was added to the watched elements list.` ) ;
103
+ let cache = scrollHandlers . handlers [ scrollableIndex ] ;
104
+ assert . strictEqual ( cache . handlers . length , 1 ) ;
105
+
106
+ // test triggering that handler
107
+ assert . strictEqual ( scrollable . scrollTop , 0 , `The scrollable is initially unscrolled` ) ;
108
+
109
+ afterNextScrollUpdate ( ( ) => {
110
+ scrollable . scrollTop = 10 ;
111
+ assert . strictEqual ( scrollable . scrollTop , 10 , `We updated the scrollable's scroll position` ) ;
112
+
113
+ afterNextScrollUpdate ( ( ) => {
114
+ // test removing that handler
115
+ scrollHandlers . removeScrollHandler ( scrollable , handler ) ;
116
+ let newScrollableIndex = scrollHandlers . elements . indexOf ( scrollable ) ;
117
+
118
+ assert . strictEqual ( cache . handlers . length , 0 , `The handler was removed from the listener cache.` ) ;
119
+ assert . strictEqual ( newScrollableIndex , - 1 , `Removing the last handler removed the element from the watched elements list.` ) ;
120
+ assert . strictEqual ( scrollHandlers . handlers . indexOf ( cache ) , - 1 , `Removing the last handler removed the cache.` ) ;
121
+
122
+ assert . strictEqual ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
123
+ assert . false ( scrollHandlers . isPolling , `We are no longer polling the elements.` ) ;
72
124
73
125
destroyScrollable ( scrollable ) ;
74
126
done ( ) ;
@@ -125,7 +177,6 @@ test('Adding/removing multiple handlers to an element works as expected', (asser
125
177
assert . ok ( scrollHandlers . handlers . indexOf ( cache ) === - 1 , `Removing the last handler removed the cache.` ) ;
126
178
127
179
assert . equal ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
128
- assert . equal ( scrollHandlers . isPolling , false , `We are no longer polling the elements.` ) ;
129
180
130
181
destroyScrollable ( scrollable ) ;
131
182
done ( ) ;
@@ -192,7 +243,6 @@ test('Multiple elements with handlers works as expected', (assert) => {
192
243
assert . ok ( scrollHandlers . handlers . indexOf ( cache2 ) === - 1 , `Removing the last handler removed the cache.` ) ;
193
244
194
245
assert . equal ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
195
- assert . equal ( scrollHandlers . isPolling , false , `We are no longer polling the elements.` ) ;
196
246
197
247
destroyScrollable ( scrollable1 ) ;
198
248
destroyScrollable ( scrollable2 ) ;
@@ -253,8 +303,6 @@ test('multiple handlers with same scrollable', (assert) => {
253
303
assert . strictEqual ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
254
304
assert . strictEqual ( cache1 . handlers . length , 0 , `The last handler was removed from the listener cache.` ) ;
255
305
256
- assert . false ( scrollHandlers . isPolling , `We are no longer polling the elements.` ) ;
257
-
258
306
destroyScrollable ( scrollable ) ;
259
307
done ( ) ;
260
308
} ) ;
0 commit comments