diff --git a/lib/draw/BpmnRenderer.js b/lib/draw/BpmnRenderer.js index c6fb95db..de761d43 100644 --- a/lib/draw/BpmnRenderer.js +++ b/lib/draw/BpmnRenderer.js @@ -1277,7 +1277,7 @@ function BpmnRenderer(eventBus, styles, pathMap, priority) { // update element.x so that the layouted text is still // center alligned (newX = oldMidX - newWidth / 2) - element.x = Math.round(element.x + element.width / 2) - Math.round((textBBox.width / 2)); + element.x = Math.ceil(element.x + element.width / 2) - Math.ceil((textBBox.width / 2)); // take element width, height from actual bounds element.width = Math.ceil(textBBox.width); diff --git a/test/spec/features/label-editing/LabelEditingProviderSpec.js b/test/spec/features/label-editing/LabelEditingProviderSpec.js index 036fcabb..78985aab 100644 --- a/test/spec/features/label-editing/LabelEditingProviderSpec.js +++ b/test/spec/features/label-editing/LabelEditingProviderSpec.js @@ -1,7 +1,5 @@ 'use strict'; -var TestContainer = require('mocha-test-container-support'); - var TestHelper = require('../../../TestHelper'); /* global bootstrapViewer, inject */ @@ -513,12 +511,6 @@ describe('features - label-editing', function() { describe('zoom', function() { - var container; - - beforeEach(function() { - container = TestContainer.get(this); - }); - it('should have fixed dimensions (low zoom)', testTextboxSizing('empty-task', 0.5, 100, 80, oneWord)); it('should have fixed dimensions (high zoom)', testTextboxSizing('empty-task', 1.5, 150, 120, oneWord)); @@ -526,7 +518,7 @@ describe('features - label-editing', function() { it('should center text box position (low zoom)', inject(function(canvas, elementRegistry, directEditing) { // given - canvas.zoom(0.5); + canvas.zoom(0.5, { x: 0, y: 0 }); var shape = elementRegistry.get('empty-task'); @@ -534,17 +526,10 @@ describe('features - label-editing', function() { directEditing.activate(shape); // then - var textbox = directEditing._textbox, - gfx = elementRegistry.getGraphics('empty-task'), - shapeClientRect = gfx.node.parentNode.getBoundingClientRect(); + var textbox = directEditing._textbox; - var shapeRect = { - top: shapeClientRect.top - container.offsetTop, - left: shapeClientRect.left - container.offsetLeft - }; - - expect(textbox.content.offsetLeft).to.be.within(shapeRect.left - 28, shapeRect.left - 22); - expect(textbox.content.offsetTop).to.be.within(shapeRect.top - 22, shapeRect.top - 17); + expect(textbox.content.offsetLeft).to.equal(211); + expect(textbox.content.offsetTop).to.equal(17); })); diff --git a/test/spec/features/modeling/LabelBoundsSpec.js b/test/spec/features/modeling/LabelBoundsSpec.js index fb0b4bbb..621f5260 100644 --- a/test/spec/features/modeling/LabelBoundsSpec.js +++ b/test/spec/features/modeling/LabelBoundsSpec.js @@ -108,9 +108,9 @@ describe('label bounds', function() { describe('label position', function() { var getExpectedX = function(shape) { - var shapeMid = shape.x + shape.width/2; + var shapeMid = shape.x + Math.ceil(shape.width/2); - return Math.round(shapeMid - shape.label.width/2); + return shapeMid - Math.ceil(shape.label.width/2); }; it('should shift to left', inject(function(elementRegistry) { @@ -124,7 +124,7 @@ describe('label bounds', function() { // then var expectedX = getExpectedX(shape); - expect(shape.label.x).to.be.within(expectedX - 1, expectedX); + expect(shape.label.x).to.equal(expectedX); })); @@ -139,7 +139,25 @@ describe('label bounds', function() { // then var expectedX = getExpectedX(shape); - expect(shape.label.x).to.be.within(expectedX -1, expectedX); + expect(shape.label.x).to.equal(expectedX); + })); + + + it('should remain the same', inject(function(elementRegistry) { + + // given + var shape = elementRegistry.get('StartEvent_1'); + + // when + updateLabel(shape, 'FOOBAR'); + + // copy old horizontal label position + var oldX = shape.label.x + 0; + + updateLabel(shape, 'FOOBAR\n1'); + + // then + expect(shape.label.x).to.equal(oldX); })); }); diff --git a/test/spec/features/modeling/LabelLayoutingSpec.js b/test/spec/features/modeling/LabelLayoutingSpec.js index 79017225..15ea5b6e 100644 --- a/test/spec/features/modeling/LabelLayoutingSpec.js +++ b/test/spec/features/modeling/LabelLayoutingSpec.js @@ -309,7 +309,7 @@ describe('modeling - label layouting', function() { dragging.end(); // then - expect(Math.round(connection.label.x)).to.be.equal(467); + expect(Math.round(connection.label.x)).to.be.within(467, 468); expect(Math.round(connection.label.y)).to.be.within(170, 171); })); @@ -502,7 +502,7 @@ describe('modeling - label layouting', function() { dragging.end(); // then - expect(connection.label.y - labelPosition.y).to.be.within(-76, -72); + expect(connection.label.y - labelPosition.y).to.be.within(-76, -70); expect(connection.label.x - labelPosition.x).to.be.within(-53, -51); })); diff --git a/test/spec/import/elements/LabelSpec.js b/test/spec/import/elements/LabelSpec.js index f520da0d..99ad4095 100644 --- a/test/spec/import/elements/LabelSpec.js +++ b/test/spec/import/elements/LabelSpec.js @@ -51,12 +51,12 @@ describe('import - labels', function() { expect(endEvent.label.x).to.be.within(236, 237); expect(endEvent.label.y).to.be.within(256, 256); expect(endEvent.label.width).to.be.within(68, 69); - expect(endEvent.label.height).to.be.within(25, 30); + expect(endEvent.label.height).to.be.within(23, 30); expect(sequenceFlow.label.x).to.be.within(441, 442); expect(sequenceFlow.label.y).to.be.within(316, 317); expect(sequenceFlow.label.width).to.be.within(79, 82); - expect(sequenceFlow.label.height).to.be.within(13, 15); + expect(sequenceFlow.label.height).to.be.within(11, 15); done(); })();