@@ -14,6 +14,7 @@ var customMatchers = require('../assets/custom_matchers');
14
14
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
15
15
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
16
16
var failTest = require ( '../assets/fail_test' ) ;
17
+ var drag = require ( '../assets/drag' ) ;
17
18
18
19
19
20
describe ( 'Test shapes defaults:' , function ( ) {
@@ -748,7 +749,7 @@ describe('Test shapes', function() {
748
749
749
750
var initialCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
750
751
751
- return resize ( direction , node , dx , dy ) . then ( function ( ) {
752
+ return drag ( node , dx , dy , direction ) . then ( function ( ) {
752
753
var finalCoordinates = getShapeCoordinates ( layoutShape , x2p , y2p ) ;
753
754
754
755
var keyN , keyS , keyW , keyE ;
@@ -815,118 +816,3 @@ describe('Test shapes', function() {
815
816
return coordinates ;
816
817
}
817
818
} ) ;
818
-
819
- var DBLCLICKDELAY = require ( '@src/plots/cartesian/constants' ) . DBLCLICKDELAY ;
820
-
821
- function mouseDown ( node , x , y ) {
822
- node . dispatchEvent ( new MouseEvent ( 'mousedown' , {
823
- bubbles : true ,
824
- clientX : x ,
825
- clientY : y
826
- } ) ) ;
827
- }
828
-
829
- function mouseMove ( node , x , y ) {
830
- node . dispatchEvent ( new MouseEvent ( 'mousemove' , {
831
- bubbles : true ,
832
- clientX : x ,
833
- clientY : y
834
- } ) ) ;
835
- }
836
-
837
- function mouseUp ( node , x , y ) {
838
- node . dispatchEvent ( new MouseEvent ( 'mouseup' , {
839
- bubbles : true ,
840
- clientX : x ,
841
- clientY : y
842
- } ) ) ;
843
- }
844
-
845
- function drag ( node , dx , dy ) {
846
- var bbox = node . getBoundingClientRect ( ) ,
847
- fromX = ( bbox . left + bbox . right ) / 2 ,
848
- fromY = ( bbox . bottom + bbox . top ) / 2 ,
849
- toX = fromX + dx ,
850
- toY = fromY + dy ;
851
-
852
- mouseMove ( node , fromX , fromY ) ;
853
- mouseDown ( node , fromX , fromY ) ;
854
-
855
- var promise = waitForDragCover ( ) . then ( function ( dragCoverNode ) {
856
- mouseMove ( dragCoverNode , toX , toY ) ;
857
- mouseUp ( dragCoverNode , toX , toY ) ;
858
- return waitForDragCoverRemoval ( ) ;
859
- } ) ;
860
-
861
- return promise ;
862
- }
863
-
864
- function resize ( direction , node , dx , dy ) {
865
- var bbox = node . getBoundingClientRect ( ) ;
866
-
867
- var fromX , fromY , toX , toY ;
868
-
869
- if ( ~ direction . indexOf ( 'n' ) ) fromY = bbox . top ;
870
- else if ( ~ direction . indexOf ( 's' ) ) fromY = bbox . bottom ;
871
- else fromY = ( bbox . bottom + bbox . top ) / 2 ;
872
-
873
- if ( ~ direction . indexOf ( 'w' ) ) fromX = bbox . left ;
874
- else if ( ~ direction . indexOf ( 'e' ) ) fromX = bbox . right ;
875
- else fromX = ( bbox . left + bbox . right ) / 2 ;
876
-
877
- toX = fromX + dx ;
878
- toY = fromY + dy ;
879
-
880
- mouseMove ( node , fromX , fromY ) ;
881
- mouseDown ( node , fromX , fromY ) ;
882
-
883
- var promise = waitForDragCover ( ) . then ( function ( dragCoverNode ) {
884
- mouseMove ( dragCoverNode , toX , toY ) ;
885
- mouseUp ( dragCoverNode , toX , toY ) ;
886
- return waitForDragCoverRemoval ( ) ;
887
- } ) ;
888
-
889
- return promise ;
890
- }
891
-
892
- function waitForDragCover ( ) {
893
- return new Promise ( function ( resolve ) {
894
- var interval = DBLCLICKDELAY / 4 ,
895
- timeout = 5000 ;
896
-
897
- var id = setInterval ( function ( ) {
898
- var dragCoverNode = d3 . selectAll ( '.dragcover' ) . node ( ) ;
899
- if ( dragCoverNode ) {
900
- clearInterval ( id ) ;
901
- resolve ( dragCoverNode ) ;
902
- }
903
-
904
- timeout -= interval ;
905
- if ( timeout < 0 ) {
906
- clearInterval ( id ) ;
907
- throw new Error ( 'waitForDragCover: timeout' ) ;
908
- }
909
- } , interval ) ;
910
- } ) ;
911
- }
912
-
913
- function waitForDragCoverRemoval ( ) {
914
- return new Promise ( function ( resolve ) {
915
- var interval = DBLCLICKDELAY / 4 ,
916
- timeout = 5000 ;
917
-
918
- var id = setInterval ( function ( ) {
919
- var dragCoverNode = d3 . selectAll ( '.dragcover' ) . node ( ) ;
920
- if ( ! dragCoverNode ) {
921
- clearInterval ( id ) ;
922
- resolve ( dragCoverNode ) ;
923
- }
924
-
925
- timeout -= interval ;
926
- if ( timeout < 0 ) {
927
- clearInterval ( id ) ;
928
- throw new Error ( 'waitForDragCoverRemoval: timeout' ) ;
929
- }
930
- } , interval ) ;
931
- } ) ;
932
- }
0 commit comments