88 * See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99*/
1010
11- import scrollLock from 'docc-render/utils/scroll-lock' ;
11+ import scrollLock , { SCROLL_LOCK_DISABLE_ATTR } from 'docc-render/utils/scroll-lock' ;
1212import { createEvent , parseHTMLString } from '../../../test-utils' ;
1313
1414const { platform } = window . navigator ;
@@ -56,6 +56,9 @@ describe('scroll-lock', () => {
5656 preventDefault,
5757 stopPropagation,
5858 touches : [ 1 ] ,
59+ target : {
60+ closest : jest . fn ( ) ,
61+ } ,
5962 } ;
6063 // init the scroll lock
6164 scrollLock . lockScroll ( container ) ;
@@ -67,6 +70,8 @@ describe('scroll-lock', () => {
6770 container . ontouchmove ( touchMoveEvent ) ;
6871 expect ( preventDefault ) . toHaveBeenCalledTimes ( 1 ) ;
6972 expect ( stopPropagation ) . toHaveBeenCalledTimes ( 0 ) ;
73+ expect ( touchMoveEvent . target . closest ) . toHaveBeenCalledTimes ( 1 ) ;
74+ expect ( touchMoveEvent . target . closest ) . toHaveBeenCalledWith ( `[${ SCROLL_LOCK_DISABLE_ATTR } ]` ) ;
7075
7176 // simulate scroll middle
7277 // simulate we have enough to scroll
@@ -81,6 +86,21 @@ describe('scroll-lock', () => {
8186 expect ( preventDefault ) . toHaveBeenCalledTimes ( 2 ) ;
8287 expect ( stopPropagation ) . toHaveBeenCalledTimes ( 1 ) ;
8388
89+ // simulate there is a scroll-lock-disable target
90+ container . ontouchmove ( {
91+ ...touchMoveEvent ,
92+ targetTouches : [ { clientY : - 10 } ] ,
93+ target : {
94+ closest : jest . fn ( ) . mockReturnValue ( {
95+ ...container ,
96+ clientHeight : 150 ,
97+ } ) ,
98+ } ,
99+ } ) ;
100+ // assert scrolling was allowed
101+ expect ( preventDefault ) . toHaveBeenCalledTimes ( 2 ) ;
102+ expect ( stopPropagation ) . toHaveBeenCalledTimes ( 2 ) ;
103+
84104 scrollLock . unlockScroll ( container ) ;
85105 expect ( container . ontouchmove ) . toBeFalsy ( ) ;
86106 expect ( container . ontouchstart ) . toBeFalsy ( ) ;
0 commit comments