@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
9
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
10
10
var fail = require ( '../assets/fail_test' ) ;
11
11
var mouseEvent = require ( '../assets/mouse_event' ) ;
12
+ var touchEvent = require ( '../assets/touch_event' ) ;
12
13
var selectButton = require ( '../assets/modebar_button' ) ;
13
14
var delay = require ( '../assets/delay' ) ;
14
15
@@ -651,26 +652,88 @@ describe('Test gl3d modebar handlers', function() {
651
652
} ) ;
652
653
653
654
describe ( 'Test gl3d drag and wheel interactions' , function ( ) {
654
- var gd , relayoutCallback ;
655
+ var gd ;
655
656
656
- function scroll ( target ) {
657
+ function scroll ( target , amt ) {
657
658
return new Promise ( function ( resolve ) {
658
- target . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : 1 } ) ) ;
659
+ target . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : amt || 1 , cancelable : true } ) ) ;
659
660
setTimeout ( resolve , 0 ) ;
660
661
} ) ;
661
662
}
662
663
663
- function drag ( target ) {
664
+ function drag ( target , start , end ) {
664
665
return new Promise ( function ( resolve ) {
665
- target . dispatchEvent ( new MouseEvent ( 'mousedown' , { x : 0 , y : 0 } ) ) ;
666
- target . dispatchEvent ( new MouseEvent ( 'mousemove' , { x : 100 , y : 100 } ) ) ;
667
- target . dispatchEvent ( new MouseEvent ( 'mouseup' , { x : 100 , y : 100 } ) ) ;
666
+ mouseEvent ( 'mousedown' , start [ 0 ] , start [ 1 ] , { element : target } ) ;
667
+ mouseEvent ( 'mousemove' , end [ 0 ] , end [ 1 ] , { element : target } ) ;
668
+ mouseEvent ( 'mouseup' , end [ 0 ] , end [ 1 ] , { element : target } ) ;
668
669
setTimeout ( resolve , 0 ) ;
669
670
} ) ;
670
671
}
671
672
672
- beforeEach ( function ( done ) {
673
+ function touchDrag ( target , start , end ) {
674
+ return new Promise ( function ( resolve ) {
675
+ touchEvent ( 'touchstart' , start [ 0 ] , start [ 1 ] , { element : target } ) ;
676
+ touchEvent ( 'touchmove' , end [ 0 ] , end [ 1 ] , { element : target } ) ;
677
+ touchEvent ( 'touchend' , end [ 0 ] , end [ 1 ] , { element : target } ) ;
678
+ setTimeout ( resolve , 0 ) ;
679
+ } ) ;
680
+ }
681
+
682
+ beforeEach ( function ( ) {
673
683
gd = createGraphDiv ( ) ;
684
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 3000 ;
685
+ } ) ;
686
+
687
+ afterEach ( function ( ) {
688
+ Plotly . purge ( gd ) ;
689
+ destroyGraphDiv ( ) ;
690
+ } ) ;
691
+
692
+ it ( 'should not scroll document while panning' , function ( done ) {
693
+ var mock = {
694
+ data : [
695
+ { type : 'scatter3d' }
696
+ ] ,
697
+ layout : {
698
+ width : 500 ,
699
+ height : 500 ,
700
+ scene : { camera : { eye : { x : 0.1 , y : 0.1 , z : 1 } } }
701
+ }
702
+ } ;
703
+
704
+ var sceneTarget , relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
705
+
706
+ function assertEvent ( e ) {
707
+ expect ( e . defaultPrevented ) . toEqual ( true ) ;
708
+ relayoutCallback ( ) ;
709
+ }
710
+
711
+ gd . addEventListener ( 'touchend' , assertEvent ) ;
712
+ gd . addEventListener ( 'touchstart' , assertEvent ) ;
713
+ gd . addEventListener ( 'touchmove' , assertEvent ) ;
714
+ gd . addEventListener ( 'wheel' , assertEvent ) ;
715
+
716
+ Plotly . plot ( gd , mock )
717
+ . then ( function ( ) {
718
+ sceneTarget = gd . querySelector ( '.svg-container .gl-container #scene' ) ;
719
+
720
+ return touchDrag ( sceneTarget , [ 100 , 100 ] , [ 0 , 0 ] ) ;
721
+ } )
722
+ . then ( function ( ) {
723
+ return drag ( sceneTarget , [ 100 , 100 ] , [ 0 , 0 ] ) ;
724
+ } )
725
+ . then ( function ( ) {
726
+ return scroll ( sceneTarget ) ;
727
+ } )
728
+ . then ( function ( ) {
729
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 3 ) ;
730
+ } )
731
+ . catch ( fail )
732
+ . then ( done ) ;
733
+ } ) ;
734
+
735
+ it ( 'should update the scene camera' , function ( done ) {
736
+ var sceneLayout , sceneLayout2 , sceneTarget , sceneTarget2 , relayoutCallback ;
674
737
675
738
var mock = {
676
739
data : [
@@ -684,31 +747,23 @@ describe('Test gl3d drag and wheel interactions', function() {
684
747
} ;
685
748
686
749
Plotly . plot ( gd , mock )
687
- . then ( delay ( 20 ) )
688
750
. then ( function ( ) {
689
751
relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
690
752
gd . on ( 'plotly_relayout' , relayoutCallback ) ;
691
- } )
692
- . then ( done ) ;
693
- } ) ;
694
753
695
- afterEach ( function ( ) {
696
- Plotly . purge ( gd ) ;
697
- destroyGraphDiv ( ) ;
698
- } ) ;
699
-
700
- it ( 'should update the scene camera' , function ( done ) {
701
- var sceneLayout = gd . _fullLayout . scene ,
702
- sceneLayout2 = gd . _fullLayout . scene2 ,
703
- sceneTarget = gd . querySelector ( '.svg-container .gl-container #scene canvas' ) ,
754
+ sceneLayout = gd . _fullLayout . scene ;
755
+ sceneLayout2 = gd . _fullLayout . scene2 ;
756
+ sceneTarget = gd . querySelector ( '.svg-container .gl-container #scene canvas' ) ;
704
757
sceneTarget2 = gd . querySelector ( '.svg-container .gl-container #scene2 canvas' ) ;
705
758
706
- expect ( sceneLayout . camera . eye )
707
- . toEqual ( { x : 0.1 , y : 0.1 , z : 1 } ) ;
708
- expect ( sceneLayout2 . camera . eye )
709
- . toEqual ( { x : 2.5 , y : 2.5 , z : 2.5 } ) ;
759
+ expect ( sceneLayout . camera . eye )
760
+ . toEqual ( { x : 0.1 , y : 0.1 , z : 1 } ) ;
761
+ expect ( sceneLayout2 . camera . eye )
762
+ . toEqual ( { x : 2.5 , y : 2.5 , z : 2.5 } ) ;
710
763
711
- scroll ( sceneTarget ) . then ( function ( ) {
764
+ return scroll ( sceneTarget ) ;
765
+ } )
766
+ . then ( function ( ) {
712
767
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
713
768
relayoutCallback . calls . reset ( ) ;
714
769
@@ -718,13 +773,13 @@ describe('Test gl3d drag and wheel interactions', function() {
718
773
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
719
774
relayoutCallback . calls . reset ( ) ;
720
775
721
- return drag ( sceneTarget2 ) ;
776
+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
722
777
} )
723
778
. then ( function ( ) {
724
779
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
725
780
relayoutCallback . calls . reset ( ) ;
726
781
727
- return drag ( sceneTarget ) ;
782
+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
728
783
} )
729
784
. then ( function ( ) {
730
785
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -739,10 +794,10 @@ describe('Test gl3d drag and wheel interactions', function() {
739
794
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
740
795
relayoutCallback . calls . reset ( ) ;
741
796
742
- return drag ( sceneTarget ) ;
797
+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
743
798
} )
744
799
. then ( function ( ) {
745
- return drag ( sceneTarget2 ) ;
800
+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
746
801
} )
747
802
. then ( function ( ) {
748
803
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -756,14 +811,15 @@ describe('Test gl3d drag and wheel interactions', function() {
756
811
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
757
812
relayoutCallback . calls . reset ( ) ;
758
813
759
- return drag ( sceneTarget ) ;
814
+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
760
815
} )
761
816
. then ( function ( ) {
762
- return drag ( sceneTarget2 ) ;
817
+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
763
818
} )
764
819
. then ( function ( ) {
765
820
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 2 ) ;
766
821
} )
822
+ . catch ( fail )
767
823
. then ( done ) ;
768
824
} ) ;
769
825
} ) ;
0 commit comments