@@ -13,6 +13,7 @@ var click = require('../assets/click');
13
13
var delay = require ( '../assets/delay' ) ;
14
14
var doubleClick = require ( '../assets/double_click' ) ;
15
15
var failTest = require ( '../assets/fail_test' ) ;
16
+ var touchEvent = require ( '../assets/touch_event' ) ;
16
17
17
18
var customAssertions = require ( '../assets/custom_assertions' ) ;
18
19
var assertHoverLabelStyle = customAssertions . assertHoverLabelStyle ;
@@ -21,6 +22,20 @@ var assertElemRightTo = customAssertions.assertElemRightTo;
21
22
var assertElemTopsAligned = customAssertions . assertElemTopsAligned ;
22
23
var assertElemInside = customAssertions . assertElemInside ;
23
24
25
+ function touch ( path , options ) {
26
+ var len = path . length ;
27
+ Lib . clearThrottle ( ) ;
28
+ touchEvent ( 'touchstart' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , options ) ;
29
+
30
+ path . slice ( 1 , len ) . forEach ( function ( pt ) {
31
+ Lib . clearThrottle ( ) ;
32
+ touchEvent ( 'touchmove' , pt [ 0 ] , pt [ 1 ] , options ) ;
33
+ } ) ;
34
+
35
+ touchEvent ( 'touchend' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , options ) ;
36
+ return ;
37
+ }
38
+
24
39
describe ( 'hover info' , function ( ) {
25
40
'use strict' ;
26
41
@@ -2503,3 +2518,43 @@ describe('hovermode defaults to', function() {
2503
2518
. then ( done ) ;
2504
2519
} ) ;
2505
2520
} ) ;
2521
+
2522
+
2523
+ describe ( 'touch devices' , function ( ) {
2524
+ afterEach ( destroyGraphDiv ) ;
2525
+
2526
+ [ 'pan' , 'zoom' ] . forEach ( function ( type ) {
2527
+ describe ( 'dragmode:' + type , function ( ) {
2528
+ var data = [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 3 , 2 ] , type : 'bar' } ] ;
2529
+ var layout = { width : 600 , height : 400 , dragmode : type } ;
2530
+ var gd ;
2531
+
2532
+ beforeEach ( function ( done ) {
2533
+ gd = createGraphDiv ( ) ;
2534
+ Plotly . plot ( gd , data , layout ) . then ( done ) ;
2535
+ } ) ;
2536
+
2537
+ it ( 'emits click events' , function ( done ) {
2538
+ var hoverHandler = jasmine . createSpy ( 'hover' ) ;
2539
+ var clickHandler = jasmine . createSpy ( 'click' ) ;
2540
+ gd . on ( 'plotly_hover' , hoverHandler ) ;
2541
+ gd . on ( 'plotly_click' , clickHandler ) ;
2542
+
2543
+ var gdBB = gd . getBoundingClientRect ( ) ;
2544
+ var touchPoint = [ [ gdBB . left + 300 , gdBB . top + 200 ] ] ;
2545
+
2546
+ Promise . resolve ( )
2547
+ . then ( function ( ) {
2548
+ touch ( touchPoint ) ;
2549
+ } )
2550
+ . then ( delay ( HOVERMINTIME * 1.1 ) )
2551
+ . then ( function ( ) {
2552
+ expect ( clickHandler ) . toHaveBeenCalled ( ) ;
2553
+ expect ( hoverHandler ) . not . toHaveBeenCalled ( ) ;
2554
+ } )
2555
+ . catch ( failTest )
2556
+ . then ( done ) ;
2557
+ } ) ;
2558
+ } ) ;
2559
+ } ) ;
2560
+ } ) ;
0 commit comments