Skip to content

Commit

Permalink
feat(reconnect): add layout in postExecute
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Apr 9, 2019
1 parent 4c8d3d6 commit ab64363
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
26 changes: 23 additions & 3 deletions lib/features/modeling/cmd/ReconnectConnectionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { isArray } from 'min-dash';
/**
* Reconnect connection handler
*/
export default function ReconnectConnectionHandler() { }
export default function ReconnectConnectionHandler(modeling) {
this._modeling = modeling;
}

ReconnectConnectionHandler.$inject = [ ];
ReconnectConnectionHandler.$inject = [ 'modeling' ];

ReconnectConnectionHandler.prototype.execute = function(context) {

Expand Down Expand Up @@ -50,6 +52,17 @@ ReconnectConnectionHandler.prototype.execute = function(context) {
return connection;
};

ReconnectConnectionHandler.prototype.postExecute = function(context) {
var connection = context.connection,
connectionStart = getDocking(connection.waypoints[0]),
connectionEnd = getDocking(connection.waypoints[connection.waypoints.length - 1]);

this._modeling.layoutConnection(connection, {
connectionStart: connectionStart,
connectionEnd: connectionEnd
});
};

ReconnectConnectionHandler.prototype.revert = function(context) {

var newSource = context.newSource,
Expand All @@ -67,4 +80,11 @@ ReconnectConnectionHandler.prototype.revert = function(context) {
connection.waypoints = context.oldWaypoints;

return connection;
};
};



// helper ///////////////
function getDocking(point) {
return point.original || point;
}
4 changes: 3 additions & 1 deletion test/spec/features/bendpoints/BendpointsMoveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ describe('features/bendpoints - move', function() {
dragging.end();

// then
expect(connection.waypoints[2]).to.eql({ x: 530, y: 120 });
var waypoints = connection.waypoints;

expect(waypoints[waypoints.length - 1]).to.eql({ x: 530, y: 120 });
}));


Expand Down
35 changes: 33 additions & 2 deletions test/spec/features/modeling/ReconnectConnectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

import modelingModule from 'lib/features/modeling';

/* global sinon */

describe('features/modeling - reconnect connection', function() {

Expand Down Expand Up @@ -49,6 +50,8 @@ describe('features/modeling - reconnect connection', function() {
canvas.addConnection(connection, parentShape);
}));

afterEach(sinon.restore);


describe('reconnectStart', function() {

Expand All @@ -57,7 +60,7 @@ describe('features/modeling - reconnect connection', function() {
it('should execute', inject(function(modeling) {

// given
var newWaypoints = [ { x: 120, y: 120 }, { x: 150, y: 200 }, { x: 350, y: 150 } ];
var newWaypoints = [ { x: 120, y: 120 }, { x: 350, y: 150 } ];

// when
modeling.reconnectStart(connection, childShape, { x: 120, y: 120 });
Expand All @@ -81,6 +84,20 @@ describe('features/modeling - reconnect connection', function() {
expect(connection.waypoints).to.eql(oldWaypoints);
}));


it('should layout connection', inject(function(modeling) {

// given
var layoutSpy = sinon.spy(modeling, 'layoutConnection');

// when
modeling.reconnectStart(connection, childShape, { x: 120, y: 120 });

// then
expect(layoutSpy).to.have.been.calledOnce;

}));

});


Expand Down Expand Up @@ -125,7 +142,7 @@ describe('features/modeling - reconnect connection', function() {
it('should execute', inject(function(modeling) {

// given
var newWaypoints = [ { x: 150, y: 150 }, { x: 150, y: 200 }, { x: 300, y: 100 } ];
var newWaypoints = [ { x: 150, y: 150 }, { x: 300, y: 100 } ];

// when
modeling.reconnectEnd(connection, childShape2, { x: 300, y: 100 });
Expand All @@ -149,6 +166,20 @@ describe('features/modeling - reconnect connection', function() {
expect(connection.waypoints).to.eql(oldWaypoints);
}));


it('should layout connection', inject(function(modeling) {

// given
var layoutSpy = sinon.spy(modeling, 'layoutConnection');

// when
modeling.reconnectEnd(connection, childShape, { x: 120, y: 120 });

// then
expect(layoutSpy).to.have.been.calledOnce;

}));

});


Expand Down

0 comments on commit ab64363

Please sign in to comment.