From 64d360575b8e43b0711b2cfdaa7e8547cb34fcba Mon Sep 17 00:00:00 2001 From: Oguz Eroglu Date: Tue, 22 Oct 2019 15:17:36 +0200 Subject: [PATCH] fix(modeling): skip moving if label is not yet created. Related to https://github.com/zeebe-io/zeebe-modeler/issues/134 --- .../modeling/behavior/LabelBehavior.js | 9 ++- .../behavior/LabelBehavior.copyPaste.bpmn | 31 +++++++++ .../modeling/behavior/LabelBehaviorSpec.js | 63 ++++++++++++++++++- 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 test/spec/features/modeling/behavior/LabelBehavior.copyPaste.bpmn diff --git a/lib/features/modeling/behavior/LabelBehavior.js b/lib/features/modeling/behavior/LabelBehavior.js index 63dff55a..589fd8df 100644 --- a/lib/features/modeling/behavior/LabelBehavior.js +++ b/lib/features/modeling/behavior/LabelBehavior.js @@ -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; } @@ -386,4 +391,4 @@ function getNearestLine(point, lines) { var sorted = sortBy(distances, 'distance'); return sorted[0].line; -} \ No newline at end of file +} diff --git a/test/spec/features/modeling/behavior/LabelBehavior.copyPaste.bpmn b/test/spec/features/modeling/behavior/LabelBehavior.copyPaste.bpmn new file mode 100644 index 00000000..c77d4e29 --- /dev/null +++ b/test/spec/features/modeling/behavior/LabelBehavior.copyPaste.bpmn @@ -0,0 +1,31 @@ + + + + + SequenceFlow + + + SequenceFlow + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/behavior/LabelBehaviorSpec.js b/test/spec/features/modeling/behavior/LabelBehaviorSpec.js index 21a5f767..9d43b448 100644 --- a/test/spec/features/modeling/behavior/LabelBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/LabelBehaviorSpec.js @@ -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() { @@ -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) {