test(modeling): verify connection move behavior

Closes to #511
This commit is contained in:
Nico Rehwaldt 2017-12-14 15:38:46 +01:00
parent 8b4476a388
commit 2218b84af6
3 changed files with 133 additions and 24 deletions

View File

@ -11,16 +11,19 @@ var modelingModule = require('../../../../lib/features/modeling'),
describe('features/modeling - move connection', function() { describe('features/modeling - move connection', function() {
describe('should move connection', function() {
var diagramXML = require('../../../fixtures/bpmn/sequence-flows.bpmn'); var diagramXML = require('../../../fixtures/bpmn/sequence-flows.bpmn');
var testModules = [ coreModule, modelingModule ]; beforeEach(bootstrapModeler(diagramXML, {
modules: [
beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); coreModule,
modelingModule
]
}));
describe('connection handling', function() { it('execute', inject(function(elementRegistry, modeling, bpmnFactory) {
it('should execute', inject(function(elementRegistry, modeling, bpmnFactory) {
// given // given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
@ -47,12 +50,8 @@ describe('features/modeling - move connection', function() {
expect(sequenceFlow.di.waypoint).eql(diWaypoints); expect(sequenceFlow.di.waypoint).eql(diWaypoints);
})); }));
});
it('undo', inject(function(elementRegistry, commandStack, modeling) {
describe('undo support', function() {
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
// given // given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
@ -71,12 +70,8 @@ describe('features/modeling - move connection', function() {
expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints); expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints);
})); }));
});
it('redo', inject(function(elementRegistry, commandStack, modeling) {
describe('redo support', function() {
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
// given // given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
@ -97,5 +92,4 @@ describe('features/modeling - move connection', function() {
})); }));
}); });
}); });

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:task id="Task_1">
<bpmn:outgoing>Task_Flow</bpmn:outgoing>
</bpmn:task>
<bpmn:task id="Task_2">
<bpmn:incoming>Task_Flow</bpmn:incoming>
<bpmn:incoming>Boundary_Flow</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="Task_Flow" sourceRef="Task_1" targetRef="Task_2" />
<bpmn:boundaryEvent id="BoundaryEvent" attachedToRef="Task_1">
<bpmn:outgoing>Boundary_Flow</bpmn:outgoing>
</bpmn:boundaryEvent>
<bpmn:sequenceFlow id="Boundary_Flow" sourceRef="BoundaryEvent" targetRef="Task_2" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="324" y="219" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_2_di" bpmnElement="Task_2">
<dc:Bounds x="590" y="219" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Task_Flow_di" bpmnElement="Task_Flow">
<di:waypoint xsi:type="dc:Point" x="424" y="259" />
<di:waypoint xsi:type="dc:Point" x="590" y="259" />
<bpmndi:BPMNLabel>
<dc:Bounds x="462" y="249" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="BoundaryEvent_di" bpmnElement="BoundaryEvent">
<dc:Bounds x="363" y="281" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="336" y="317" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Boundary_Flow_di" bpmnElement="Boundary_Flow">
<di:waypoint xsi:type="dc:Point" x="381" y="317" />
<di:waypoint xsi:type="dc:Point" x="381" y="456" />
<di:waypoint xsi:type="dc:Point" x="640" y="456" />
<di:waypoint xsi:type="dc:Point" x="640" y="299" />
<bpmndi:BPMNLabel>
<dc:Bounds x="451" y="319" width="90" height="20" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -11,14 +11,17 @@ var modelingModule = require('../../../../lib/features/modeling'),
describe('features/modeling - move elements', function() { describe('features/modeling - move elements', function() {
describe('should keep flow parent', function() {
var diagramXML = require('./MoveElements.flow-collaboration.bpmn'); var diagramXML = require('./MoveElements.flow-collaboration.bpmn');
var testModules = [ coreModule, modelingModule ]; beforeEach(bootstrapModeler(diagramXML, {
modules: [
coreModule,
modelingModule
]
}));
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('should keep flow parent', function() {
it('when moving shapes', inject(function(elementRegistry, modeling, bpmnFactory) { it('when moving shapes', inject(function(elementRegistry, modeling, bpmnFactory) {
@ -67,4 +70,67 @@ describe('features/modeling - move elements', function() {
}); });
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);
}));
});
}); });
///////// helpers /////////////////////////////////
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;
});
}