@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
99var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1010var fail = require ( '../assets/fail_test' ) ;
1111var mouseEvent = require ( '../assets/mouse_event' ) ;
12+ var touchEvent = require ( '../assets/touch_event' ) ;
1213var selectButton = require ( '../assets/modebar_button' ) ;
1314var delay = require ( '../assets/delay' ) ;
1415
@@ -651,26 +652,88 @@ describe('Test gl3d modebar handlers', function() {
651652} ) ;
652653
653654describe ( 'Test gl3d drag and wheel interactions' , function ( ) {
654- var gd , relayoutCallback ;
655+ var gd ;
655656
656- function scroll ( target ) {
657+ function scroll ( target , amt ) {
657658 return new Promise ( function ( resolve ) {
658- target . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : 1 } ) ) ;
659+ target . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : amt || 1 , cancelable : true } ) ) ;
659660 setTimeout ( resolve , 0 ) ;
660661 } ) ;
661662 }
662663
663- function drag ( target ) {
664+ function drag ( target , start , end ) {
664665 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 } ) ;
668669 setTimeout ( resolve , 0 ) ;
669670 } ) ;
670671 }
671672
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 ( ) {
673683 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 ;
674737
675738 var mock = {
676739 data : [
@@ -684,31 +747,23 @@ describe('Test gl3d drag and wheel interactions', function() {
684747 } ;
685748
686749 Plotly . plot ( gd , mock )
687- . then ( delay ( 20 ) )
688750 . then ( function ( ) {
689751 relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
690752 gd . on ( 'plotly_relayout' , relayoutCallback ) ;
691- } )
692- . then ( done ) ;
693- } ) ;
694753
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' ) ;
704757 sceneTarget2 = gd . querySelector ( '.svg-container .gl-container #scene2 canvas' ) ;
705758
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 } ) ;
710763
711- scroll ( sceneTarget ) . then ( function ( ) {
764+ return scroll ( sceneTarget ) ;
765+ } )
766+ . then ( function ( ) {
712767 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
713768 relayoutCallback . calls . reset ( ) ;
714769
@@ -718,13 +773,13 @@ describe('Test gl3d drag and wheel interactions', function() {
718773 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
719774 relayoutCallback . calls . reset ( ) ;
720775
721- return drag ( sceneTarget2 ) ;
776+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
722777 } )
723778 . then ( function ( ) {
724779 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
725780 relayoutCallback . calls . reset ( ) ;
726781
727- return drag ( sceneTarget ) ;
782+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
728783 } )
729784 . then ( function ( ) {
730785 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -739,10 +794,10 @@ describe('Test gl3d drag and wheel interactions', function() {
739794 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
740795 relayoutCallback . calls . reset ( ) ;
741796
742- return drag ( sceneTarget ) ;
797+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
743798 } )
744799 . then ( function ( ) {
745- return drag ( sceneTarget2 ) ;
800+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
746801 } )
747802 . then ( function ( ) {
748803 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -756,14 +811,15 @@ describe('Test gl3d drag and wheel interactions', function() {
756811 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
757812 relayoutCallback . calls . reset ( ) ;
758813
759- return drag ( sceneTarget ) ;
814+ return drag ( sceneTarget , [ 0 , 0 ] , [ 100 , 100 ] ) ;
760815 } )
761816 . then ( function ( ) {
762- return drag ( sceneTarget2 ) ;
817+ return drag ( sceneTarget2 , [ 0 , 0 ] , [ 100 , 100 ] ) ;
763818 } )
764819 . then ( function ( ) {
765820 expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 2 ) ;
766821 } )
822+ . catch ( fail )
767823 . then ( done ) ;
768824 } ) ;
769825} ) ;
0 commit comments