diff --git a/lib/features/modeling/cmd/UpdateFlowNodeRefsHandler.js b/lib/features/modeling/cmd/UpdateFlowNodeRefsHandler.js index a1a0bfbe..efd30d0e 100644 --- a/lib/features/modeling/cmd/UpdateFlowNodeRefsHandler.js +++ b/lib/features/modeling/cmd/UpdateFlowNodeRefsHandler.js @@ -34,7 +34,7 @@ UpdateFlowNodeRefsHandler.$inject = [ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, laneShapes) { - var handledNodes = {}; + var handledNodes = []; var updates = []; @@ -58,9 +58,9 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la } function addFlowNodeShape(flowNodeShape) { - if (!handledNodes[flowNodeShape.id]) { + if (handledNodes.indexOf(flowNodeShape) === -1) { allFlowNodeShapes.push(flowNodeShape); - handledNodes[flowNodeShape.id] = flowNodeShape; + handledNodes.push(flowNodeShape); } } @@ -92,7 +92,7 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la laneShapes.forEach(function(laneShape) { var root = getLanesRoot(laneShape); - if (!root || handledNodes[root.id]) { + if (!root || handledNodes.indexOf(root) !== -1) { return; } @@ -102,7 +102,7 @@ UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, la children.forEach(addFlowNodeShape); - handledNodes[root.id] = root; + handledNodes.push(root); }); flowNodeShapes.forEach(addFlowNodeShape); @@ -190,4 +190,4 @@ UpdateFlowNodeRefsHandler.prototype.revert = function(context) { // TODO(nikku): return changed elements // return [ ... ]; -}; \ No newline at end of file +}; diff --git a/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js b/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js index d969e4cf..3b32b9f9 100644 --- a/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js +++ b/test/spec/features/modeling/lanes/UpdateFlowNodeRefsSpec.js @@ -266,4 +266,28 @@ describe('features/modeling - lanes - flowNodeRefs', function() { expect(sourceLane.flowNodeRef).not.to.contain(event); })); + + it('should not create duplicate refs on attaching / detaching', inject(function(elementRegistry, modeling) { + + // given + var eventID = 'IntermediateThrowEvent', + throwEvent = elementRegistry.get(eventID), + task1 = elementRegistry.get('Task_1'), + task2 = elementRegistry.get('Task_2'), + lane1 = elementRegistry.get('Participant_C_Lane_1').businessObject, + lane2 = elementRegistry.get('Participant_C_Lane_2').businessObject; + + // when + modeling.moveElements([ throwEvent ], { x: -280, y: 30 }, task1, { attach: true }); + + var boundaryEvent = elementRegistry.get(eventID); + + modeling.moveElements([ boundaryEvent ], { x: 0, y: 150 }, task2, { attach: true }); + + // then + expect(lane1.flowNodeRef).not.to.contain(boundaryEvent.businessObject); + expect(lane2.flowNodeRef).to.contain(boundaryEvent.businessObject); + expect(lane1.flowNodeRef).to.have.length(1); + expect(lane2.flowNodeRef).to.have.length(2); + })); }); diff --git a/test/spec/features/modeling/lanes/flowNodeRefs.bpmn b/test/spec/features/modeling/lanes/flowNodeRefs.bpmn index dfa65134..3a405db1 100644 --- a/test/spec/features/modeling/lanes/flowNodeRefs.bpmn +++ b/test/spec/features/modeling/lanes/flowNodeRefs.bpmn @@ -1,8 +1,9 @@ - + - - + + + @@ -14,44 +15,76 @@ SequenceFlow - SequenceFlow + - + + + + + + Task_1 + IntermediateThrowEvent + + + Task_2 + + + + + - + - + - + - + - + - + - - + + - + - + + + + + + + + + + + + + + + + + + + - \ No newline at end of file +