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 - layout connection', function() {
|
|
|
|
|
2015-07-29 13:11:54 +00:00
|
|
|
var diagramXML = require('../../../../fixtures/bpmn/sequence-flows.bpmn');
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule
|
|
|
|
]
|
|
|
|
}));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
describe('should not touch already layouted', function() {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
it('execute', inject(function(elementRegistry, modeling, bpmnFactory) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
2014-07-30 14:06:32 +00:00
|
|
|
sequenceFlow = sequenceFlowConnection.businessObject;
|
|
|
|
|
2016-06-26 21:42:11 +00:00
|
|
|
var expectedWaypoints = sequenceFlowConnection.waypoints;
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
// when
|
|
|
|
modeling.layoutConnection(sequenceFlowConnection);
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
2014-09-04 11:47:11 +00:00
|
|
|
// expect cropped, repaired connection
|
2015-04-22 07:08:38 +00:00
|
|
|
// that was not actually modified
|
2015-08-24 09:28:54 +00:00
|
|
|
|
2016-06-26 21:42:11 +00:00
|
|
|
expect(sequenceFlowConnection.waypoints).to.eql(expectedWaypoints);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// expect cropped waypoints in di
|
2016-06-26 21:42:11 +00:00
|
|
|
var diWaypoints = bpmnFactory.createDiWaypoints(expectedWaypoints);
|
2015-07-15 15:22:19 +00:00
|
|
|
|
|
|
|
expect(sequenceFlow.di.waypoint).eql(diWaypoints);
|
2014-07-30 14:06:32 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
it('undo', inject(function(elementRegistry, commandStack, modeling) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
2014-07-30 14:06:32 +00:00
|
|
|
sequenceFlow = sequenceFlowConnection.businessObject;
|
|
|
|
|
|
|
|
var oldWaypoints = sequenceFlowConnection.waypoints,
|
|
|
|
oldDiWaypoints = sequenceFlow.di.waypoint;
|
|
|
|
|
|
|
|
modeling.layoutConnection(sequenceFlowConnection);
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(sequenceFlowConnection.waypoints).eql(oldWaypoints);
|
|
|
|
expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints);
|
2014-07-30 14:06:32 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
it('redo', inject(function(elementRegistry, commandStack, modeling) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
|
2014-07-30 14:06:32 +00:00
|
|
|
sequenceFlow = sequenceFlowConnection.businessObject;
|
|
|
|
|
|
|
|
modeling.layoutConnection(sequenceFlowConnection);
|
|
|
|
|
|
|
|
var newWaypoints = sequenceFlowConnection.waypoints,
|
|
|
|
newDiWaypoints = sequenceFlow.di.waypoint;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(sequenceFlowConnection.waypoints).eql(newWaypoints);
|
|
|
|
expect(sequenceFlow.di.waypoint).eql(newDiWaypoints);
|
2014-07-30 14:06:32 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-10 11:29:54 +00:00
|
|
|
|
|
|
|
it('should remove un-needed waypoints', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var taskShape = elementRegistry.get('Task_2'),
|
|
|
|
sequenceFlowConnection = elementRegistry.get('SequenceFlow_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
// moving task
|
|
|
|
modeling.moveElements([ taskShape ], { x: 250, y: -95 });
|
|
|
|
|
|
|
|
// then
|
|
|
|
var newWaypoints = sequenceFlowConnection.waypoints;
|
|
|
|
|
|
|
|
expect(newWaypoints.map(toPoint)).to.eql([
|
|
|
|
{ x: 578, y: 341 },
|
|
|
|
{ x: 982, y: 341 }
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
});
|
2017-12-10 11:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2017-12-10 11:29:54 +00:00
|
|
|
|
|
|
|
function toPoint(p) {
|
|
|
|
return {
|
|
|
|
x: p.x,
|
|
|
|
y: p.y
|
|
|
|
};
|
|
|
|
}
|