2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features/modeling - create connection', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/sequence-flows.bpmn');
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2014-10-30 11:06:43 +00:00
|
|
|
var testModules = [ coreModule, modelingModule ];
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
it('should connect', inject(function(elementRegistry, modeling, bpmnFactory) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var taskShape = elementRegistry.get('Task_1'),
|
|
|
|
task = taskShape.businessObject,
|
|
|
|
gatewayShape = elementRegistry.get('Gateway_1'),
|
|
|
|
gateway = gatewayShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var sequenceFlowConnection = modeling.createConnection(taskShape, gatewayShape, {
|
|
|
|
type: 'bpmn:SequenceFlow'
|
|
|
|
}, taskShape.parent);
|
|
|
|
|
|
|
|
var sequenceFlow = sequenceFlowConnection.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(sequenceFlowConnection).to.exist;
|
|
|
|
expect(sequenceFlow).to.exist;
|
|
|
|
|
|
|
|
expect(sequenceFlow.sourceRef).to.eql(task);
|
|
|
|
expect(sequenceFlow.targetRef).to.eql(gateway);
|
|
|
|
|
|
|
|
expect(task.outgoing).to.include(sequenceFlow);
|
|
|
|
expect(gateway.incoming).to.include(sequenceFlow);
|
|
|
|
|
|
|
|
expect(sequenceFlow.di.$parent).to.eql(task.di.$parent);
|
|
|
|
expect(sequenceFlow.di.$parent.planeElement).to.include(sequenceFlow.di);
|
|
|
|
|
|
|
|
// expect cropped connection
|
|
|
|
expect(sequenceFlowConnection.waypoints).eql([
|
|
|
|
{ original: { x: 242, y: 376 }, x: 292, y: 376 },
|
|
|
|
{ x: 410, y: 376 },
|
|
|
|
{ x: 410, y: 341 },
|
|
|
|
{ original: { x: 553, y: 341 }, x: 528, y: 341 }
|
|
|
|
]);
|
|
|
|
|
|
|
|
var diWaypoints = bpmnFactory.createDiWaypoints([
|
|
|
|
{ x: 292, y: 376 },
|
|
|
|
{ x: 410, y: 376 },
|
|
|
|
{ x: 410, y: 341 },
|
|
|
|
{ x: 528, y: 341 }
|
|
|
|
]);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// expect cropped waypoints in di
|
|
|
|
expect(sequenceFlow.di.waypoint).eql(diWaypoints);
|
|
|
|
}));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
it('should connect with custom start / end', inject(function(elementRegistry, modeling) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// given
|
|
|
|
var sourceShape = elementRegistry.get('Task_2'),
|
|
|
|
sourcePosition = {
|
|
|
|
x: 740,
|
|
|
|
y: 400
|
|
|
|
},
|
|
|
|
targetShape = elementRegistry.get('Task_3'),
|
|
|
|
targetPosition = {
|
|
|
|
x: 420,
|
|
|
|
y: 130
|
|
|
|
};
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// when
|
|
|
|
var newConnection = modeling.connect(
|
|
|
|
sourceShape, targetShape,
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
connectionStart: sourcePosition,
|
|
|
|
connectionEnd: targetPosition
|
|
|
|
}
|
|
|
|
);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// then
|
|
|
|
// expect cropped connection with custom start/end
|
|
|
|
expect(newConnection).to.have.waypoints([
|
2017-12-13 13:05:29 +00:00
|
|
|
{ x: 734, y: 400 },
|
2016-06-22 12:38:44 +00:00
|
|
|
{ x: 590, y: 400 },
|
|
|
|
{ x: 590, y: 130 },
|
2017-12-13 13:05:29 +00:00
|
|
|
{ x: 447, y: 130 }
|
2016-06-22 12:38:44 +00:00
|
|
|
]);
|
|
|
|
}));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// given
|
|
|
|
var taskShape = elementRegistry.get('Task_1'),
|
|
|
|
task = taskShape.businessObject,
|
|
|
|
gatewayShape = elementRegistry.get('Gateway_1'),
|
|
|
|
gateway = gatewayShape.businessObject;
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
var sequenceFlowConnection = modeling.createConnection(taskShape, gatewayShape, {
|
|
|
|
type: 'bpmn:SequenceFlow'
|
|
|
|
}, taskShape.parent);
|
2015-07-15 15:22:19 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
var sequenceFlow = sequenceFlowConnection.businessObject;
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// when
|
|
|
|
commandStack.undo();
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// then
|
|
|
|
expect(sequenceFlow.$parent).to.be.null;
|
|
|
|
expect(sequenceFlow.sourceRef).to.be.null;
|
|
|
|
expect(sequenceFlow.targetRef).to.be.null;
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
expect(task.outgoing).not.to.include(sequenceFlow);
|
|
|
|
expect(gateway.incoming).not.to.include(sequenceFlow);
|
|
|
|
}));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// given
|
|
|
|
var taskShape = elementRegistry.get('Task_1'),
|
|
|
|
task = taskShape.businessObject,
|
|
|
|
gatewayShape = elementRegistry.get('Gateway_1'),
|
|
|
|
gateway = gatewayShape.businessObject;
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
var sequenceFlowConnection = modeling.createConnection(taskShape, gatewayShape, {
|
|
|
|
type: 'bpmn:SequenceFlow'
|
|
|
|
}, taskShape.parent);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
var sequenceFlow = sequenceFlowConnection.businessObject;
|
|
|
|
|
|
|
|
var newWaypoints = sequenceFlowConnection.waypoints,
|
|
|
|
newDiWaypoints = sequenceFlow.di.waypoint;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// then
|
|
|
|
expect(sequenceFlow.sourceRef).to.eql(task);
|
|
|
|
expect(sequenceFlow.targetRef).to.eql(gateway);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
expect(task.outgoing).to.include(sequenceFlow);
|
|
|
|
expect(gateway.incoming).to.include(sequenceFlow);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
expect(sequenceFlow.di.$parent).to.eql(task.di.$parent);
|
|
|
|
expect(sequenceFlow.di.$parent.planeElement).to.include(sequenceFlow.di);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// expect cropped connection
|
|
|
|
expect(sequenceFlowConnection.waypoints).eql(newWaypoints);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-06-22 12:38:44 +00:00
|
|
|
// expect cropped waypoints in di
|
|
|
|
expect(sequenceFlow.di.waypoint).eql(newDiWaypoints);
|
|
|
|
}));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
});
|