@@ -10,7 +10,7 @@ describe('Scroll helper', () => {
1010 innerWidth : 0 ,
1111 scrollBy : ( ) => {
1212 }
13- }
13+ } as any
1414 } ;
1515 let scrollSpy : SpyObj < any > ;
1616
@@ -21,57 +21,65 @@ describe('Scroll helper', () => {
2121
2222 describe ( 'Top scroll' , ( ) => {
2323
24- it ( 'should scroll to the top with the default scroll speed when we drag over the top viewport' , ( ) => {
25- const element = {
26- getBoundingClientRect : ( ) => ( { top : - 100 , left : 0 , bottom : 0 , right : 0 } )
27- } as any ;
28- sut . scrollIfNecessary ( element ) ;
24+ it ( `should scroll to the top with the default scroll speed when we drag over
25+ the top viewport + scroll buffer` , ( ) => {
26+ documentMock . defaultView . scrollY = 0 ;
27+ const event = {
28+ pageY : 40
29+ } ;
30+ sut . scrollIfNecessary ( event ) ;
2931 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : - 50 , behavior : 'smooth' } ) ;
3032 } ) ;
3133
3234 it ( 'should scroll to the top with the default scroll speed when we drag over the top scroll position' , ( ) => {
33- const element = {
34- getBoundingClientRect : ( ) => ( { top : 120 , left : 0 , bottom : 0 , right : 0 } )
35- } as any ;
36- sut . scrollIfNecessary ( element , { top : 140 } ) ;
35+ documentMock . defaultView . scrollY = 0 ;
36+ const event = {
37+ pageY : 110
38+ } ;
39+ sut . scrollIfNecessary ( event , { top : 140 } ) ;
3740 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : - 50 , behavior : 'smooth' } ) ;
3841 } ) ;
3942
4043 it ( 'should scroll to the top with the custom scroll speed when we drag over the top viewport' , ( ) => {
41- const element = {
42- getBoundingClientRect : ( ) => ( { top : - 100 , left : 0 , bottom : 0 , right : 0 } )
43- } as any ;
44+ documentMock . defaultView . scrollY = 0 ;
45+ const event = {
46+ pageY : 40
47+ } ;
4448 const scrollSpeed = 100 ;
45- sut . scrollIfNecessary ( element , { } , scrollSpeed ) ;
49+ sut . scrollIfNecessary ( event , { } , scrollSpeed ) ;
4650 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : - scrollSpeed , behavior : 'smooth' } ) ;
4751 } ) ;
4852
4953 } ) ;
5054
5155 describe ( 'Bottom scroll' , ( ) => {
5256
53- it ( 'should scroll to the bottom with the default scroll speed when we drag over the bottom viewport' , ( ) => {
54- const element = {
55- getBoundingClientRect : ( ) => ( { top : 100 , left : 0 , bottom : 20 , right : 0 } )
56- } as any ;
57- sut . scrollIfNecessary ( element ) ;
57+ it ( 'should scroll to the bottom with the default scroll speed when we drag over the bottom viewport - scroll buffer' , ( ) => {
58+ documentMock . defaultView . scrollY = 0 ;
59+ documentMock . defaultView . innerHeight = 100 ;
60+ const event = {
61+ pageY : 80
62+ } ;
63+ sut . scrollIfNecessary ( event ) ;
5864 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : 50 , behavior : 'smooth' } ) ;
5965 } ) ;
6066
6167 it ( 'should scroll to the bottom with the default scroll speed when we drag over the bottom scroll position' , ( ) => {
62- const element = {
63- getBoundingClientRect : ( ) => ( { top : 120 , left : 0 , bottom : 200 , right : 0 } )
64- } as any ;
65- sut . scrollIfNecessary ( element , { bottom : 140 } ) ;
68+ documentMock . defaultView . scrollY = 0 ;
69+ const event = {
70+ pageY : 141
71+ } ;
72+ sut . scrollIfNecessary ( event , { bottom : 140 } ) ;
6673 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : 50 , behavior : 'smooth' } ) ;
6774 } ) ;
6875
6976 it ( 'should scroll to the top with the custom scroll speed when we drag over the top viewport' , ( ) => {
70- const element = {
71- getBoundingClientRect : ( ) => ( { top : 20 , left : 0 , bottom : 20 , right : 0 } )
72- } as any ;
77+ documentMock . defaultView . scrollY = 0 ;
78+ const event = {
79+ pageY : 110
80+ } ;
7381 const scrollSpeed = 100 ;
74- sut . scrollIfNecessary ( element , { } , scrollSpeed ) ;
82+ sut . scrollIfNecessary ( event , { } , scrollSpeed ) ;
7583 expect ( scrollSpy ) . toHaveBeenCalledWith ( { top : scrollSpeed , behavior : 'smooth' } ) ;
7684 } ) ;
7785
0 commit comments