bpmn-js 0.20.3 → 0.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,26 +75,28 @@ describe('modeling - label layouting', function() {
75
75
 
76
76
  describe('on segment move', function() {
77
77
 
78
- it('label name not set -> move label to waypoints mid', inject(function(modeling, elementRegistry, connectionSegmentMove, dragging) {
78
+ it('label name not set -> move label to waypoints mid', inject(
79
+ function(modeling, elementRegistry, connectionSegmentMove, dragging) {
79
80
 
80
- // given
81
- var connection = elementRegistry.get('SequenceFlow_C'),
82
- labelPosition = getLabelPosition(connection);
81
+ // given
82
+ var connection = elementRegistry.get('SequenceFlow_C'),
83
+ labelPosition = getLabelPosition(connection);
83
84
 
84
- connection.label.businessObject.name = false;
85
- connection.label.hidden = true;
85
+ connection.label.businessObject.name = false;
86
+ connection.label.hidden = true;
86
87
 
87
- // when
88
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
88
+ // when
89
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
89
90
 
90
- dragging.move(canvasEvent({ x: 0, y: 50 }));
91
+ dragging.move(canvasEvent({ x: 0, y: 50 }));
91
92
 
92
- dragging.end();
93
+ dragging.end();
93
94
 
94
- // then
95
- expect(connection.label.y - labelPosition.y).to.be.within(13, 16);
96
- expect(connection.label.x - labelPosition.x).to.be.within(-87, -85);
97
- }));
95
+ // then
96
+ expect(connection.label.y - labelPosition.y).to.be.within(13, 16);
97
+ expect(connection.label.x - labelPosition.x).to.be.within(-87, -85);
98
+ }
99
+ ));
98
100
 
99
101
 
100
102
  it('left - no relayout', inject(function(elementRegistry, connectionSegmentMove, dragging) {
@@ -115,58 +117,64 @@ describe('modeling - label layouting', function() {
115
117
  }));
116
118
 
117
119
 
118
- it('left - remove bendpoint', inject(function(elementRegistry, connectionSegmentMove, dragging) {
120
+ it('left - remove bendpoint', inject(
121
+ function(elementRegistry, connectionSegmentMove, dragging) {
119
122
 
120
- // given
121
- var connection = elementRegistry.get('SequenceFlow_B'),
122
- labelPosition = getLabelPosition(connection);
123
+ // given
124
+ var connection = elementRegistry.get('SequenceFlow_B'),
125
+ labelPosition = getLabelPosition(connection);
123
126
 
124
- // when
125
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
127
+ // when
128
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
126
129
 
127
- dragging.move(canvasEvent({ x: -70, y: 0 }));
130
+ dragging.move(canvasEvent({ x: -70, y: 0 }));
128
131
 
129
- dragging.end();
132
+ dragging.end();
130
133
 
131
- // then
132
- expectLabelMoved(connection, labelPosition, { x: -70, y: 24 });
133
- }));
134
+ // then
135
+ expectLabelMoved(connection, labelPosition, { x: -70, y: 24 });
136
+ }
137
+ ));
134
138
 
135
139
 
136
- it('right - no relayout', inject(function(elementRegistry, connectionSegmentMove, dragging) {
140
+ it('right - no relayout', inject(
141
+ function(elementRegistry, connectionSegmentMove, dragging) {
137
142
 
138
- // given
139
- var connection = elementRegistry.get('SequenceFlow_B'),
140
- labelPosition = getLabelPosition(connection);
143
+ // given
144
+ var connection = elementRegistry.get('SequenceFlow_B'),
145
+ labelPosition = getLabelPosition(connection);
141
146
 
142
- // when
143
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
147
+ // when
148
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
144
149
 
145
- dragging.move(canvasEvent({ x: 30, y: 0 }));
150
+ dragging.move(canvasEvent({ x: 30, y: 0 }));
146
151
 
147
- dragging.end();
152
+ dragging.end();
148
153
 
149
- // then
150
- expectLabelMoved(connection, labelPosition, { x: 30, y: 0 });
151
- }));
154
+ // then
155
+ expectLabelMoved(connection, labelPosition, { x: 30, y: 0 });
156
+ }
157
+ ));
152
158
 
153
159
 
154
- it('right - remove bendpoint', inject(function(elementRegistry, connectionSegmentMove, dragging) {
160
+ it('right - remove bendpoint', inject(
161
+ function(elementRegistry, connectionSegmentMove, dragging) {
155
162
 
156
- // given
157
- var connection = elementRegistry.get('SequenceFlow_B'),
158
- labelPosition = getLabelPosition(connection);
163
+ // given
164
+ var connection = elementRegistry.get('SequenceFlow_B'),
165
+ labelPosition = getLabelPosition(connection);
159
166
 
160
- // when
161
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
167
+ // when
168
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
162
169
 
163
- dragging.move(canvasEvent({ x: 70, y: 0 }));
170
+ dragging.move(canvasEvent({ x: 70, y: 0 }));
164
171
 
165
- dragging.end();
172
+ dragging.end();
166
173
 
167
- // then
168
- expectLabelMoved(connection, labelPosition, { x: 70, y: -16 });
169
- }));
174
+ // then
175
+ expectLabelMoved(connection, labelPosition, { x: 70, y: -16 });
176
+ }
177
+ ));
170
178
 
171
179
 
172
180
  it('down', inject(function(elementRegistry, connectionSegmentMove, dragging) {
@@ -188,50 +196,54 @@ describe('modeling - label layouting', function() {
188
196
  }));
189
197
 
190
198
 
191
- it('up - remove two bendpoints', inject(function(elementRegistry, connectionSegmentMove, dragging) {
199
+ it('up - remove two bendpoints', inject(
200
+ function(elementRegistry, connectionSegmentMove, dragging) {
192
201
 
193
- // given
194
- var connection = elementRegistry.get('SequenceFlow_C'),
195
- labelPosition = getLabelPosition(connection);
202
+ // given
203
+ var connection = elementRegistry.get('SequenceFlow_C'),
204
+ labelPosition = getLabelPosition(connection);
196
205
 
197
- // when
198
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
206
+ // when
207
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
199
208
 
200
- dragging.move(canvasEvent({ x: 0, y: -90 }));
209
+ dragging.move(canvasEvent({ x: 0, y: -90 }));
201
210
 
202
- dragging.end();
211
+ dragging.end();
203
212
 
204
- // then
205
- expectLabelMoved(connection, labelPosition, { x: -39, y: -85 });
213
+ // then
214
+ expectLabelMoved(connection, labelPosition, { x: -39, y: -85 });
206
215
 
207
- }));
216
+ }
217
+ ));
208
218
 
209
219
 
210
220
  // TODO(@janstuemmel): solve by connectionSegmentMove refactoring
211
- it('up - remove two bendpoints - redundant waypoints', inject(function(elementRegistry, connectionSegmentMove, dragging, bendpointMove) {
221
+ it('up - remove two bendpoints - redundant waypoints', inject(
222
+ function(elementRegistry, connectionSegmentMove, dragging, bendpointMove) {
212
223
 
213
- // given
214
- var connection = elementRegistry.get('SequenceFlow_C');
224
+ // given
225
+ var connection = elementRegistry.get('SequenceFlow_C');
215
226
 
216
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
217
- dragging.move(canvasEvent({ x: 620, y: 435 }));
218
- dragging.end();
227
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
228
+ dragging.move(canvasEvent({ x: 620, y: 435 }));
229
+ dragging.end();
219
230
 
220
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
221
- dragging.move(canvasEvent({ x: 300, y: 435 }));
222
- dragging.end();
231
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
232
+ dragging.move(canvasEvent({ x: 300, y: 435 }));
233
+ dragging.end();
223
234
 
224
- var labelPosition = getLabelPosition(connection);
235
+ var labelPosition = getLabelPosition(connection);
225
236
 
226
- // when
227
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
228
- dragging.move(canvasEvent({ x: 0, y: -160 }));
229
- dragging.end();
237
+ // when
238
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
239
+ dragging.move(canvasEvent({ x: 0, y: -160 }));
240
+ dragging.end();
230
241
 
231
- // then
232
- expect(getLabelPosition(connection)).to.not.eql(labelPosition);
242
+ // then
243
+ expect(getLabelPosition(connection)).to.not.eql(labelPosition);
233
244
 
234
- }));
245
+ }
246
+ ));
235
247
 
236
248
  });
237
249
 
@@ -314,245 +326,212 @@ describe('modeling - label layouting', function() {
314
326
  }));
315
327
 
316
328
 
317
- it('move, label on bendpoint', inject(function(elementRegistry, bendpointMove, dragging, modeling) {
329
+ it('move, label on bendpoint', inject(
330
+ function(elementRegistry, bendpointMove, dragging, modeling) {
318
331
 
319
- // given
320
- var connection = elementRegistry.get('SequenceFlow_C');
321
-
322
- // label out of segments, on a bendpoint (idx=1)
323
- modeling.moveShape(connection.label, { x: 40, y: 0 });
332
+ // given
333
+ var connection = elementRegistry.get('SequenceFlow_C');
324
334
 
325
- // when
326
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
335
+ // label out of segments, on a bendpoint (idx=1)
336
+ modeling.moveShape(connection.label, { x: 40, y: 0 });
327
337
 
328
- dragging.move(canvasEvent({ x: 455 + 50, y: 500 }));
338
+ // when
339
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
329
340
 
330
- dragging.end();
341
+ dragging.move(canvasEvent({ x: 455 + 50, y: 500 }));
331
342
 
332
- // then
333
- expect(Math.round(connection.label.x)).to.be.within(517, 519);
334
- expect(Math.round(connection.label.y)).to.be.equal(507);
343
+ dragging.end();
335
344
 
336
- }));
345
+ // then
346
+ expect(Math.round(connection.label.x)).to.be.within(517, 519);
347
+ expect(Math.round(connection.label.y)).to.be.equal(507);
337
348
 
349
+ }
350
+ ));
338
351
 
339
- it('remove bendpoint when label on segment', inject(function(elementRegistry, bendpointMove, dragging) {
340
352
 
341
- // given
342
- var connection = elementRegistry.get('SequenceFlow_B');
353
+ it('remove bendpoint when label on segment', inject(
354
+ function(elementRegistry, bendpointMove, dragging) {
343
355
 
344
- // when
345
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
356
+ // given
357
+ var connection = elementRegistry.get('SequenceFlow_B');
346
358
 
347
- dragging.move(canvasEvent({ x: 455, y: 120 + 160 }));
359
+ // when
360
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
348
361
 
349
- dragging.end();
362
+ dragging.move(canvasEvent({ x: 455, y: 120 + 160 }));
350
363
 
351
- // then
352
- expect(Math.round(connection.label.x)).to.be.within(418, 421);
353
- expect(Math.round(connection.label.y)).to.be.equal(191);
364
+ dragging.end();
354
365
 
355
- }));
366
+ // then
367
+ expect(Math.round(connection.label.x)).to.be.within(418, 421);
368
+ expect(Math.round(connection.label.y)).to.be.equal(191);
356
369
 
370
+ }
371
+ ));
357
372
 
358
- it('add bendpoint, label on right segment', inject(function(elementRegistry, bendpointMove, dragging, canvas) {
359
373
 
360
- // given
361
- var connection = elementRegistry.get('SequenceFlow_A');
374
+ it('add bendpoint, label on right segment', inject(
375
+ function(elementRegistry, bendpointMove, dragging, canvas) {
362
376
 
363
- // when
364
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1, true);
377
+ // given
378
+ var connection = elementRegistry.get('SequenceFlow_A');
365
379
 
366
- dragging.hover({
367
- element: connection,
368
- gfx: canvas.getGraphics(connection)
369
- });
380
+ // when
381
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1, true);
370
382
 
371
- dragging.move(canvasEvent({ x: 220, y: 200 }));
383
+ dragging.hover({
384
+ element: connection,
385
+ gfx: canvas.getGraphics(connection)
386
+ });
372
387
 
373
- dragging.end();
388
+ dragging.move(canvasEvent({ x: 220, y: 200 }));
374
389
 
375
- // then
376
- expect(Math.round(connection.label.x)).to.be.within(248, 251);
377
- expect(Math.round(connection.label.y)).to.be.equal(152);
390
+ dragging.end();
378
391
 
379
- }));
392
+ // then
393
+ expect(Math.round(connection.label.x)).to.be.within(248, 251);
394
+ expect(Math.round(connection.label.y)).to.be.equal(152);
380
395
 
396
+ }
397
+ ));
381
398
 
382
- it('add bendpoint, label on left segment', inject(function(elementRegistry, bendpointMove, dragging, canvas) {
383
399
 
384
- // given
385
- var connection = elementRegistry.get('SequenceFlow_A');
400
+ it('add bendpoint, label on left segment', inject(
401
+ function(elementRegistry, bendpointMove, dragging, canvas) {
386
402
 
387
- // when
388
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1, true);
403
+ // given
404
+ var connection = elementRegistry.get('SequenceFlow_A');
389
405
 
390
- dragging.hover({
391
- element: connection,
392
- gfx: canvas.getGraphics(connection)
393
- });
406
+ // when
407
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1, true);
394
408
 
395
- dragging.move(canvasEvent({ x: 260, y: 200 }));
409
+ dragging.hover({
410
+ element: connection,
411
+ gfx: canvas.getGraphics(connection)
412
+ });
396
413
 
397
- dragging.end();
414
+ dragging.move(canvasEvent({ x: 260, y: 200 }));
398
415
 
399
- // then
400
- expect(Math.round(connection.label.x)).to.be.within(240, 242);
401
- expect(Math.round(connection.label.y)).to.be.equal(148);
416
+ dragging.end();
402
417
 
418
+ // then
419
+ expect(Math.round(connection.label.x)).to.be.within(240, 242);
420
+ expect(Math.round(connection.label.y)).to.be.equal(148);
403
421
 
404
- }));
422
+ }
423
+ ));
405
424
 
406
425
 
407
- it('remove bendpoint when label on bendpoint', inject(function(elementRegistry, bendpointMove, dragging, modeling) {
426
+ it('remove bendpoint when label on bendpoint', inject(
427
+ function(elementRegistry, bendpointMove, dragging, modeling) {
408
428
 
409
- // given
410
- var connection = elementRegistry.get('SequenceFlow_C');
429
+ // given
430
+ var connection = elementRegistry.get('SequenceFlow_C');
411
431
 
412
- // label out of segments, on a bendpoint
413
- modeling.moveShape(connection.label, { x: 40, y: 0 });
432
+ // label out of segments, on a bendpoint
433
+ modeling.moveShape(connection.label, { x: 40, y: 0 });
414
434
 
415
- // when
416
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
435
+ // when
436
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
417
437
 
418
- dragging.move(canvasEvent({ x: 455, y: 320 }));
438
+ dragging.move(canvasEvent({ x: 455, y: 320 }));
419
439
 
420
- dragging.end();
440
+ dragging.end();
421
441
 
422
- // then
423
- expect(Math.round(connection.label.x)).to.be.within(462, 465);
424
- expect(Math.round(connection.label.y)).to.be.within(290, 293);
442
+ // then
443
+ expect(Math.round(connection.label.x)).to.be.within(462, 465);
444
+ expect(Math.round(connection.label.y)).to.be.within(290, 293);
425
445
 
426
- }));
446
+ }
447
+ ));
427
448
 
428
449
 
429
- it('add benpoint, label on segment, should not move', inject(function(elementRegistry, bendpointMove, canvas, dragging, modeling) {
450
+ it('add benpoint, label on segment, should not move', inject(
451
+ function(elementRegistry, bendpointMove, canvas, dragging, modeling) {
430
452
 
431
- // given
432
- var connection = elementRegistry.get('SequenceFlow_C');
453
+ // given
454
+ var connection = elementRegistry.get('SequenceFlow_C');
433
455
 
434
- // label out of segments, on a bendpoint
435
- modeling.moveShape(connection.label, { x: 40, y: -60 });
436
- var position = getLabelPosition(connection);
456
+ // label out of segments, on a bendpoint
457
+ modeling.moveShape(connection.label, { x: 40, y: -60 });
458
+ var position = getLabelPosition(connection);
437
459
 
438
- // when
439
- bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2, true);
460
+ // when
461
+ bendpointMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2, true);
440
462
 
441
- dragging.hover({
442
- element: connection,
443
- gfx: canvas.getGraphics(connection)
444
- });
463
+ dragging.hover({
464
+ element: connection,
465
+ gfx: canvas.getGraphics(connection)
466
+ });
445
467
 
446
- dragging.move(canvasEvent({ x: 400, y: 350 }));
468
+ dragging.move(canvasEvent({ x: 400, y: 350 }));
447
469
 
448
- dragging.end();
470
+ dragging.end();
449
471
 
450
- // then
451
- expectLabelMoved(connection, position, { x: 0, y: 0 });
472
+ // then
473
+ expectLabelMoved(connection, position, { x: 0, y: 0 });
452
474
 
453
- }));
475
+ }
476
+ ));
454
477
 
