From 9ee90ef0894f6651e535cf144885a98ad479edd0 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Tue, 2 Jul 2019 13:28:34 +0200 Subject: [PATCH] fix(modeling): correctly create connection replacement Closes https://github.com/bpmn-io/bpmn-js/issues/1072 --- .../behavior/ReplaceConnectionBehavior.js | 11 +- ...nectionBehavior.message-sequence-flow.bpmn | 107 +++++++++--------- .../behavior/ReplaceConnectionBehaviorSpec.js | 71 +++++++++++- 3 files changed, 130 insertions(+), 59 deletions(-) diff --git a/lib/features/modeling/behavior/ReplaceConnectionBehavior.js b/lib/features/modeling/behavior/ReplaceConnectionBehavior.js index bc21ea30..a5f382c0 100644 --- a/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +++ b/lib/features/modeling/behavior/ReplaceConnectionBehavior.js @@ -89,21 +89,18 @@ export default function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, var context = event.context, connection = context.connection, + source = context.newSource || connection.source, + target = context.newTarget || connection.target, allowed, replacement; - if (context.newTarget) { - allowed = bpmnRules.canConnect(connection.source, context.newTarget); - } else { - allowed = bpmnRules.canConnect(context.newSource, connection.target); - } + allowed = bpmnRules.canConnect(source, target); if (!allowed || allowed.type === connection.type) { return; } - // temporarily connect old shapes with new connection - replacement = modeling.connect(connection.source, connection.target, { + replacement = modeling.connect(source, target, { type: allowed.type, waypoints: connection.waypoints.slice() }); diff --git a/test/spec/features/modeling/behavior/ReplaceConnectionBehavior.message-sequence-flow.bpmn b/test/spec/features/modeling/behavior/ReplaceConnectionBehavior.message-sequence-flow.bpmn index ba239791..6971e00f 100644 --- a/test/spec/features/modeling/behavior/ReplaceConnectionBehavior.message-sequence-flow.bpmn +++ b/test/spec/features/modeling/behavior/ReplaceConnectionBehavior.message-sequence-flow.bpmn @@ -1,12 +1,13 @@ - + - - - - - - + + + + + + + @@ -14,7 +15,7 @@ SequenceFlow_2 - + SequenceFlow_2 @@ -23,100 +24,104 @@ SequenceFlow_3 SequenceFlow_1 - + SequenceFlow_3 - + - + - - + + - + - + - + - + - - + + - + - + - + - + - + - - + + - + - - + + - + - + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - + + + + + - \ No newline at end of file + diff --git a/test/spec/features/modeling/behavior/ReplaceConnectionBehaviorSpec.js b/test/spec/features/modeling/behavior/ReplaceConnectionBehaviorSpec.js index 3428461f..d819433e 100644 --- a/test/spec/features/modeling/behavior/ReplaceConnectionBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/ReplaceConnectionBehaviorSpec.js @@ -11,6 +11,10 @@ import { find } from 'min-dash'; +import { + getMid +} from 'diagram-js/lib/layout/LayoutUtil'; + import modelingModule from 'lib/features/modeling'; import moveModule from 'diagram-js/lib/features/move'; import coreModule from 'lib/core'; @@ -553,4 +557,69 @@ describe('features/modeling - replace connection', function() { }); -}); \ No newline at end of file + + describe('reconnecting to create loops', function() { + + var processDiagramXML = require('./ReplaceConnectionBehavior.message-sequence-flow.bpmn'); + + beforeEach(bootstrapModeler(processDiagramXML, { + modules: testModules + })); + + + it('should set correct parents when reconnecting message flow start to task', + inject(function(elementRegistry, modeling) { + + // given + var task = elementRegistry.get('Task_4'), + connection = elementRegistry.get('MessageFlow_5'); + + // when + modeling.reconnectStart(connection, task, getMid(task)); + + // then + expect(connection.parent).to.not.exist; + expect(task.outgoing[0]).to.exist; + expect(task.outgoing[0]).to.have.property('parent', task.parent); + }) + ); + + + it('should set correct parents when reconnecting message flow end to task', + inject(function(elementRegistry, modeling) { + + // given + var task = elementRegistry.get('Task_3'), + connection = elementRegistry.get('MessageFlow_1'); + + // when + modeling.reconnectEnd(connection, task, getMid(task)); + + // then + expect(connection.parent).to.not.exist; + expect(task.outgoing[0]).to.exist; + expect(task.outgoing[0]).to.have.property('parent', task.parent); + }) + ); + + + it('should set correct parents when reconnecting message flow from participant to task', + inject(function(elementRegistry, modeling) { + + // given + var task = elementRegistry.get('Task_3'), + connection = elementRegistry.get('MessageFlow_6'); + + // when + modeling.reconnectStart(connection, task, getMid(task)); + + // then + expect(connection.parent).to.not.exist; + expect(task.outgoing[1]).to.exist; + expect(task.outgoing[1]).to.have.property('parent', task.parent); + }) + ); + + }); + +});