Skip to content

Commit

Permalink
REVIEW: UPDATE STUFF
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Oct 25, 2019
1 parent 395488a commit b98dbca
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
5 changes: 5 additions & 0 deletions lib/features/modeling/behavior/LabelBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export default function LabelBehavior(
var label = event.context.connection.label,
labelAdjustment;

// handle missing label as well as the case
// that the label parent does not exist (yet),
// because it is being pasted / created via multi element create
//
// Cf. https://github.com/bpmn-io/bpmn-js/pull/1227
if (!label || !label.parent) {
return;
}
Expand Down
22 changes: 0 additions & 22 deletions test/spec/features/modeling/behavior/LabelBehavior.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
<bpmn:startEvent id="StartEvent_1" name="foo" />
<bpmn:task id="Task_1" />
<bpmn:exclusiveGateway id="ExclusiveGateway_1" />
<bpmn:task id="Task_2">
<bpmn:outgoing>SequenceFlow1</bpmn:outgoing>
</bpmn:task>
<bpmn:task id="Task_3">
<bpmn:incoming>SequenceFlow1</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow1" name="SequenceFlow1" sourceRef="Task_2" targetRef="Task_3" />
<bpmn:textAnnotation id="TextAnnotation_1">
<bpmn:text>foo</bpmn:text>
</bpmn:textAnnotation>
Expand Down Expand Up @@ -75,21 +68,6 @@
<dc:Bounds x="403" y="583" width="28" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_0ukipr5_di" bpmnElement="Task_2">
<dc:Bounds x="160" y="740" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_06mo077_di" bpmnElement="Task_3">
<dc:Bounds x="353" y="740" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1gzp2c4_di" bpmnElement="SequenceFlow1">
<di:waypoint x="210" y="820" />
<di:waypoint x="210" y="850" />
<di:waypoint x="403" y="850" />
<di:waypoint x="403" y="820" />
<bpmndi:BPMNLabel>
<dc:Bounds x="267" y="860" width="79" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
31 changes: 31 additions & 0 deletions test/spec/features/modeling/behavior/LabelBehavior.copyPaste.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions 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_0cu5n0d" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.0">
<bpmn:process id="Process_1cirp64" isExecutable="true">
<bpmn:startEvent id="Source">
<bpmn:outgoing>SequenceFlow</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Target">
<bpmn:incoming>SequenceFlow</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="SequenceFlow" name="A" sourceRef="Source" targetRef="Target" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1cirp64">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="Source">
<dc:Bounds x="179" y="79" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1m56bsl_di" bpmnElement="Target">
<dc:Bounds x="300" y="250" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_di" bpmnElement="SequenceFlow">
<di:waypoint x="215" y="97" />
<di:waypoint x="258" y="97" />
<di:waypoint x="258" y="290" />
<di:waypoint x="300" y="290" />
<bpmndi:BPMNLabel>
<dc:Bounds x="270" y="191" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
76 changes: 39 additions & 37 deletions test/spec/features/modeling/behavior/LabelBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ describe('behavior - LabelBehavior', function() {

var diagramXML = require('./LabelBehavior.bpmn');

var testModules = [ modelingModule, coreModule, gridSnappingModule ];

beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
beforeEach(bootstrapModeler(diagramXML, {
modules: [
modelingModule,
coreModule
]
}));


describe('updating name property', function() {
Expand Down Expand Up @@ -668,64 +671,63 @@ describe('behavior - LabelBehavior', function() {

});

});


describe('behavior - LabelBehavior', function() {

describe('copy/paste integration', function() {

var diagramXML = require('./LabelBehavior.copyPaste.bpmn');

beforeEach(bootstrapModeler(diagramXML, {
modules: [
modelingModule,
coreModule,
gridSnappingModule
]
}));

describe('Waypoint update', function() {

it('should execute on waypoint update during creation mode', inject(
it('should skip adjustment during creation', inject(
function(elementRegistry, copyPaste, canvas, dragging) {

// given
var task1 = elementRegistry.get('Task_2'),
task2 = elementRegistry.get('Task_3'),
sequenceFlow = elementRegistry.get('SequenceFlow1'),
label = sequenceFlow.label,
rootElement = canvas.getRootElement(),
taskMidPoint = getMidPoint(task1, task2),
labelDistanceToTaskMidPoint = getElementDistanceToPoint(label, taskMidPoint);
var elements = [
elementRegistry.get('Source'),
elementRegistry.get('Target'),
elementRegistry.get('SequenceFlow'),
elementRegistry.get('SequenceFlow').label
];

copyPaste.copy([ task1, task2, sequenceFlow, label ]);
var rootElement = canvas.getRootElement();

copyPaste.copy(elements);

// when
var pastedElements = copyPaste.paste({
element: rootElement,
point: {
x: 700,
y: 100
y: 300
}
});

var pastedTask1 = pastedElements[0],
pastedTask2 = pastedElements[1],
pastedSequenceFlow = pastedElements[2],
pastedLabel = pastedElements[3],
newTaskMidPoint = getMidPoint(pastedTask1, pastedTask2),
newLabelDistanceToTaskMidPoint = getElementDistanceToPoint(pastedLabel, newTaskMidPoint);
var label = pastedElements[3];

// then
expect(pastedLabel.parent).to.be.eql(rootElement);
expect(pastedLabel.labelTarget).to.be.eql(pastedSequenceFlow);
expect(newLabelDistanceToTaskMidPoint).to.be.eql(labelDistanceToTaskMidPoint);
expect(label).to.exist;

expect(label).to.have.position({ x: 681, y: 287 });
}
));

});

});

// helpers //////////

function getBounds(element) {
return pick(element, [ 'x', 'y', 'width', 'height' ]);
}

function getMidPoint(element1, element2) {
return {
x: (element1.x + element2.x) / 2,
y: (element1.y + element2.y) / 2
};
}

function getElementDistanceToPoint(element, point) {
return Math.sqrt(
Math.pow(element.x - point.x, 2) +
Math.pow(element.y - point.y, 2)
);
}

0 comments on commit b98dbca

Please sign in to comment.