diff --git a/lib/features/snapping/BpmnSnapping.js b/lib/features/snapping/BpmnSnapping.js index f5f3c50a..63c8ca1c 100644 --- a/lib/features/snapping/BpmnSnapping.js +++ b/lib/features/snapping/BpmnSnapping.js @@ -215,7 +215,7 @@ BpmnSnapping.prototype.initSnap = function(event) { BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) { // use target parent as snap target - if (is(shape, 'bpmn:BoundaryEvent')) { + if (is(shape, 'bpmn:BoundaryEvent') && shape.type !== 'label') { target = target.parent; } @@ -385,4 +385,4 @@ function computeParticipantMinBounds(element) { if (childrenBoxes.length) { return getBBox(childrenBoxes); } -} \ No newline at end of file +} diff --git a/test/spec/features/snapping/BpmnSnapping.labels.bpmn b/test/spec/features/snapping/BpmnSnapping.labels.bpmn new file mode 100644 index 00000000..71b8bf56 --- /dev/null +++ b/test/spec/features/snapping/BpmnSnapping.labels.bpmn @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index 0023c60c..e6db5a0e 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -14,7 +14,6 @@ var coreModule = require('../../../../lib/core'), moveModule = require('diagram-js/lib/features/move'), rulesModule = require('../../../../lib/features/rules'); - describe('features/snapping - BpmnSnapping', function() { var testModules = [ coreModule, snappingModule, modelingModule, createModule, rulesModule, moveModule ]; @@ -401,4 +400,81 @@ describe('features/snapping - BpmnSnapping', function() { }); + describe('labels', function() { + + var diagramXML = require('./BpmnSnapping.labels.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + it('should snap to start events', inject(function(canvas, elementRegistry, move, dragging) { + + var label = elementRegistry.get('StartEvent_1_label'), + rootElement = canvas.getRootElement(); + + var originalPosition = { x: label.x, y: label.y }; + + move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label); + + dragging.hover({ + element: rootElement, + gfx: elementRegistry.getGraphics(rootElement) + }); + + dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 })); + dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 })); + + dragging.end(); + + expect(label.x).to.equal(originalPosition.x); + + })); + + + it('should snap to boundary events', inject(function(canvas, elementRegistry, move, dragging) { + + var label = elementRegistry.get('BoundaryEvent_1_label'), + rootElement = canvas.getRootElement(); + + var originalPosition = { x: label.x, y: label.y }; + + move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label); + + dragging.hover({ + element: rootElement, + gfx: elementRegistry.getGraphics(rootElement) + }); + + dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 })); + dragging.move(canvasEvent({ x: label.x+4, y: label.y+40 })); + + dragging.end(); + + expect(label.x).to.equal(originalPosition.x); + + })); + + + it('should snap to siblings', inject(function(canvas, elementRegistry, move, dragging) { + + var label = elementRegistry.get('BoundaryEvent_1_label'), + rootElement = canvas.getRootElement(); + + move.start(canvasEvent({ x: label.x+2, y: label.y+2 }), label); + + dragging.hover({ + element: rootElement, + gfx: elementRegistry.getGraphics(rootElement) + }); + + dragging.move(canvasEvent({ x: label.x-23, y: label.y+40 })); + dragging.move(canvasEvent({ x: label.x-23, y: label.y+40 })); + + dragging.end(); + + expect(label.x).to.equal(161); + + })); + + }); + });