chore(modeling): move BpmnLabelSupport to behavior
* Make sure the label support is part of our behavior definitions. * Adjust test cases accordingly.
This commit is contained in:
parent
0393d51893
commit
1bceaaa229
|
@ -3,8 +3,8 @@
|
||||||
var assign = require('lodash/object/assign'),
|
var assign = require('lodash/object/assign'),
|
||||||
inherits = require('inherits');
|
inherits = require('inherits');
|
||||||
|
|
||||||
var LabelUtil = require('../../util/LabelUtil'),
|
var LabelUtil = require('../../../util/LabelUtil'),
|
||||||
is = require('../../util/ModelUtil').is;
|
is = require('../../../util/ModelUtil').is;
|
||||||
|
|
||||||
var hasExternalLabel = LabelUtil.hasExternalLabel,
|
var hasExternalLabel = LabelUtil.hasExternalLabel,
|
||||||
getExternalLabelMid = LabelUtil.getExternalLabelMid;
|
getExternalLabelMid = LabelUtil.getExternalLabelMid;
|
||||||
|
@ -12,6 +12,15 @@ var hasExternalLabel = LabelUtil.hasExternalLabel,
|
||||||
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A component that makes sure that external labels are added
|
||||||
|
* together with respective elements and properly updated (DI wise)
|
||||||
|
* during move.
|
||||||
|
*
|
||||||
|
* @param {EventBus} eventBus
|
||||||
|
* @param {Modeling} modeling
|
||||||
|
* @param {BpmnFactory} bpmnFactory
|
||||||
|
*/
|
||||||
function LabelSupport(eventBus, modeling, bpmnFactory) {
|
function LabelSupport(eventBus, modeling, bpmnFactory) {
|
||||||
|
|
||||||
CommandInterceptor.call(this, eventBus);
|
CommandInterceptor.call(this, eventBus);
|
||||||
|
@ -37,8 +46,9 @@ function LabelSupport(eventBus, modeling, bpmnFactory) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// update di information on label movement and creation
|
// update di information on label creation
|
||||||
this.executed([ 'label.create', 'shape.moved' ], function(e) {
|
this.executed([ 'label.create' ], function(e) {
|
||||||
|
|
||||||
var element = e.context.shape,
|
var element = e.context.shape,
|
||||||
businessObject,
|
businessObject,
|
||||||
di;
|
di;
|
|
@ -7,6 +7,7 @@ module.exports = {
|
||||||
'createParticipantBehavior',
|
'createParticipantBehavior',
|
||||||
'dataInputAssociationBehavior',
|
'dataInputAssociationBehavior',
|
||||||
'deleteLaneBehavior',
|
'deleteLaneBehavior',
|
||||||
|
'labelBehavior',
|
||||||
'modelingFeedback',
|
'modelingFeedback',
|
||||||
'removeParticipantBehavior',
|
'removeParticipantBehavior',
|
||||||
'replaceConnectionBehavior',
|
'replaceConnectionBehavior',
|
||||||
|
@ -21,6 +22,7 @@ module.exports = {
|
||||||
createParticipantBehavior: [ 'type', require('./CreateParticipantBehavior') ],
|
createParticipantBehavior: [ 'type', require('./CreateParticipantBehavior') ],
|
||||||
dataInputAssociationBehavior: [ 'type', require('./DataInputAssociationBehavior') ],
|
dataInputAssociationBehavior: [ 'type', require('./DataInputAssociationBehavior') ],
|
||||||
deleteLaneBehavior: [ 'type', require('./DeleteLaneBehavior') ],
|
deleteLaneBehavior: [ 'type', require('./DeleteLaneBehavior') ],
|
||||||
|
labelBehavior: [ 'type', require('./LabelBehavior') ],
|
||||||
modelingFeedback: [ 'type', require('./ModelingFeedback') ],
|
modelingFeedback: [ 'type', require('./ModelingFeedback') ],
|
||||||
removeParticipantBehavior: [ 'type', require('./RemoveParticipantBehavior') ],
|
removeParticipantBehavior: [ 'type', require('./RemoveParticipantBehavior') ],
|
||||||
replaceConnectionBehavior: [ 'type', require('./ReplaceConnectionBehavior') ],
|
replaceConnectionBehavior: [ 'type', require('./ReplaceConnectionBehavior') ],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
__init__: [ 'modeling', 'bpmnUpdater', 'bpmnLabelSupport' ],
|
__init__: [ 'modeling', 'bpmnUpdater' ],
|
||||||
__depends__: [
|
__depends__: [
|
||||||
require('./behavior'),
|
require('./behavior'),
|
||||||
require('../label-editing'),
|
require('../label-editing'),
|
||||||
|
@ -18,7 +18,6 @@ module.exports = {
|
||||||
bpmnUpdater: [ 'type', require('./BpmnUpdater') ],
|
bpmnUpdater: [ 'type', require('./BpmnUpdater') ],
|
||||||
elementFactory: [ 'type', require('./ElementFactory') ],
|
elementFactory: [ 'type', require('./ElementFactory') ],
|
||||||
modeling: [ 'type', require('./Modeling') ],
|
modeling: [ 'type', require('./Modeling') ],
|
||||||
bpmnLabelSupport: [ 'type', require('./BpmnLabelSupport') ],
|
|
||||||
layouter: [ 'type', require('./BpmnLayouter') ],
|
layouter: [ 'type', require('./BpmnLayouter') ],
|
||||||
connectionDocking: [ 'type', require('diagram-js/lib/layout/CroppingConnectionDocking') ]
|
connectionDocking: [ 'type', require('diagram-js/lib/layout/CroppingConnectionDocking') ]
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,16 +4,11 @@
|
||||||
|
|
||||||
var find = require('lodash/collection/find');
|
var find = require('lodash/collection/find');
|
||||||
|
|
||||||
var assign = require('lodash/object/assign');
|
|
||||||
|
|
||||||
|
|
||||||
var modelingModule = require('../../../../lib/features/modeling'),
|
var modelingModule = require('../../../../lib/features/modeling'),
|
||||||
coreModule = require('../../../../lib/core');
|
coreModule = require('../../../../lib/core');
|
||||||
|
|
||||||
|
|
||||||
var LabelUtil = require('../../../../lib/util/LabelUtil');
|
|
||||||
|
|
||||||
|
|
||||||
describe('features/modeling - append shape', function() {
|
describe('features/modeling - append shape', function() {
|
||||||
|
|
||||||
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
||||||
|
@ -74,44 +69,6 @@ describe('features/modeling - append shape', function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
describe('should add external label', function() {
|
|
||||||
|
|
||||||
it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) {
|
|
||||||
|
|
||||||
// given
|
|
||||||
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
||||||
|
|
||||||
// when
|
|
||||||
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' });
|
|
||||||
|
|
||||||
var label = targetShape.label;
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(label).to.exist;
|
|
||||||
expect(elementRegistry.get(label.id)).to.exist;
|
|
||||||
|
|
||||||
expect(label).to.have.bounds(assign({ x: 441, y: 278 }, LabelUtil.DEFAULT_LABEL_SIZE));
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
it('with di', inject(function(elementRegistry, modeling, commandStack) {
|
|
||||||
|
|
||||||
// given
|
|
||||||
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
||||||
|
|
||||||
// when
|
|
||||||
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
|
|
||||||
target = targetShape.businessObject;
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(target.di.label).to.exist;
|
|
||||||
|
|
||||||
expect(target.di.label).to.have.bounds(targetShape.label);
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should add connection', inject(function(elementRegistry, modeling) {
|
it('should add connection', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var TestHelper = require('../../../TestHelper');
|
|
||||||
|
|
||||||
/* global bootstrapModeler, inject */
|
|
||||||
|
|
||||||
var modelingModule = require('../../../../lib/features/modeling'),
|
|
||||||
coreModule = require('../../../../lib/core');
|
|
||||||
|
|
||||||
describe('features - bpmn-label-support', function() {
|
|
||||||
|
|
||||||
var diagramXML = require('../../../fixtures/bpmn/basic.bpmn');
|
|
||||||
|
|
||||||
var testModules = [ modelingModule, coreModule ];
|
|
||||||
|
|
||||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
||||||
|
|
||||||
describe('should not add a label on create', function() {
|
|
||||||
|
|
||||||
it('should not add a label on create', inject(function(elementFactory, elementRegistry, modeling, canvas) {
|
|
||||||
// when
|
|
||||||
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
||||||
task = elementRegistry.get('Task_1');
|
|
||||||
|
|
||||||
modeling.connect(startEvent, task);
|
|
||||||
|
|
||||||
var labels = elementRegistry.filter(function(element) {
|
|
||||||
return element.type === 'label';
|
|
||||||
});
|
|
||||||
|
|
||||||
// then
|
|
||||||
expect(labels).to.have.length(2);
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -0,0 +1,144 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var TestHelper = require('../../../../TestHelper');
|
||||||
|
|
||||||
|
/* global bootstrapModeler, inject */
|
||||||
|
|
||||||
|
var assign = require('lodash/object/assign');
|
||||||
|
|
||||||
|
var modelingModule = require('../../../../../lib/features/modeling'),
|
||||||
|
coreModule = require('../../../../../lib/core');
|
||||||
|
|
||||||
|
var LabelUtil = require('../../../../../lib/util/LabelUtil');
|
||||||
|
|
||||||
|
|
||||||
|
describe('behavior - LabelBehavior', function() {
|
||||||
|
|
||||||
|
var diagramXML = require('../../../../fixtures/bpmn/basic.bpmn');
|
||||||
|
|
||||||
|
var testModules = [ modelingModule, coreModule ];
|
||||||
|
|
||||||
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||||
|
|
||||||
|
|
||||||
|
describe('add label', function() {
|
||||||
|
|
||||||
|
it('should add to sequence flow', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
||||||
|
task = elementRegistry.get('Task_1');
|
||||||
|
|
||||||
|
// when
|
||||||
|
var connection = modeling.connect(startEvent, task);
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(connection.label).to.exist;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should add to exclusive gateway', inject(function(elementFactory, elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var parentShape = elementRegistry.get('Process_1'),
|
||||||
|
newShapeAttrs = { type: 'bpmn:ExclusiveGateway' };
|
||||||
|
|
||||||
|
// when
|
||||||
|
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(newShape.label).to.exist;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should not add to task', inject(function(elementFactory, elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var parentShape = elementRegistry.get('Process_1'),
|
||||||
|
newShapeAttrs = { type: 'bpmn:Task' };
|
||||||
|
|
||||||
|
// when
|
||||||
|
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(newShape.label).not.to.exist;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
describe('on append', function() {
|
||||||
|
|
||||||
|
it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
||||||
|
|
||||||
|
// when
|
||||||
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' });
|
||||||
|
|
||||||
|
var label = targetShape.label;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(label).to.exist;
|
||||||
|
expect(elementRegistry.get(label.id)).to.exist;
|
||||||
|
|
||||||
|
expect(label).to.have.bounds(assign({ x: 262, y: 138 }, LabelUtil.DEFAULT_LABEL_SIZE));
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('with di', inject(function(elementRegistry, modeling, commandStack) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
||||||
|
|
||||||
|
// when
|
||||||
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
|
||||||
|
target = targetShape.businessObject;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(target.di.label).to.exist;
|
||||||
|
|
||||||
|
expect(target.di.label).to.have.bounds(targetShape.label);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should add with di', inject(function(elementFactory, elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
||||||
|
|
||||||
|
// when
|
||||||
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
|
||||||
|
target = targetShape.businessObject;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(target.di.label).to.exist;
|
||||||
|
|
||||||
|
expect(target.di.label).to.have.bounds(targetShape.label);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('move label', function() {
|
||||||
|
|
||||||
|
it('should move start event label', inject(function(elementRegistry, modeling) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
||||||
|
startEvent = startEventShape.businessObject,
|
||||||
|
labelShape = startEventShape.label;
|
||||||
|
|
||||||
|
// when
|
||||||
|
modeling.moveElements([ labelShape ], { x: 10, y: -10 });
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(labelShape).to.have.position({ x: 156, y: 128 });
|
||||||
|
expect(startEvent.di.label).to.have.position({ x: 156, y: 128 });
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue