11var Plotly = require ( '@lib/index' ) ;
22var Lib = require ( '@src/lib' ) ;
3+ var Drawing = require ( '@src/components/drawing' ) ;
34var constants = require ( '@src/components/legend/constants' ) ;
45var DBLCLICKDELAY = require ( '@src/plot_api/plot_config' ) . dfltConfig . doubleClickDelay ;
56
@@ -9,6 +10,7 @@ var destroyGraph = require('../assets/destroy_graph_div');
910var failTest = require ( '../assets/fail_test' ) ;
1011var getBBox = require ( '../assets/get_bbox' ) ;
1112var mouseEvent = require ( '../assets/mouse_event' ) ;
13+ var touchEvent = require ( '../assets/touch_event' ) ;
1214var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
1315
1416describe ( 'The legend' , function ( ) {
@@ -169,6 +171,56 @@ describe('The legend', function() {
169171 'translate(0, ' + - dataScroll + ')' ) ;
170172 } ) ;
171173
174+ it ( 'should handle touch events on scrollbox' , function ( done ) {
175+ var scrollBox = getScrollBox ( ) ;
176+ var x = 637 ;
177+ var y0 = 140 ;
178+ var y1 = 200 ;
179+ var opts = { element : scrollBox } ;
180+
181+ spyOn ( Drawing , 'setRect' ) ;
182+
183+ // N.B. sometimes the touch start/move/end don't trigger a drag for
184+ // some obscure reason, for more details see
185+ // https://github.com/plotly/plotly.js/pull/3873#issuecomment-519686050
186+ for ( var i = 0 ; i < 20 ; i ++ ) {
187+ touchEvent ( 'touchstart' , x , y0 , opts ) ;
188+ touchEvent ( 'touchmove' , x , y0 , opts ) ;
189+ touchEvent ( 'touchmove' , x , y1 , opts ) ;
190+ touchEvent ( 'touchend' , x , y1 , opts ) ;
191+ }
192+
193+ setTimeout ( function ( ) {
194+ expect ( Drawing . setRect ) . toHaveBeenCalled ( ) ;
195+ done ( ) ;
196+ } , 100 ) ;
197+ } ) ;
198+
199+ it ( 'should handle touch events on scrollbar' , function ( done ) {
200+ var scrollBox = getScrollBar ( ) ;
201+ var x = 691 ;
202+ var y0 = 140 ;
203+ var y1 = 200 ;
204+ var opts = { element : scrollBox } ;
205+
206+ spyOn ( Drawing , 'setRect' ) ;
207+
208+ // N.B. sometimes the touch start/move/end don't trigger a drag for
209+ // some obscure reason, for more details see
210+ // https://github.com/plotly/plotly.js/pull/3873#issuecomment-519686050
211+ for ( var i = 0 ; i < 20 ; i ++ ) {
212+ touchEvent ( 'touchstart' , x , y0 , opts ) ;
213+ touchEvent ( 'touchmove' , x , y0 , opts ) ;
214+ touchEvent ( 'touchmove' , x , y1 , opts ) ;
215+ touchEvent ( 'touchend' , x , y1 , opts ) ;
216+ }
217+
218+ setTimeout ( function ( ) {
219+ expect ( Drawing . setRect ) . toHaveBeenCalled ( ) ;
220+ done ( ) ;
221+ } , 100 ) ;
222+ } ) ;
223+
172224 it ( 'should not scroll on dragging the scrollbar with a right click' , function ( ) {
173225 var finalDataScroll = dragScroll ( getScrollBar ( ) , true ) ;
174226 var scrollBox = getScrollBox ( ) ;
0 commit comments