diff --git a/lib/features/modeling/BpmnUpdater.js b/lib/features/modeling/BpmnUpdater.js index e1cb90d7..9fd9adb3 100644 --- a/lib/features/modeling/BpmnUpdater.js +++ b/lib/features/modeling/BpmnUpdater.js @@ -173,25 +173,26 @@ BpmnUpdater.prototype.updateConnection = function(connection) { newSource = connection.source && connection.source.businessObject, newTarget = connection.target && connection.target.businessObject; - // don't set incoming / outgoing for associations - if(businessObject.$instanceOf('bpmn:Association')) { - return; - } + var inverseSet = businessObject.$instanceOf('bpmn:SequenceFlow'); if (businessObject.sourceRef !== newSource) { - Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject); + if (inverseSet) { + Collections.remove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject); - if (newSource) { - newSource.get('outgoing').push(businessObject); + if (newSource) { + newSource.get('outgoing').push(businessObject); + } } businessObject.sourceRef = newSource; } if (businessObject.targetRef !== newTarget) { - Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject); + if (inverseSet) { + Collections.remove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject); - if (newTarget) { - newTarget.get('incoming').push(businessObject); + if (newTarget) { + newTarget.get('incoming').push(businessObject); + } } businessObject.targetRef = newTarget; diff --git a/test/spec/features/modeling/AppendShapeSpec.js b/test/spec/features/modeling/AppendShapeSpec.js index aa469180..12a90270 100644 --- a/test/spec/features/modeling/AppendShapeSpec.js +++ b/test/spec/features/modeling/AppendShapeSpec.js @@ -348,6 +348,58 @@ describe('features/modeling - append shape', function() { describe('bpmn element support', function() { + describe('TextAnnotation', function() { + + it('should wire connection source + target', inject(function(elementRegistry, modeling) { + + // given + var startEventShape = elementRegistry.getById('StartEvent_1'); + + // when + var targetShape = modeling.appendTextAnnotation(startEventShape, 'bpmn:TextAnnotation'), + target = targetShape.businessObject; + + var connectingConnection = _.find(targetShape.incoming, function(c) { + return c.target === targetShape; + }); + + var connecting = connectingConnection.businessObject; + + // then + expect(targetShape).toBeDefined(); + expect(target.$instanceOf('bpmn:TextAnnotation')).toBe(true); + + expect(connecting.$instanceOf('bpmn:Association')).toBe(true); + expect(connecting.sourceRef).toBe(startEventShape.businessObject); + expect(connecting.targetRef).toBe(target); + })); + + + it('should undo wire connection source + target', inject(function(elementRegistry, modeling, commandStack) { + + // given + var startEventShape = elementRegistry.getById('StartEvent_1'); + + var targetShape = modeling.appendTextAnnotation(startEventShape, 'bpmn:TextAnnotation'), + target = targetShape.businessObject; + + var connectingConnection = _.find(targetShape.incoming, function(c) { + return c.target === targetShape; + }); + + var connecting = connectingConnection.businessObject; + + // when + commandStack.undo(); + + // then + expect(connecting.sourceRef).toBe(null); + expect(connecting.targetRef).toBe(null); + })); + + }); + + describe('ExclusiveGateway', function() { it('should append', inject(function(elementRegistry, modeling) {