455
478
  });
456
479
 
457
480
 
458
481
  describe('special cases', function() {
459
482
 
460
- it('should behave properly, right after importing', inject(function(elementRegistry, connectionSegmentMove, dragging, modeling) {
483
+ it('should behave properly, right after importing', inject(
484
+ function(elementRegistry, connectionSegmentMove, dragging, modeling) {
461
485
 
462
- // given
463
- var connection = elementRegistry.get('SequenceFlow_C'),
464
- labelPosition = getLabelPosition(connection),
465
- label = connection.label;
466
-
467
- // when
468
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
469
-
470
- dragging.move(canvasEvent({ x: 0, y: 70 }));
471
-
472
- dragging.end();
473
-
474
- // move label
475
- modeling.moveShape(label, { x: 40, y: -30 });
476
-
477
- // drag again
478
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
479
-
480
- dragging.move(canvasEvent({ x: -20, y: 0 }));
481
-
482
- dragging.end();
483
-
484
- // then
485
- expectLabelMoved(connection, labelPosition, { x: 20, y: 40 });
486
-
487
- }));
488
-
489
-
490
- it('should reposition on right segment', inject(function(elementRegistry, connectionSegmentMove, dragging) {
491
-
492
- // given
493
- var connection = elementRegistry.get('SequenceFlow_E'),
494
- labelPosition = getLabelPosition(connection);
495
-
496
- // when
497
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
498
-
499
- dragging.move(canvasEvent({ x: -100, y: 0 }));
500
-
501
- dragging.end();
502
-
503
- // then
504
- expect(connection.label.y - labelPosition.y).to.be.within(-76, -70);
505
- expect(connection.label.x - labelPosition.x).to.be.within(-54, -51);
506
-
507
- }));
508
-
509
-
510
- describe.skip('label out of bounds', function() {
486
+ // given
487
+ var connection = elementRegistry.get('SequenceFlow_C'),
488
+ labelPosition = getLabelPosition(connection),
489
+ label = connection.label;
511
490
 
512
- it('should not move label that is out of bounds', inject(function(elementRegistry, connectionSegmentMove, dragging, modeling) {
491
+ // when
492
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
513
493
 
514
- // given
515
- var connection = elementRegistry.get('SequenceFlow_C');
494
+ dragging.move(canvasEvent({ x: 0, y: 70 }));
516
495
 
517
- // move shape away
518
- modeling.moveShape(connection.label, { x: 0, y: 140 });
496
+ dragging.end();
519
497
 
520
- var labelPosition = getLabelPosition(connection);
498
+ // move label
499
+ modeling.moveShape(label, { x: 40, y: -30 });
521
500
 
522
- // when
523
- connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
501
+ // drag again
502
+ connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
524
503
 
525
- dragging.move(canvasEvent({ x: 0, y: 30 }));
504
+ dragging.move(canvasEvent({ x: -20, y: 0 }));
526
505
 
527
506
  dragging.end();
528
507
 
529
508
  // then
530
- expectLabelMoved(connection, labelPosition, { x: 0, y: 0 });
531
- }));
532
-
509
+ expectLabelMoved(connection, labelPosition, { x: 20, y: 40 });
533
510
 
534
- it('should not move label that is out of bounds in corner', inject(function(elementRegistry, connectionSegmentMove, dragging, modeling) {
511
+ }
512
+ ));
535
513
 
536
- // given
537
- var connection = elementRegistry.get('SequenceFlow_C');
538
514
 
539
- // move shape away
540
- modeling.moveShape(connection.label, { x: 50, y: 0 });
515
+ it('should reposition on right segment', inject(
516
+ function(elementRegistry, connectionSegmentMove, dragging) {
541
517
 
542
- var labelPosition = getLabelPosition(connection);
518
+ // given
519
+ var connection = elementRegistry.get('SequenceFlow_E'),
520
+ labelPosition = getLabelPosition(connection);
543
521
 
544
522
  // when
545
523
  connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
546
524
 
547
- dragging.move(canvasEvent({ x: 0, y: 30 }));
525
+ dragging.move(canvasEvent({ x: -100, y: 0 }));
548
526
 
549
527
  dragging.end();
550
528
 
551
529
  // then
552
- expectLabelMoved(connection, labelPosition, { x: 0, y: 0 });
553
- }));
530
+ expect(connection.label.y - labelPosition.y).to.be.within(-76, -70);
531
+ expect(connection.label.x - labelPosition.x).to.be.within(-54, -51);
554
532
 
555
- });
533
+ }
534
+ ));
556
535
 
557
536
  });
