From b4b5d1d139a38263527ce01974699574af925494 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 11 Dec 2019 10:54:52 +0100 Subject: [PATCH] fix(modeling): correct creation of nested lanes With diagram-js@5 we've introduced the CreateBehavior that ensures elements are not created on top of lanes but always on top of the actual participant. Unfortunately we forgot about the fact that lanes are created once in a while, too. This commit accounts for this fact and ensures we do not adjust the parent of to-be-created lanes. (A test cases for splitting nested lanes did not exist until now). Closes #1254 Closes #1253 --- .../modeling/behavior/CreateBehavior.js | 5 +- .../modeling/lanes/SplitLane.nested.bpmn | 44 ++++++++++++ .../features/modeling/lanes/SplitLaneSpec.js | 67 +++++++++++++++++-- 3 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 test/spec/features/modeling/lanes/SplitLane.nested.bpmn diff --git a/lib/features/modeling/behavior/CreateBehavior.js b/lib/features/modeling/behavior/CreateBehavior.js index c8a2d545..b32471a0 100644 --- a/lib/features/modeling/behavior/CreateBehavior.js +++ b/lib/features/modeling/behavior/CreateBehavior.js @@ -12,9 +12,10 @@ export default function CreateBehavior(injector) { this.preExecute('shape.create', 1500, function(event) { var context = event.context, - parent = context.parent; + parent = context.parent, + shape = context.shape; - if (is(parent, 'bpmn:Lane')) { + if (is(parent, 'bpmn:Lane') && !is(shape, 'bpmn:Lane')) { context.parent = getParent(parent, 'bpmn:Participant'); } }); diff --git a/test/spec/features/modeling/lanes/SplitLane.nested.bpmn b/test/spec/features/modeling/lanes/SplitLane.nested.bpmn new file mode 100644 index 00000000..8b58dda5 --- /dev/null +++ b/test/spec/features/modeling/lanes/SplitLane.nested.bpmn @@ -0,0 +1,44 @@ + + + + + + + + + Event + Task + + + + SequenceFlow_192h0e0 + + + SequenceFlow_192h0e0 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/lanes/SplitLaneSpec.js b/test/spec/features/modeling/lanes/SplitLaneSpec.js index dab40473..0ffec2da 100644 --- a/test/spec/features/modeling/lanes/SplitLaneSpec.js +++ b/test/spec/features/modeling/lanes/SplitLaneSpec.js @@ -18,12 +18,13 @@ function getBounds(element) { describe('features/modeling - SplitLane', function() { + var testModules = [ coreModule, modelingModule ]; + + describe('should split Participant with Lane', function() { var diagramXML = require('./participant-lane.bpmn'); - var testModules = [ coreModule, modelingModule ]; - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); @@ -124,8 +125,6 @@ describe('features/modeling - SplitLane', function() { var diagramXML = require('./participant-no-lane.bpmn'); - var testModules = [ coreModule, modelingModule ]; - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); @@ -148,7 +147,7 @@ describe('features/modeling - SplitLane', function() { expect(participantShape).to.have.bounds(oldBounds); // and two child lanes - expect(childLanes.length).to.eql(2); + expect(childLanes).to.have.length(2); // with respective bounds expect(childLanes[0]).to.have.bounds({ @@ -186,7 +185,7 @@ describe('features/modeling - SplitLane', function() { expect(participantShape).to.have.bounds(oldBounds); // and two child lanes - expect(childLanes.length).to.eql(3); + expect(childLanes).to.have.length(3); // with respective bounds expect(childLanes[0]).to.have.bounds({ @@ -213,4 +212,60 @@ describe('features/modeling - SplitLane', function() { }); + + describe('should split nested Lane', function() { + + var diagramXML = require('./SplitLane.nested.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('into two lanes', inject(function(elementRegistry, modeling) { + + // given + var laneShape = elementRegistry.get('Lane'), + laneBo = laneShape.businessObject, + oldBounds = getBounds(laneShape); + + // when + modeling.splitLane(laneShape, 2); + + var childLanes = getChildLanes(laneShape); + + var newLaneHeight = Math.round(laneShape.height / 2); + + // then + + // participant has original size + expect(laneShape).to.have.bounds(oldBounds); + + // and two child lanes + expect(childLanes).to.have.length(2); + + // with respective bounds + expect(childLanes[0]).to.have.bounds({ + x: laneShape.x + 30, + y: laneShape.y, + width: laneShape.width - 30, + height: newLaneHeight + }); + + expect(childLanes[1]).to.have.bounds({ + x: laneShape.x + 30, + y: laneShape.y + newLaneHeight, + width: laneShape.width - 30, + height: newLaneHeight + }); + + // BPMN internals are properly updated + expect(laneBo.childLaneSet).to.exist; + expect(laneBo.childLaneSet.lanes).to.eql([ + childLanes[0].businessObject, + childLanes[1].businessObject + ]); + + })); + + }); + }); \ No newline at end of file