Skip to content

Commit 1f73366

Browse files
committed
sankey: test dragging node
1 parent 08e5a50 commit 1f73366

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/jasmine/tests/sankey_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var createGraphDiv = require('../assets/create_graph_div');
1414
var destroyGraphDiv = require('../assets/destroy_graph_div');
1515
var failTest = require('../assets/fail_test');
1616
var mouseEvent = require('../assets/mouse_event');
17+
var getNodeCoords = require('../assets/get_node_coords');
1718
var assertHoverLabelStyle = require('../assets/custom_assertions').assertHoverLabelStyle;
1819
var supplyAllDefaults = require('../assets/supply_defaults');
1920
var defaultColors = require('@src/components/color/attributes').defaults;
@@ -905,6 +906,57 @@ describe('sankey tests', function() {
905906
});
906907
});
907908

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+
});
908960
it('emits a warning if node.pad is too large', function(done) {
909961
var gd = createGraphDiv();
910962
var mockCopy = Lib.extendDeep({}, mock);

0 commit comments

Comments
 (0)