1
1
var Plotly = require ( '@lib/index' ) ;
2
2
var Lib = require ( '@src/lib' ) ;
3
+ var Drawing = require ( '@src/components/drawing' ) ;
3
4
var constants = require ( '@src/components/legend/constants' ) ;
4
5
var DBLCLICKDELAY = require ( '@src/plot_api/plot_config' ) . dfltConfig . doubleClickDelay ;
5
6
@@ -9,6 +10,7 @@ var destroyGraph = require('../assets/destroy_graph_div');
9
10
var failTest = require ( '../assets/fail_test' ) ;
10
11
var getBBox = require ( '../assets/get_bbox' ) ;
11
12
var mouseEvent = require ( '../assets/mouse_event' ) ;
13
+ var touchEvent = require ( '../assets/touch_event' ) ;
12
14
var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
13
15
14
16
describe ( 'The legend' , function ( ) {
@@ -169,6 +171,56 @@ describe('The legend', function() {
169
171
'translate(0, ' + - dataScroll + ')' ) ;
170
172
} ) ;
171
173
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
+
172
224
it ( 'should not scroll on dragging the scrollbar with a right click' , function ( ) {
173
225
var finalDataScroll = dragScroll ( getScrollBar ( ) , true ) ;
174
226
var scrollBox = getScrollBox ( ) ;
0 commit comments