@@ -7,6 +7,7 @@ var Plotly = require('@lib/index');
7
7
var Lib = require ( '@src/lib' ) ;
8
8
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
9
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
10
+ var touchEvent = require ( '../assets/touch_event' ) ;
10
11
11
12
var delay = require ( '../assets/delay' ) ;
12
13
var assertPlotSize = require ( '../assets/custom_assertions' ) . assertPlotSize ;
@@ -507,6 +508,44 @@ describe('sliders interactions', function() {
507
508
. then ( done , done . fail ) ;
508
509
} ) ;
509
510
511
+ it ( 'should respond to touch interactions' , function ( done ) {
512
+ var firstGroup = gd . _fullLayout . _infolayer . select ( '.' + constants . railTouchRectClass ) ;
513
+ var firstGrip = gd . _fullLayout . _infolayer . select ( '.' + constants . gripRectClass ) ;
514
+ var railNode = firstGroup . node ( ) ;
515
+ var gripNode = firstGrip . node ( ) ;
516
+ var touchRect = railNode . getBoundingClientRect ( ) ;
517
+ var gripRect = gripNode . getBoundingClientRect ( ) ;
518
+
519
+ var originalFill = gripNode . style . fill ;
520
+
521
+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
522
+
523
+ // Dispatch start of touch where the grip control is
524
+ touchEvent ( 'touchstart' , gripRect . left + 5 , gripRect . top + 5 ) ;
525
+
526
+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
527
+ var touchdownFill = gripNode . style . fill ;
528
+ expect ( touchdownFill ) . not . toEqual ( originalFill ) ;
529
+
530
+ // Drag to the right side:
531
+ touchEvent ( 'touchmove' , touchRect . left + touchRect . width - 5 , gripRect . top + 5 ) ;
532
+
533
+ var touchmoveFill = gripNode . style . fill ;
534
+ expect ( touchmoveFill ) . toEqual ( touchdownFill ) ;
535
+
536
+ delay ( 100 ) ( )
537
+ . then ( function ( ) {
538
+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 5 ) ;
539
+
540
+ touchEvent ( 'touchend' , touchRect . left + touchRect . width - 5 , gripRect . top + 5 ) ;
541
+
542
+ var touchupFill = gripNode . style . fill ;
543
+ expect ( touchupFill ) . toEqual ( originalFill ) ;
544
+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 5 ) ;
545
+ } )
546
+ . then ( done , done . fail ) ;
547
+ } ) ;
548
+
510
549
it ( 'should issue events on interaction' , function ( done ) {
511
550
var cntStart = 0 ;
512
551
var cntInteraction = 0 ;
0 commit comments