2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-10-11 09:22:51 +00:00
|
|
|
import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil';
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-10-11 09:22:51 +00:00
|
|
|
import {
|
|
|
|
DEFAULT_LABEL_SIZE,
|
|
|
|
getExternalLabelMid
|
|
|
|
} from 'lib/util/LabelUtil';
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
var testModules = [
|
|
|
|
modelingModule,
|
|
|
|
coreModule
|
|
|
|
];
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-06-05 05:48:33 +00:00
|
|
|
var ATTACH = { attach: true };
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
function expectLabelOrientation(element, expectedOrientation) {
|
|
|
|
|
|
|
|
var label = element.label;
|
|
|
|
|
|
|
|
// assume
|
|
|
|
expect(label).to.exist;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var orientation = getOrientation(label, element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(orientation).to.eql(expectedOrientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('basics', function() {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
var diagramXML = require('./AdaptiveLabelPositioningBehavior.basics.bpmn');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: testModules
|
2017-05-12 14:13:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('on connect', function() {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from LEFT to TOP', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelBottom'),
|
|
|
|
target = elementRegistry.get('LabelLeft');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
expectLabelOrientation(target, 'top');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from BOTTOM to TOP', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelBottom'),
|
|
|
|
target = elementRegistry.get('LabelRight');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'top');
|
|
|
|
expectLabelOrientation(target, 'right');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelRight'),
|
|
|
|
target = elementRegistry.get('LabelTop');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'top');
|
|
|
|
expectLabelOrientation(target, 'top');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelTop'),
|
|
|
|
target = elementRegistry.get('LabelLeft');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'left');
|
|
|
|
expectLabelOrientation(target, 'left');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelTop'),
|
|
|
|
target = elementRegistry.get('LabelLeft');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'left');
|
|
|
|
expectLabelOrientation(target, 'left');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from TOP to LEFT (inverse)', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelLeft'),
|
|
|
|
target = elementRegistry.get('LabelTop');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(target, 'left');
|
|
|
|
expectLabelOrientation(source, 'left');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should keep unaligned labels AS IS', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelBottomLeft'),
|
|
|
|
target = elementRegistry.get('LabelTop');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
expectLabelOrientation(target, 'top');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should keep label where it is, if no options', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelImpossible'),
|
|
|
|
target = elementRegistry.get('Task');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'right');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
});
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('on reconnect', function() {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// given
|
|
|
|
var connection = elementRegistry.get('SequenceFlow_1'),
|
|
|
|
source = elementRegistry.get('LabelTop'),
|
|
|
|
target = elementRegistry.get('LabelLeft');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.reconnectEnd(connection, target, { x: target.x + target.width / 2, y: target.y });
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
expectLabelOrientation(target, 'left');
|
|
|
|
}));
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
});
|
2017-05-12 14:13:07 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('on target move / layout', function() {
|
2018-07-11 11:10:18 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
2018-07-11 11:10:18 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelTop'),
|
|
|
|
target = elementRegistry.get('LabelBottom_3');
|
|
|
|
|
|
|
|
// when
|
2019-04-25 11:53:34 +00:00
|
|
|
modeling.moveElements([ source ], { x: 0, y: 300 });
|
2018-07-11 11:10:18 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
expectLabelOrientation(target, 'top');
|
2019-04-25 11:53:34 +00:00
|
|
|
}));
|
2018-07-11 11:10:18 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
});
|
2018-07-11 11:10:18 +00:00
|
|
|
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
describe('on source move / layout', function() {
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
it('should move label from BOTTOM to TOP', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('LabelTop'),
|
|
|
|
target = elementRegistry.get('LabelBottom_3');
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// when
|
|
|
|
modeling.moveElements([ target ], { x: 20, y: -300 });
|
2017-05-12 14:13:07 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
expectLabelOrientation(target, 'top');
|
|
|
|
}
|
|
|
|
));
|
2018-07-11 11:25:25 +00:00
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on waypoints update', function() {
|
|
|
|
|
|
|
|
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
2018-07-11 11:25:25 +00:00
|
|
|
|
|
|
|
// given
|
2019-04-25 11:53:34 +00:00
|
|
|
var connection = elementRegistry.get('SequenceFlow_2'),
|
|
|
|
source = elementRegistry.get('LabelRight'),
|
|
|
|
target = elementRegistry.get('LabelBottom');
|
2018-07-11 11:25:25 +00:00
|
|
|
|
|
|
|
// when
|
2019-04-25 11:53:34 +00:00
|
|
|
modeling.updateWaypoints(connection, [
|
|
|
|
{
|
|
|
|
original: { x: 131, y: 248 },
|
|
|
|
x: 131,
|
|
|
|
y: 248
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: 250,
|
|
|
|
y: 248
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: 250,
|
|
|
|
y: 394
|
|
|
|
},
|
|
|
|
{
|
|
|
|
original: { x: 131, y: 394 },
|
|
|
|
x: 131,
|
|
|
|
y: 394
|
|
|
|
},
|
|
|
|
]);
|
2018-07-11 11:25:25 +00:00
|
|
|
|
|
|
|
// then
|
2019-04-25 11:53:34 +00:00
|
|
|
expectLabelOrientation(source, 'top');
|
|
|
|
expectLabelOrientation(target, 'bottom');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on label creation', function() {
|
|
|
|
|
|
|
|
it('should create label at TOP', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('NoLabel');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.updateProperties(element, { name: 'FOO BAR' });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(element, 'top');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2019-10-11 09:22:51 +00:00
|
|
|
|
|
|
|
it('should not adjust position', inject(function(bpmnFactory, elementFactory, elementRegistry, modeling, textRenderer) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_1');
|
|
|
|
|
|
|
|
var intermediateThrowEvent = elementFactory.createShape({
|
|
|
|
businessObject: bpmnFactory.create('bpmn:IntermediateThrowEvent', {
|
|
|
|
name: 'Foo'
|
|
|
|
}),
|
|
|
|
type: 'bpmn:IntermediateThrowEvent',
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
var externalLabelMid = getExternalLabelMid(intermediateThrowEvent);
|
|
|
|
|
|
|
|
var externalLabelBounds = textRenderer.getExternalLabelBounds(DEFAULT_LABEL_SIZE, 'Foo');
|
|
|
|
|
|
|
|
var label = elementFactory.createLabel({
|
|
|
|
labelTarget: intermediateThrowEvent,
|
|
|
|
x: externalLabelMid.x - externalLabelBounds.width / 2,
|
|
|
|
y: externalLabelMid.y - externalLabelBounds.height / 2,
|
|
|
|
width: externalLabelBounds.width,
|
|
|
|
height: externalLabelBounds.height
|
|
|
|
});
|
|
|
|
|
|
|
|
var sequenceFlowMid = getConnectionMid(sequenceFlow.waypoints[0], sequenceFlow.waypoints[1]);
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.createElements([ intermediateThrowEvent, label ], sequenceFlowMid, sequenceFlow);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(label.x).to.be.closeTo(325, 1);
|
|
|
|
expect(label.y).to.be.closeTo(335, 1);
|
|
|
|
expect(label.width).to.be.closeTo(19, 1);
|
|
|
|
expect(label.height).to.be.closeTo(14, 1);
|
|
|
|
}));
|
|
|
|
|
2019-04-25 11:53:34 +00:00
|
|
|
});
|
|
|
|
|
2018-07-11 11:25:25 +00:00
|
|
|
});
|
|
|
|
|
2019-06-05 05:48:33 +00:00
|
|
|
|
|
|
|
describe('boundary-events', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./AdaptiveLabelPositioningBehavior.boundary-events.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: testModules
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('on boundary label creation', function() {
|
|
|
|
|
|
|
|
it('should NOT create label onto host', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('BoundaryEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.updateProperties(element, { name: 'FOO BAR' });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(element, 'bottom');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
it('should create label to the left', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('BoundaryEvent_4');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.updateProperties(element, { name: 'FOO BAR' });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(element, 'left');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on connect', function() {
|
|
|
|
|
|
|
|
it('should keep label where it is if no better position', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('BoundaryEvent_2'),
|
|
|
|
target = elementRegistry.get('EndEvent_2');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.connect(source, target);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'right');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on reconnect', function() {
|
|
|
|
|
|
|
|
it('should keep label where it is if no better position', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var source = elementRegistry.get('BoundaryEvent_3'),
|
|
|
|
target = elementRegistry.get('EndEvent_1'),
|
|
|
|
connection = elementRegistry.get('SequenceFlow_2');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.reconnectEnd(connection, target, { x: target.x + target.width / 2, y: target.y });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(source, 'bottom');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on boundary move', function() {
|
|
|
|
|
|
|
|
it('should move label to the left', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('BoundaryEvent_3'),
|
|
|
|
host = elementRegistry.get('Task_3');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements([ element ], { x: -50, y: -50 }, host, ATTACH);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(element, 'left');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
it('should move label to the top', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('BoundaryEvent_3'),
|
|
|
|
host = elementRegistry.get('Task_3');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements([ element ], { x: 50, y: -80 }, host, ATTACH); // top-right corner
|
|
|
|
|
|
|
|
// then
|
|
|
|
expectLabelOrientation(element, 'top');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-05-12 14:13:07 +00:00
|
|
|
});
|
2019-10-11 09:22:51 +00:00
|
|
|
|
|
|
|
// helpers //////////
|
|
|
|
|
|
|
|
function getConnectionMid(a, b) {
|
|
|
|
return {
|
|
|
|
x: (a.x + b.x) / 2,
|
|
|
|
y: (a.y + b.y) / 2
|
|
|
|
};
|
|
|
|
}
|