@@ -3,13 +3,16 @@ import {
33 inject
44} from 'test/TestHelper' ;
55
6- import {
7- getOrientation
8- } from 'diagram-js/lib/layout/LayoutUtil' ;
6+ import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil' ;
97
108import modelingModule from 'lib/features/modeling' ;
119import coreModule from 'lib/core' ;
1210
11+ import {
12+ DEFAULT_LABEL_SIZE ,
13+ getExternalLabelMid
14+ } from 'lib/util/LabelUtil' ;
15+
1316var testModules = [
1417 modelingModule ,
1518 coreModule
@@ -281,6 +284,45 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
281284 }
282285 ) ) ;
283286
287+
288+ it ( 'should not adjust position' , inject ( function ( bpmnFactory , elementFactory , elementRegistry , modeling , textRenderer ) {
289+
290+ // given
291+ var sequenceFlow = elementRegistry . get ( 'SequenceFlow_1' ) ;
292+
293+ var intermediateThrowEvent = elementFactory . createShape ( {
294+ businessObject : bpmnFactory . create ( 'bpmn:IntermediateThrowEvent' , {
295+ name : 'Foo'
296+ } ) ,
297+ type : 'bpmn:IntermediateThrowEvent' ,
298+ x : 0 ,
299+ y : 0
300+ } ) ;
301+
302+ var externalLabelMid = getExternalLabelMid ( intermediateThrowEvent ) ;
303+
304+ var externalLabelBounds = textRenderer . getExternalLabelBounds ( DEFAULT_LABEL_SIZE , 'Foo' ) ;
305+
306+ var label = elementFactory . createLabel ( {
307+ labelTarget : intermediateThrowEvent ,
308+ x : externalLabelMid . x - externalLabelBounds . width / 2 ,
309+ y : externalLabelMid . y - externalLabelBounds . height / 2 ,
310+ width : externalLabelBounds . width ,
311+ height : externalLabelBounds . height
312+ } ) ;
313+
314+ var sequenceFlowMid = getConnectionMid ( sequenceFlow . waypoints [ 0 ] , sequenceFlow . waypoints [ 1 ] ) ;
315+
316+ // when
317+ modeling . createElements ( [ intermediateThrowEvent , label ] , sequenceFlowMid , sequenceFlow ) ;
318+
319+ // then
320+ expect ( label . x ) . to . be . closeTo ( 325 , 1 ) ;
321+ expect ( label . y ) . to . be . closeTo ( 335 , 1 ) ;
322+ expect ( label . width ) . to . be . closeTo ( 19 , 1 ) ;
323+ expect ( label . height ) . to . be . closeTo ( 14 , 1 ) ;
324+ } ) ) ;
325+
284326 } ) ;
285327
286328 } ) ;
@@ -407,3 +449,12 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
407449 } ) ;
408450
409451} ) ;
452+
453+ // helpers //////////
454+
455+ function getConnectionMid ( a , b ) {
456+ return {
457+ x : ( a . x + b . x ) / 2 ,
458+ y : ( a . y + b . y ) / 2
459+ } ;
460+ }
0 commit comments