Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

743 create connection preview #1009

Merged
merged 2 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/features/modeling/BpmnLayouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ inherits(BpmnLayouter, BaseLayouter);
BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
hints = hints || {};

var source = connection.source,
target = connection.target,
var source = hints.source || connection.source,
target = hints.target || connection.target,
waypoints = connection.waypoints,
start = hints.connectionStart,
end = hints.connectionEnd;
Expand All @@ -54,7 +54,7 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
if (is(connection, 'bpmn:Association') ||
is(connection, 'bpmn:DataAssociation')) {

if (waypoints && !isCompensationAssociation(connection)) {
if (waypoints && !isCompensationAssociation(source, target)) {
return [].concat([ start ], waypoints.slice(1, -1), [ end ]);
}
}
Expand All @@ -75,7 +75,7 @@ BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
// (3) loops from / to the same element
//
if (is(connection, 'bpmn:SequenceFlow') ||
isCompensationAssociation(connection)) {
isCompensationAssociation(source, target)) {

if (source === target) {
manhattanOptions = {
Expand Down Expand Up @@ -189,11 +189,7 @@ function getConnectionDocking(point, shape) {
return point ? (point.original || point) : getMid(shape);
}

function isCompensationAssociation(connection) {

var source = connection.source,
target = connection.target;

function isCompensationAssociation(source, target) {
return is(target, 'bpmn:Activity') &&
is(source, 'bpmn:BoundaryEvent') &&
target.businessObject.isForCompensation;
Expand Down
131 changes: 94 additions & 37 deletions test/spec/features/modeling/layout/LayoutConnectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
import createModule from 'diagram-js/lib/features/create';

import {
createCanvasEvent as canvasEvent
} from '../../../../util/MockEvents';


describe('features/modeling - layout connection', function() {
Expand All @@ -14,7 +19,8 @@ describe('features/modeling - layout connection', function() {
beforeEach(bootstrapModeler(diagramXML, {
modules: [
coreModule,
modelingModule
modelingModule,
createModule
]
}));

Expand Down Expand Up @@ -111,57 +117,108 @@ describe('features/modeling - layout connection', function() {

describe('integration', function() {

it('should correctly layout after start re-connection', inject(function(elementRegistry, modeling) {
describe('re-connection', function() {

// given
var task1 = elementRegistry.get('Task_1'),
connection = elementRegistry.get('SequenceFlow_1'),
docking = { x: 292, y: 376 };
it('should correctly layout after start re-connection', inject(function(elementRegistry, modeling) {

// when
modeling.reconnectStart(connection, task1, docking);
// given
var task1 = elementRegistry.get('Task_1'),
connection = elementRegistry.get('SequenceFlow_1'),
docking = { x: 292, y: 376 };

// then
var waypoints = connection.waypoints,
i,
first,
second;
// when
modeling.reconnectStart(connection, task1, docking);

for (i = 0; i < waypoints.length - 1; i++) {
first = waypoints[i];
second = waypoints[i + 1];
// then
var waypoints = connection.waypoints,
i,
first,
second;

expect(areOnSameAxis(first, second), 'points are on different axes').to.be.true;
}
for (i = 0; i < waypoints.length - 1; i++) {
first = waypoints[i];
second = waypoints[i + 1];

}));
expect(areOnSameAxis(first, second), 'points are on different axes').to.be.true;
}

}));

it('should correctly layout after end re-connection', inject(function(elementRegistry, modeling) {

// given
var task1 = elementRegistry.get('Task_1'),
connection = elementRegistry.get('SequenceFlow_1'),
docking = { x: 292, y: 376 };
it('should correctly layout after end re-connection', inject(function(elementRegistry, modeling) {

// when
modeling.reconnectEnd(connection, task1, docking);
// given
var task1 = elementRegistry.get('Task_1'),
connection = elementRegistry.get('SequenceFlow_1'),
docking = { x: 292, y: 376 };

// then
var waypoints = connection.waypoints,
i,
first,
second;
// when
modeling.reconnectEnd(connection, task1, docking);

for (i = 0; i < waypoints.length - 1; i++) {
first = waypoints[i];
second = waypoints[i + 1];
// then
var waypoints = connection.waypoints,
i,
first,
second;

expect(areOnSameAxis(first, second), 'points are on different axes').to.be.true;
}
for (i = 0; i < waypoints.length - 1; i++) {
first = waypoints[i];
second = waypoints[i + 1];

}));
expect(areOnSameAxis(first, second), 'points are on different axes').to.be.true;
}

}));

});


describe('connection preview', function() {

var task;

beforeEach(inject(function(elementFactory, dragging) {
task = elementFactory.createShape({
type: 'bpmn:Task'
});

dragging.setOptions({ manual: true });
}));

afterEach(inject(function(dragging) {
dragging.setOptions({ manual: false });
}));


it('should correctly lay out connection preview',
inject(function(canvas, create, dragging, elementRegistry) {

// given
var rootShape = canvas.getRootElement(),
rootShapeGfx = canvas.getGraphics(rootShape),
task1 = elementRegistry.get('Task_1');

// when
create.start(canvasEvent({ x: 0, y: 0 }), task, task1);

dragging.move(canvasEvent({ x: 175, y: 175 }));
dragging.hover({ element: rootShape, gfx: rootShapeGfx });
dragging.move(canvasEvent({ x: 200, y: 200 }));

var ctx = dragging.context();
var context = ctx.data.context;

var connectionPreview = context.getConnection(context.canExecute.connect);
var waypointsPreview = connectionPreview.waypoints.slice();

dragging.end();

// then
expect(task1.outgoing[0]).to.exist;
expect(task1.outgoing[0].waypoints).to.deep.eql(waypointsPreview);
})
);
});
});

});
Expand Down