From 643ca2193c0c5e889f88868958679b23c745894c Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Wed, 29 May 2019 08:10:34 +0200 Subject: [PATCH] fix(snapping): prevent participants snap to group bounds --- lib/features/snapping/BpmnSnapping.js | 2 +- test/fixtures/bpmn/collaboration/process.bpmn | 4 +++ .../behavior/CreateParticipantBehaviorSpec.js | 2 +- .../features/snapping/BpmnSnappingSpec.js | 28 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/features/snapping/BpmnSnapping.js b/lib/features/snapping/BpmnSnapping.js index 4920678d..81228378 100644 --- a/lib/features/snapping/BpmnSnapping.js +++ b/lib/features/snapping/BpmnSnapping.js @@ -403,7 +403,7 @@ function initParticipantSnapping(context, shape, elements) { } var snapBox = getBoundingBox(elements.filter(function(e) { - return !e.labelTarget && !e.waypoints; + return !e.labelTarget && !e.waypoints && !is(e, 'bpmn:Group'); })); snapBox.x -= 50; diff --git a/test/fixtures/bpmn/collaboration/process.bpmn b/test/fixtures/bpmn/collaboration/process.bpmn index 1ef9119b..3e0f1044 100644 --- a/test/fixtures/bpmn/collaboration/process.bpmn +++ b/test/fixtures/bpmn/collaboration/process.bpmn @@ -14,6 +14,7 @@ SequenceFlow_2 + @@ -39,6 +40,9 @@ + + + diff --git a/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js b/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js index db67208d..38cb935d 100644 --- a/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/CreateParticipantBehaviorSpec.js @@ -143,7 +143,7 @@ describe('features/modeling - create participant', function() { // then expect(participantShape.children.length).to.equal(0); - expect(processShape.children.length).to.equal(7); + expect(processShape.children.length).to.equal(8); // children di is wired expect(startEventDi.$parent).to.eql(rootShapeDi); diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index 1fd79ca4..528e9724 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -337,6 +337,34 @@ describe('features/snapping - BpmnSnapping', function() { ); + it('should not snap to group bounds', + inject(function(canvas, create, dragging, elementFactory, elementRegistry) { + + // given + var participantShape = elementFactory.createParticipantShape(false), + rootElement = canvas.getRootElement(), + rootGfx = canvas.getGraphics(rootElement), + groupElement = elementRegistry.get('Group_1'); + + // when + create.start(canvasEvent({ x: 50, y: 50 }), participantShape); + + dragging.hover({ element: rootElement, gfx: rootGfx }); + + dragging.move(canvasEvent({ x: 400, y: 400 })); + dragging.end(canvasEvent({ x: 400, y: 400 })); + + // then + var totalWidth = groupElement.x + groupElement.width + 70, + totalHeight = groupElement.y + groupElement.height + 40; + + expect(participantShape).not.to.have.bounds({ + width: totalWidth, height: totalHeight, x: 100, y: 52 + }); + }) + ); + + it('should snap to process children bounds / bottom right', inject(function(canvas, create, dragging, elementFactory) {