test(modeling/behavior): reorganize label positioning behavior specs
This commit is contained in:
parent
8df95ed754
commit
2935b23ee4
|
@ -10,19 +10,14 @@ import {
|
||||||
import modelingModule from 'lib/features/modeling';
|
import modelingModule from 'lib/features/modeling';
|
||||||
import coreModule from 'lib/core';
|
import coreModule from 'lib/core';
|
||||||
|
|
||||||
|
var testModules = [
|
||||||
|
modelingModule,
|
||||||
|
coreModule
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
|
describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
|
||||||
|
|
||||||
var diagramXML = require('./AdaptiveLabelPositioningBehavior.bpmn');
|
|
||||||
|
|
||||||
beforeEach(bootstrapModeler(diagramXML, {
|
|
||||||
modules: [
|
|
||||||
modelingModule,
|
|
||||||
coreModule
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
function expectLabelOrientation(element, expectedOrientation) {
|
function expectLabelOrientation(element, expectedOrientation) {
|
||||||
|
|
||||||
var label = element.label;
|
var label = element.label;
|
||||||
|
@ -38,243 +33,255 @@ describe('modeling/behavior - AdaptiveLabelPositioningBehavior', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
describe('on connect', function() {
|
describe('basics', function() {
|
||||||
|
|
||||||
it('should move label from LEFT to TOP', inject(function(elementRegistry, modeling) {
|
var diagramXML = require('./AdaptiveLabelPositioningBehavior.basics.bpmn');
|
||||||
|
|
||||||
// given
|
beforeEach(bootstrapModeler(diagramXML, {
|
||||||
var source = elementRegistry.get('LabelBottom'),
|
modules: testModules
|
||||||
target = elementRegistry.get('LabelLeft');
|
|
||||||
|
|
||||||
// when
|
|
||||||
modeling.connect(source, target);
|
|
||||||
|
|
||||||
// then
|
|
||||||
expectLabelOrientation(source, 'bottom');
|
|
||||||
expectLabelOrientation(target, 'top');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should move label from BOTTOM to TOP', inject(function(elementRegistry, modeling) {
|
describe('on connect', function() {
|
||||||
|
|
||||||
// given
|
it('should move label from LEFT to TOP', inject(function(elementRegistry, modeling) {
|
||||||
var source = elementRegistry.get('LabelBottom'),
|
|
||||||
target = elementRegistry.get('LabelRight');
|
|
||||||
|
|
||||||
// when
|
// given
|
||||||
modeling.connect(source, target);
|
var source = elementRegistry.get('LabelBottom'),
|
||||||
|
target = elementRegistry.get('LabelLeft');
|
||||||
|
|
||||||
// then
|
// when
|
||||||
expectLabelOrientation(source, 'top');
|
modeling.connect(source, target);
|
||||||
expectLabelOrientation(target, 'right');
|
|
||||||
}));
|
// then
|
||||||
|
expectLabelOrientation(source, 'bottom');
|
||||||
|
expectLabelOrientation(target, 'top');
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
it('should move label from BOTTOM to TOP', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelRight'),
|
var source = elementRegistry.get('LabelBottom'),
|
||||||
target = elementRegistry.get('LabelTop');
|
target = elementRegistry.get('LabelRight');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'top');
|
expectLabelOrientation(source, 'top');
|
||||||
expectLabelOrientation(target, 'top');
|
expectLabelOrientation(target, 'right');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelTop'),
|
var source = elementRegistry.get('LabelRight'),
|
||||||
target = elementRegistry.get('LabelLeft');
|
target = elementRegistry.get('LabelTop');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'left');
|
expectLabelOrientation(source, 'top');
|
||||||
expectLabelOrientation(target, 'left');
|
expectLabelOrientation(target, 'top');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelTop'),
|
var source = elementRegistry.get('LabelTop'),
|
||||||
target = elementRegistry.get('LabelLeft');
|
target = elementRegistry.get('LabelLeft');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'left');
|
expectLabelOrientation(source, 'left');
|
||||||
expectLabelOrientation(target, 'left');
|
expectLabelOrientation(target, 'left');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should move label from TOP to LEFT (inverse)', inject(function(elementRegistry, modeling) {
|
it('should move label from TOP to LEFT', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelLeft'),
|
var source = elementRegistry.get('LabelTop'),
|
||||||
target = elementRegistry.get('LabelTop');
|
target = elementRegistry.get('LabelLeft');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(target, 'left');
|
expectLabelOrientation(source, 'left');
|
||||||
expectLabelOrientation(source, 'left');
|
expectLabelOrientation(target, 'left');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should keep unaligned labels AS IS', inject(function(elementRegistry, modeling) {
|
it('should move label from TOP to LEFT (inverse)', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelBottomLeft'),
|
var source = elementRegistry.get('LabelLeft'),
|
||||||
target = elementRegistry.get('LabelTop');
|
target = elementRegistry.get('LabelTop');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'bottom');
|
expectLabelOrientation(target, 'left');
|
||||||
expectLabelOrientation(target, 'top');
|
expectLabelOrientation(source, 'left');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should keep label where it is, if no options', inject(function(elementRegistry, modeling) {
|
it('should keep unaligned labels AS IS', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelImpossible'),
|
var source = elementRegistry.get('LabelBottomLeft'),
|
||||||
target = elementRegistry.get('Task');
|
target = elementRegistry.get('LabelTop');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.connect(source, target);
|
modeling.connect(source, target);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'right');
|
expectLabelOrientation(source, 'bottom');
|
||||||
}));
|
expectLabelOrientation(target, 'top');
|
||||||
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('on reconnect', function() {
|
it('should keep label where it is, if no options', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
// given
|
||||||
|
var source = elementRegistry.get('LabelImpossible'),
|
||||||
|
target = elementRegistry.get('Task');
|
||||||
|
|
||||||
// given
|
// when
|
||||||
var connection = elementRegistry.get('SequenceFlow_1'),
|
modeling.connect(source, target);
|
||||||
source = elementRegistry.get('LabelTop'),
|
|
||||||
target = elementRegistry.get('LabelLeft');
|
|
||||||
|
|
||||||
// when
|
// then
|
||||||
modeling.reconnectEnd(connection, target, { x: target.x + target.width / 2, y: target.y });
|
expectLabelOrientation(source, 'right');
|
||||||
|
}));
|
||||||
|
|
||||||
// then
|
});
|
||||||
expectLabelOrientation(source, 'bottom');
|
|
||||||
expectLabelOrientation(target, 'left');
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('on target move / layout', function() {
|
describe('on reconnect', function() {
|
||||||
|
|
||||||
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelTop'),
|
var connection = elementRegistry.get('SequenceFlow_1'),
|
||||||
target = elementRegistry.get('LabelBottom_3');
|
source = elementRegistry.get('LabelTop'),
|
||||||
|
target = elementRegistry.get('LabelLeft');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.moveElements([ source ], { x: 0, y: 300 });
|
modeling.reconnectEnd(connection, target, { x: target.x + target.width / 2, y: target.y });
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'bottom');
|
expectLabelOrientation(source, 'bottom');
|
||||||
expectLabelOrientation(target, 'top');
|
expectLabelOrientation(target, 'left');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('on source move / layout', function() {
|
describe('on target move / layout', function() {
|
||||||
|
|
||||||
it('should move label from BOTTOM to TOP', inject(
|
it('should move label from TOP to BOTTOM', inject(function(elementRegistry, modeling) {
|
||||||
function(elementRegistry, modeling) {
|
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var source = elementRegistry.get('LabelTop'),
|
var source = elementRegistry.get('LabelTop'),
|
||||||
target = elementRegistry.get('LabelBottom_3');
|
target = elementRegistry.get('LabelBottom_3');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.moveElements([ target ], { x: 20, y: -300 });
|
modeling.moveElements([ source ], { x: 0, y: 300 });
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'bottom');
|
expectLabelOrientation(source, 'bottom');
|
||||||
expectLabelOrientation(target, 'top');
|
expectLabelOrientation(target, 'top');
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('on waypoints update', function() {
|
describe('on source move / layout', function() {
|
||||||
|
|
||||||
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
it('should move label from BOTTOM to TOP', inject(
|
||||||
|
function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var connection = elementRegistry.get('SequenceFlow_2'),
|
var source = elementRegistry.get('LabelTop'),
|
||||||
source = elementRegistry.get('LabelRight'),
|
target = elementRegistry.get('LabelBottom_3');
|
||||||
target = elementRegistry.get('LabelBottom');
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.updateWaypoints(connection, [
|
modeling.moveElements([ target ], { x: 20, y: -300 });
|
||||||
{
|
|
||||||
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
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(source, 'top');
|
expectLabelOrientation(source, 'bottom');
|
||||||
expectLabelOrientation(target, 'bottom');
|
expectLabelOrientation(target, 'top');
|
||||||
}));
|
}
|
||||||
|
));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('on label creation', function() {
|
describe('on waypoints update', function() {
|
||||||
|
|
||||||
it('should create label at TOP', inject(
|
it('should move label from RIGHT to TOP', inject(function(elementRegistry, modeling) {
|
||||||
function(elementRegistry, modeling) {
|
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var element = elementRegistry.get('NoLabel');
|
var connection = elementRegistry.get('SequenceFlow_2'),
|
||||||
|
source = elementRegistry.get('LabelRight'),
|
||||||
|
target = elementRegistry.get('LabelBottom');
|
||||||
|
|
||||||
// when
|
// when
|
||||||
modeling.updateProperties(element, { name: 'FOO BAR' });
|
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
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expectLabelOrientation(element, 'top');
|
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');
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue