diff --git a/lib/features/modeling/behavior/RemoveElementBehavior.js b/lib/features/modeling/behavior/RemoveElementBehavior.js index b006ad85..b22a3b89 100644 --- a/lib/features/modeling/behavior/RemoveElementBehavior.js +++ b/lib/features/modeling/behavior/RemoveElementBehavior.js @@ -1,5 +1,7 @@ import inherits from 'inherits'; +import { is } from '../../../util/ModelUtil'; + import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; import lineIntersect from './util/LineIntersect'; @@ -18,19 +20,25 @@ export default function RemoveElementBehavior(eventBus, bpmnRules, modeling) { var shape = e.context.shape; - if (shape.incoming.length == 1 && shape.outgoing.length == 1) { + // only handle [a] -> [shape] -> [b] patterns + if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) { + return; + } - var inConnection = shape.incoming[0], - outConnection = shape.outgoing[0]; + var inConnection = shape.incoming[0], + outConnection = shape.outgoing[0]; + // only handle sequence flows + if (!is(inConnection, 'bpmn:SequenceFlow') || !is(outConnection, 'bpmn:SequenceFlow')) { + return; + } - if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) { + if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) { - // compute new, combined waypoints - var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints); + // compute new, combined waypoints + var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints); - modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints); - } + modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints); } }); diff --git a/test/spec/features/replace/BpmnReplace.poolMessageFlows.bpmn b/test/spec/features/replace/BpmnReplace.poolMessageFlows.bpmn new file mode 100644 index 00000000..2aeb7e0e --- /dev/null +++ b/test/spec/features/replace/BpmnReplace.poolMessageFlows.bpmn @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js index 6bc9bf91..0b1fd001 100644 --- a/test/spec/features/replace/BpmnReplaceSpec.js +++ b/test/spec/features/replace/BpmnReplaceSpec.js @@ -317,6 +317,37 @@ describe('features/replace - bpmn replace', function() { }); + describe('should collapse pool, removing message flows', function() { + + var diagramXML = require('./BpmnReplace.poolMessageFlows.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: testModules + })); + + + it('expanded with collapsed pool', inject(function(elementRegistry, bpmnReplace) { + + // given + var shape = elementRegistry.get('Participant_1'); + + // when + var newShape = bpmnReplace.replaceElement(shape, { + type: 'bpmn:Participant', + isExpanded: false + }); + + // then + expect(isExpanded(newShape)).to.be.false; // collapsed + expect(newShape.children).to.be.empty; + + expect(elementRegistry.get('MessageFlow_1')).not.to.exist; + expect(elementRegistry.get('MessageFlow_2')).not.to.exist; + })); + + }); + + describe('should replace with data objects', function() { var diagramXML = require('./BpmnReplace.dataObjects.bpmn');