558
537
 
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ var getLabelAdjustment = require('lib/features/modeling/behavior/util/LabelLayoutUtil').getLabelAdjustment;
4
+
5
+
6
+ describe('modeling/behavior/util - LabelLayoutUtil#getLabelAdjustment', function() {
7
+
8
+ describe('should recognize on the line label', function() {
9
+
10
+ var newLine = [
11
+ { x: 10, y: 10 },
12
+ // -
13
+ { x: 15, y: 10 },
14
+ // |
15
+ { x: 15, y: 5 },
16
+ // -
17
+ { x: 30, y: 5 }
18
+ ];
19
+
20
+
21
+ it('horizontal', function() {
22
+
23
+ // given
24
+ var line = [
25
+ { x: 10, y: 10 },
26
+ // -
27
+ { x: 20, y: 10 }
28
+ ];
29
+
30
+ // label with center { x: 5, y: 10 }
31
+
32
+ var label = {
33
+ x: 0,
34
+ y: 5,
35
+ width: 10,
36
+ height: 10
37
+ };
38
+
39
+ // when
40
+ var delta = getLabelAdjustment(label, newLine, line, { connectionStart: true });
41
+
42
+ // then
43
+ expect(delta).to.eql({ x: 0, y: 0 });
44
+ });
45
+
46
+
47
+ it('zero-length line', function() {
48
+
49
+ // given
50
+ var line = [
51
+ { x: 10, y: 10 },
52
+ // -
53
+ { x: 10, y: 10 }
54
+ ];
55
+
56
+ // label with center { x: 5, y: 10 }
57
+
58
+ var label = {
59
+ x: 0,
60
+ y: 5,
61
+ width: 10,
62
+ height: 10
63
+ };
64
+
65
+ // when
66
+ var delta = getLabelAdjustment(label, newLine, line, { connectionStart: true });
67
+
68
+ // then
69
+ expect(delta).to.eql({ x: 0, y: 0 });
70
+ });
71
+
72
+ });
73
+
74
+
75
+ });