@@ -32,6 +32,8 @@ module('Unit | Radar Utils | Scroll Handler');
3232
3333test ( 'We can add, trigger, and remove a scroll handler' , ( assert ) => {
3434 let scrollHandlers = new ScrollHandler ( ) ;
35+ scrollHandlers . isUsingPassive = true ;
36+
3537 let done = assert . async ( 2 ) ;
3638 let scrollable = createScrollable ( ) ;
3739 let handler = ( ) => {
@@ -44,31 +46,81 @@ test('We can add, trigger, and remove a scroll handler', (assert) => {
4446 // test adding a single handler
4547 scrollHandlers . addScrollHandler ( scrollable , handler ) ;
4648
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' ) ;
4851
4952 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.` ) ;
5154 let cache = scrollHandlers . handlers [ scrollableIndex ] ;
52- assert . ok ( cache . handlers . length === 1 ) ;
55+ assert . strictEqual ( cache . handlers . length , 1 ) ;
5356
5457 // 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` ) ;
5659
5760 afterNextScrollUpdate ( ( ) => {
5861 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` ) ;
6063
6164 afterNextScrollUpdate ( ( ) => {
6265 // test removing that handler
6366 scrollHandlers . removeScrollHandler ( scrollable , handler ) ;
6467 let newScrollableIndex = scrollHandlers . elements . indexOf ( scrollable ) ;
6568
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.` ) ;
6972
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.` ) ;
72124
73125 destroyScrollable ( scrollable ) ;
74126 done ( ) ;
@@ -125,7 +177,6 @@ test('Adding/removing multiple handlers to an element works as expected', (asser
125177 assert . ok ( scrollHandlers . handlers . indexOf ( cache ) === - 1 , `Removing the last handler removed the cache.` ) ;
126178
127179 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.` ) ;
129180
130181 destroyScrollable ( scrollable ) ;
131182 done ( ) ;
@@ -192,7 +243,6 @@ test('Multiple elements with handlers works as expected', (assert) => {
192243 assert . ok ( scrollHandlers . handlers . indexOf ( cache2 ) === - 1 , `Removing the last handler removed the cache.` ) ;
193244
194245 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.` ) ;
196246
197247 destroyScrollable ( scrollable1 ) ;
198248 destroyScrollable ( scrollable2 ) ;
@@ -253,8 +303,6 @@ test('multiple handlers with same scrollable', (assert) => {
253303 assert . strictEqual ( scrollHandlers . length , 0 , `We have no more elements to watch.` ) ;
254304 assert . strictEqual ( cache1 . handlers . length , 0 , `The last handler was removed from the listener cache.` ) ;
255305
256- assert . false ( scrollHandlers . isPolling , `We are no longer polling the elements.` ) ;
257-
258306 destroyScrollable ( scrollable ) ;
259307 done ( ) ;
260308 } ) ;
0 commit comments