feat(label-behavior): correctly retrieve label from element

Relates to camunda/camunda-modeler#1417
This commit is contained in:
Niklas Kiefer 2019-07-01 12:48:49 +02:00 committed by merge-me[bot]
parent af348a511e
commit b7d6d62184
2 changed files with 32 additions and 3 deletions

View File

@ -15,6 +15,10 @@ import {
hasExternalLabel hasExternalLabel
} from '../../../util/LabelUtil'; } from '../../../util/LabelUtil';
import {
getLabel
} from '../../label-editing/LabelUtil';
import { import {
getLabelAdjustment getLabelAdjustment
} from './util/LabelLayoutUtil'; } from './util/LabelLayoutUtil';
@ -105,8 +109,8 @@ export default function LabelBehavior(
return; return;
} }
// only create label if name // only create label if attribute available
if (!businessObject.name) { if (!getLabel(element)) {
return; return;
} }
@ -115,7 +119,7 @@ export default function LabelBehavior(
// we don't care about x and y // we don't care about x and y
var labelDimensions = textRenderer.getExternalLabelBounds( var labelDimensions = textRenderer.getExternalLabelBounds(
DEFAULT_LABEL_DIMENSIONS, DEFAULT_LABEL_DIMENSIONS,
businessObject.name || '' getLabel(element)
); );
modeling.createLabel(element, labelCenter, { modeling.createLabel(element, labelCenter, {

View File

@ -151,6 +151,31 @@ describe('behavior - LabelBehavior', function() {
)); ));
it('should add to group', inject(
function(bpmnFactory, elementRegistry, modeling) {
// given
var parentShape = elementRegistry.get('Process_1'),
categoryValue = bpmnFactory.create('bpmn:CategoryValue', {
value: 'foo'
}),
businessObject = bpmnFactory.create('bpmn:Group', {
categoryValueRef: categoryValue
}),
newShapeAttrs = {
type: 'bpmn:Group',
businessObject: businessObject
};
// when
var newShape = modeling.createShape(newShapeAttrs, { x: 50, y: 50 }, parentShape);
// then
expect(newShape.label).to.exist;
}
));
it('should not add to task', inject( it('should not add to task', inject(
function(elementFactory, elementRegistry, modeling) { function(elementFactory, elementRegistry, modeling) {