@@ -14,6 +14,7 @@ var createGraphDiv = require('../assets/create_graph_div');
14
14
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
15
15
var failTest = require ( '../assets/fail_test' ) ;
16
16
var mouseEvent = require ( '../assets/mouse_event' ) ;
17
+ var getNodeCoords = require ( '../assets/get_node_coords' ) ;
17
18
var assertHoverLabelStyle = require ( '../assets/custom_assertions' ) . assertHoverLabelStyle ;
18
19
var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
19
20
var defaultColors = require ( '@src/components/color/attributes' ) . defaults ;
@@ -905,6 +906,57 @@ describe('sankey tests', function() {
905
906
} ) ;
906
907
} ) ;
907
908
909
+ describe ( 'Test drag interactions:' , function ( ) {
910
+ var gd ;
911
+
912
+ beforeEach ( function ( ) {
913
+ gd = createGraphDiv ( ) ;
914
+ } ) ;
915
+
916
+ afterEach ( destroyGraphDiv ) ;
917
+
918
+ function _drag ( fromX , fromY , dX , dY , delay ) {
919
+ var toX = fromX + dX ;
920
+ var toY = fromY + dY ;
921
+
922
+ return new Promise ( function ( resolve ) {
923
+ mouseEvent ( 'mousemove' , fromX , fromY ) ;
924
+ mouseEvent ( 'mousedown' , fromX , fromY ) ;
925
+ mouseEvent ( 'mousemove' , toX , toY ) ;
926
+
927
+ setTimeout ( function ( ) {
928
+ mouseEvent ( 'mouseup' , toX , toY ) ;
929
+ resolve ( ) ;
930
+ } , delay ) ;
931
+ } ) ;
932
+ }
933
+
934
+ it ( 'should change the position of a node' , function ( done ) {
935
+ var fig = Lib . extendDeep ( { } , mock ) ;
936
+ var nodes ;
937
+ var node ;
938
+ var position ;
939
+ var nodePos = [ 404 , 302 ] ;
940
+ var move = [ 0 , - 100 ] ;
941
+
942
+ Plotly . plot ( gd , fig )
943
+ . then ( function ( ) {
944
+ nodes = document . getElementsByClassName ( 'sankey-node' ) ;
945
+ node = nodes . item ( 4 ) ; // Selecting node with label 'Solid'
946
+ position = getNodeCoords ( node ) ;
947
+ return _drag ( nodePos [ 0 ] , nodePos [ 1 ] , move [ 0 ] , move [ 1 ] , 500 ) ;
948
+ } )
949
+ . then ( function ( ) {
950
+ nodes = document . getElementsByClassName ( 'sankey-node' ) ;
951
+ node = nodes . item ( nodes . length - 1 ) ; // Dragged node is now the last one
952
+ var newPosition = getNodeCoords ( node ) ;
953
+ expect ( newPosition . x ) . toBeCloseTo ( position . x + move [ 0 ] ) ;
954
+ expect ( newPosition . y ) . toBeCloseTo ( position . y + move [ 1 ] ) ;
955
+ } )
956
+ . catch ( failTest )
957
+ . then ( done ) ;
958
+ } ) ;
959
+ } ) ;
908
960
it ( 'emits a warning if node.pad is too large' , function ( done ) {
909
961
var gd = createGraphDiv ( ) ;
910
962
var mockCopy = Lib . extendDeep ( { } , mock ) ;
0 commit comments