Skip to content

Commit

Permalink
fix(modeling): skip moving if label is not yet created.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oguz Eroglu authored and nikku committed Oct 25, 2019
1 parent c74b329 commit 29b29b9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/features/modeling/behavior/LabelBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ export default function LabelBehavior(
var label = event.context.connection.label,
labelAdjustment;

if (!label) {
// 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 Expand Up @@ -386,4 +391,4 @@ function getNearestLine(point, lines) {
var sorted = sortBy(distances, 'distance');

return sorted[0].line;
}
}
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>
63 changes: 60 additions & 3 deletions test/spec/features/modeling/behavior/LabelBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ import {

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
import gridSnappingModule from 'lib/features/grid-snapping';


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

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

var testModules = [ modelingModule, coreModule ];

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


describe('updating name property', function() {
Expand Down Expand Up @@ -669,6 +673,59 @@ 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
]
}));


it('should skip adjustment during creation', inject(
function(elementRegistry, copyPaste, canvas, dragging) {

// given
var elements = [
elementRegistry.get('Source'),
elementRegistry.get('Target'),
elementRegistry.get('SequenceFlow'),
elementRegistry.get('SequenceFlow').label
];

var rootElement = canvas.getRootElement();

copyPaste.copy(elements);

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

var label = pastedElements[3];

// then
expect(label).to.exist;

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

});

});

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

function getBounds(element) {
Expand Down

0 comments on commit 29b29b9

Please sign in to comment.