2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('behavior - LabelBehavior', function() {
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
var diagramXML =
|
|
|
|
require('../../../../fixtures/bpmn/features/modeling/behavior/label-behavior.bpmn');
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
var testModules = [ modelingModule, coreModule ];
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
|
|
|
|
|
|
|
describe('add label', function() {
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should add to sequence flow with name', inject(
|
|
|
|
function(bpmnFactory, elementRegistry, modeling) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
|
|
task = elementRegistry.get('Task_1'),
|
|
|
|
businessObject = bpmnFactory.create('bpmn:SequenceFlow', {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
var connection = modeling.createConnection(startEvent, task, {
|
|
|
|
type: 'bpmn:SequenceFlow',
|
|
|
|
businessObject: businessObject
|
|
|
|
}, startEvent.parent);
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(connection.label).to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should NOT add to sequence flow without name', inject(
|
|
|
|
function(elementRegistry, modeling) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
|
|
task = elementRegistry.get('Task_1');
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
var connection = modeling.connect(startEvent, task);
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(connection.label).not.to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should add to exclusive gateway with name', inject(
|
|
|
|
function(bpmnFactory, elementFactory, elementRegistry, modeling) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var parentShape = elementRegistry.get('Process_1'),
|
|
|
|
businessObject = bpmnFactory.create('bpmn:ExclusiveGateway', {
|
|
|
|
name: 'foo'
|
|
|
|
}),
|
|
|
|
newShapeAttrs = {
|
|
|
|
type: 'bpmn:ExclusiveGateway',
|
|
|
|
businessObject: businessObject
|
|
|
|
};
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(newShape.label).to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should NOT add to exclusive gateway without name', inject(
|
|
|
|
function(elementFactory, elementRegistry, modeling) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// given
|
2018-04-30 09:06:26 +00:00
|
|
|
var parentShape = elementRegistry.get('Process_1'),
|
|
|
|
newShapeAttrs = {
|
|
|
|
type: 'bpmn:ExclusiveGateway'
|
|
|
|
};
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// when
|
2018-04-30 09:06:26 +00:00
|
|
|
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// then
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(newShape.label).not.to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should not add to task', inject(
|
|
|
|
function(elementFactory, elementRegistry, modeling) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// given
|
2018-04-30 09:06:26 +00:00
|
|
|
var parentShape = elementRegistry.get('Process_1'),
|
|
|
|
newShapeAttrs = { type: 'bpmn:Task' };
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// when
|
2018-04-30 09:06:26 +00:00
|
|
|
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
// then
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(newShape.label).not.to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
describe('on append', function() {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('correctly wired and positioned', inject(
|
|
|
|
function(bpmnFactory, elementRegistry, modeling, commandStack) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
businessObject = bpmnFactory.create('bpmn:EndEvent', {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendShape(startEventShape, {
|
|
|
|
type: 'bpmn:EndEvent',
|
|
|
|
businessObject: businessObject
|
|
|
|
});
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
var label = targetShape.label;
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(label).to.exist;
|
|
|
|
expect(elementRegistry.get(label.id)).to.exist;
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(label.x).to.within(298, 299);
|
|
|
|
expect(label.y).to.be.within(141, 142);
|
|
|
|
expect(label.width).to.be.within(15, 18);
|
|
|
|
expect(label.height).to.be.within(12, 14);
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('with di', inject(
|
|
|
|
function(bpmnFactory, elementRegistry, modeling, commandStack) {
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
businessObject = bpmnFactory.create('bpmn:EndEvent', {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendShape(startEventShape, {
|
|
|
|
type: 'bpmn:EndEvent',
|
|
|
|
businessObject: businessObject
|
|
|
|
}),
|
|
|
|
target = targetShape.businessObject;
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(target.di.label).to.exist;
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(target.di.label).to.have.bounds(targetShape.label);
|
|
|
|
}
|
|
|
|
));
|
2016-03-08 13:12:52 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
});
|
2016-04-19 15:12:48 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should add with di', inject(
|
|
|
|
function(bpmnFactory, elementFactory, elementRegistry, modeling) {
|
2016-04-19 15:12:48 +00:00
|
|
|
|
2016-07-05 13:54:14 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
2018-04-30 09:06:26 +00:00
|
|
|
businessObject = bpmnFactory.create('bpmn:SequenceFlow', {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
2016-04-19 15:12:48 +00:00
|
|
|
|
2016-07-05 13:54:14 +00:00
|
|
|
// when
|
2018-04-30 09:06:26 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, {
|
|
|
|
type: 'bpmn:EndEvent',
|
|
|
|
businessObject: businessObject
|
|
|
|
}),
|
|
|
|
target = targetShape.businessObject;
|
2016-04-19 15:12:48 +00:00
|
|
|
|
2016-07-05 13:54:14 +00:00
|
|
|
// then
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(target.di.label).to.exist;
|
2016-04-19 15:12:48 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(target.di.label).to.have.bounds(targetShape.label);
|
|
|
|
}
|
|
|
|
));
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
});
|
2016-07-05 13:54:14 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
describe('move label', function() {
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should move start event label', inject(function(elementRegistry, modeling) {
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
startEvent = startEventShape.businessObject,
|
|
|
|
labelShape = startEventShape.label;
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
modeling.moveElements([ labelShape ], { x: 10, y: -10 });
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(labelShape.x).to.be.within(193, 194);
|
|
|
|
expect(labelShape.y).to.equal(128);
|
|
|
|
expect(startEvent.di.label.bounds.x).to.be.within(193, 194);
|
|
|
|
expect(startEvent.di.label.bounds.y).to.equal(128);
|
|
|
|
}));
|
2016-07-05 13:54:14 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
describe('connection labels', function() {
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should NOT center position visible', inject(
|
|
|
|
function(bpmnFactory, elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
taskShape = elementRegistry.get('Task_1'),
|
|
|
|
businessObject = bpmnFactory.create('bpmn:SequenceFlow', {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
|
|
|
|
|
|
|
var sequenceFlowConnection = modeling.createConnection(startEventShape, taskShape, {
|
|
|
|
type: 'bpmn:SequenceFlow',
|
|
|
|
businessObject: businessObject
|
|
|
|
}, startEventShape.parent);
|
|
|
|
|
|
|
|
var oldLabelPosition = {
|
|
|
|
x: sequenceFlowConnection.label.x,
|
|
|
|
y: sequenceFlowConnection.label.y
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
sequenceFlowConnection.label.hidden = false;
|
|
|
|
|
|
|
|
modeling.updateWaypoints(sequenceFlowConnection, [
|
|
|
|
sequenceFlowConnection.waypoints[0],
|
|
|
|
{
|
|
|
|
x: sequenceFlowConnection.waypoints[0].x,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: sequenceFlowConnection.waypoints[1].x,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
sequenceFlowConnection.waypoints[1]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect({
|
|
|
|
x: sequenceFlowConnection.label.x,
|
|
|
|
y: sequenceFlowConnection.label.y
|
|
|
|
}).to.eql(oldLabelPosition);
|
|
|
|
}
|
|
|
|
));
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
});
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
});
|
2016-07-05 13:54:14 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
describe('delete label', function() {
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it('should remove name', inject(function(elementRegistry, modeling) {
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
startEvent = startEventShape.businessObject,
|
|
|
|
labelShape = startEventShape.label;
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// when
|
|
|
|
modeling.removeShape(labelShape);
|
2016-07-05 13:54:14 +00:00
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
// then
|
|
|
|
expect(startEventShape.label).not.to.exist;
|
|
|
|
expect(startEvent.name).to.equal('');
|
|
|
|
}));
|
2016-04-19 15:12:48 +00:00
|
|
|
|
2016-03-08 13:12:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|