@@ -595,6 +595,23 @@ describe('Test gl plot interactions', function() {
595
595
} ) ;
596
596
597
597
describe ( 'drag and wheel interactions' , function ( ) {
598
+
599
+ function scroll ( target ) {
600
+ return new Promise ( function ( resolve ) {
601
+ target . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : 1 } ) ) ;
602
+ setTimeout ( resolve , 0 ) ;
603
+ } ) ;
604
+ }
605
+
606
+ function drag ( target ) {
607
+ return new Promise ( function ( resolve ) {
608
+ target . dispatchEvent ( new MouseEvent ( 'mousedown' , { x : 0 , y : 0 } ) ) ;
609
+ target . dispatchEvent ( new MouseEvent ( 'mousemove' , { x : 100 , y : 100 } ) ) ;
610
+ target . dispatchEvent ( new MouseEvent ( 'mouseup' , { x : 100 , y : 100 } ) ) ;
611
+ setTimeout ( resolve , 0 ) ;
612
+ } ) ;
613
+ }
614
+
598
615
it ( 'should update the scene camera' , function ( done ) {
599
616
var sceneLayout = gd . _fullLayout . scene ,
600
617
sceneLayout2 = gd . _fullLayout . scene2 ,
@@ -606,37 +623,63 @@ describe('Test gl plot interactions', function() {
606
623
expect ( sceneLayout2 . camera . eye )
607
624
. toEqual ( { x : 2.5 , y : 2.5 , z : 2.5 } ) ;
608
625
609
- // Wheel scene 1
610
- sceneTarget . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : 1 } ) ) ;
611
-
612
- // Wheel scene 2
613
- sceneTarget2 . dispatchEvent ( new WheelEvent ( 'wheel' , { deltaY : 1 } ) ) ;
614
-
615
- setTimeout ( function ( ) {
616
-
617
- expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 2 ) ;
618
-
626
+ scroll ( sceneTarget ) . then ( function ( ) {
627
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
619
628
relayoutCallback . calls . reset ( ) ;
620
629
621
- // Drag scene 1
622
- sceneTarget . dispatchEvent ( new MouseEvent ( 'mousedown' , { x : 0 , y : 0 } ) ) ;
623
- sceneTarget . dispatchEvent ( new MouseEvent ( 'mousemove' , { x : 100 , y : 100 } ) ) ;
624
- sceneTarget . dispatchEvent ( new MouseEvent ( 'mouseup' , { x : 100 , y : 100 } ) ) ;
630
+ return scroll ( sceneTarget2 ) ;
631
+ } )
632
+ . then ( function ( ) {
633
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
634
+ relayoutCallback . calls . reset ( ) ;
625
635
626
- // Drag scene 2
627
- sceneTarget2 . dispatchEvent ( new MouseEvent ( 'mousedown' , { x : 0 , y : 0 } ) ) ;
628
- sceneTarget2 . dispatchEvent ( new MouseEvent ( 'mousemove' , { x : 100 , y : 100 } ) ) ;
629
- sceneTarget2 . dispatchEvent ( new MouseEvent ( 'mouseup' , { x : 100 , y : 100 } ) ) ;
636
+ return drag ( sceneTarget2 ) ;
637
+ } )
638
+ . then ( function ( ) {
639
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
640
+ relayoutCallback . calls . reset ( ) ;
630
641
631
- setTimeout ( function ( ) {
642
+ return drag ( sceneTarget ) ;
643
+ } )
644
+ . then ( function ( ) {
645
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
646
+ relayoutCallback . calls . reset ( ) ;
632
647
633
- expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 2 ) ;
648
+ return Plotly . relayout ( gd , {
649
+ 'scene.dragmode' : false ,
650
+ 'scene2.dragmode' : false
651
+ } ) ;
652
+ } )
653
+ . then ( function ( ) {
654
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
655
+ relayoutCallback . calls . reset ( ) ;
634
656
635
- done ( ) ;
657
+ return drag ( sceneTarget ) ;
658
+ } )
659
+ . then ( function ( ) {
660
+ return drag ( sceneTarget2 ) ;
661
+ } )
662
+ . then ( function ( ) {
663
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 0 ) ;
636
664
637
- } , MODEBAR_DELAY ) ;
665
+ return Plotly . relayout ( gd , {
666
+ 'scene.dragmode' : 'orbit' ,
667
+ 'scene2.dragmode' : 'turntable'
668
+ } ) ;
669
+ } )
670
+ . then ( function ( ) {
671
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
672
+ relayoutCallback . calls . reset ( ) ;
638
673
639
- } , MODEBAR_DELAY ) ;
674
+ return drag ( sceneTarget ) ;
675
+ } )
676
+ . then ( function ( ) {
677
+ return drag ( sceneTarget2 ) ;
678
+ } )
679
+ . then ( function ( ) {
680
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 2 ) ;
681
+ } )
682
+ . then ( done ) ;
640
683
} ) ;
641
684
} ) ;
642
685
} ) ;
0 commit comments