2016-07-05 06:23:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../../../TestHelper');
|
|
|
|
|
|
|
|
/* global bootstrapModeler, inject */
|
|
|
|
|
|
|
|
|
2018-01-24 10:41:21 +00:00
|
|
|
var modelingModule = require('lib/features/modeling'),
|
|
|
|
coreModule = require('lib/core');
|
2016-07-05 06:23:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features/modeling - move elements', function() {
|
|
|
|
|
2017-12-14 14:38:46 +00:00
|
|
|
describe('should keep flow parent', function() {
|
2016-07-05 06:23:51 +00:00
|
|
|
|
2017-12-14 14:38:46 +00:00
|
|
|
var diagramXML = require('./MoveElements.flow-collaboration.bpmn');
|
2016-07-05 06:23:51 +00:00
|
|
|
|
2017-12-14 14:38:46 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule
|
|
|
|
]
|
|
|
|
}));
|
2016-07-05 06:23:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('when moving shapes', inject(function(elementRegistry, modeling, bpmnFactory) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var connectionSequenceFlow = elementRegistry.get('SequenceFlow'),
|
|
|
|
shapeTask_A = elementRegistry.get('Task_A'),
|
|
|
|
shapeTask_B = elementRegistry.get('Task_B'),
|
|
|
|
shapeTask_C = elementRegistry.get('Task_C'),
|
|
|
|
shapePool_A = elementRegistry.get('Pool_A'),
|
|
|
|
shapePool_B = elementRegistry.get('Pool_B');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements(
|
|
|
|
[ shapeTask_A, shapeTask_B, shapeTask_C ],
|
|
|
|
{ x: 0, y: -50 },
|
|
|
|
shapePool_B,
|
|
|
|
{ primaryShape: shapeTask_C }
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connectionSequenceFlow.parent).to.eql(shapePool_A);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('when moving shapes with flow', inject(function(elementRegistry, modeling, bpmnFactory) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var connectionSequenceFlow = elementRegistry.get('SequenceFlow'),
|
|
|
|
shapeTask_A = elementRegistry.get('Task_A'),
|
|
|
|
shapeTask_B = elementRegistry.get('Task_B'),
|
|
|
|
shapeTask_C = elementRegistry.get('Task_C'),
|
|
|
|
shapePool_A = elementRegistry.get('Pool_A'),
|
|
|
|
shapePool_B = elementRegistry.get('Pool_B');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements(
|
|
|
|
[ shapeTask_A, shapeTask_B, shapeTask_C, connectionSequenceFlow ],
|
|
|
|
{ x: 0, y: -50 },
|
|
|
|
shapePool_B,
|
|
|
|
{ primaryShape: shapeTask_C }
|
|
|
|
);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connectionSequenceFlow.parent).to.eql(shapePool_A);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-14 14:38:46 +00:00
|
|
|
|
|
|
|
describe('should move boundary connection with tasks', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./MoveElements.boundary-connection.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule
|
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should properly adjust connection', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var elements = [
|
|
|
|
elementRegistry.get('Task_1'),
|
|
|
|
elementRegistry.get('Task_2'),
|
|
|
|
elementRegistry.get('BoundaryEvent')
|
|
|
|
];
|
|
|
|
|
|
|
|
var boundaryFlow = elementRegistry.get('Boundary_Flow');
|
|
|
|
|
|
|
|
var delta = { x: 0, y: 20 };
|
|
|
|
|
|
|
|
var expectedWaypoints = moveWaypoints(boundaryFlow.waypoints, delta);
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements(elements, delta);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(boundaryFlow).to.have.waypoints(expectedWaypoints);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-07-05 06:23:51 +00:00
|
|
|
});
|
2017-12-14 14:38:46 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2017-12-14 14:38:46 +00:00
|
|
|
|
|
|
|
function moveWaypoint(p, delta) {
|
|
|
|
return {
|
|
|
|
x: p.x + delta.x || 0,
|
|
|
|
y: p.y + delta.y || 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveWaypoints(waypoints, delta) {
|
|
|
|
|
|
|
|
return waypoints.map(function(p) {
|
|
|
|
|
|
|
|
var original = p.original;
|
|
|
|
|
|
|
|
var moved = moveWaypoint(p, delta);
|
|
|
|
|
|
|
|
if (original) {
|
|
|
|
moved.original = moveWaypoint(original, delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
return moved;
|
|
|
|
});
|
|
|
|
}
|