diff --git a/lib/util/LabelUtil.js b/lib/util/LabelUtil.js index 0b2a033486..c4b9dd6c66 100644 --- a/lib/util/LabelUtil.js +++ b/lib/util/LabelUtil.js @@ -251,7 +251,11 @@ export function setLabel(element, text) { if (attr) { if (attr === 'categoryValueRef') { - semantic['categoryValueRef'].value = text; + if (!semantic[attr]) { + return element; + } + + semantic[attr].value = text; } else { semantic[attr] = text; } diff --git a/test/spec/features/modeling/UpdateLabel.bpmn b/test/spec/features/modeling/UpdateLabel.bpmn index 24ebdd282d..f2baae17a3 100644 --- a/test/spec/features/modeling/UpdateLabel.bpmn +++ b/test/spec/features/modeling/UpdateLabel.bpmn @@ -1,5 +1,5 @@ - + @@ -10,9 +10,10 @@ + - + @@ -32,15 +33,18 @@ - - - + + + + + + diff --git a/test/spec/features/modeling/UpdateLabelSpec.js b/test/spec/features/modeling/UpdateLabelSpec.js index d31660beaa..2d622520d5 100644 --- a/test/spec/features/modeling/UpdateLabelSpec.js +++ b/test/spec/features/modeling/UpdateLabelSpec.js @@ -165,17 +165,45 @@ describe('features/modeling - update label', function() { )); - it('should change value of group', inject(function(modeling, elementRegistry) { + it('should update group label', inject(function(modeling, elementRegistry) { // given - var group_1 = elementRegistry.get('Group_1'); + var group = elementRegistry.get('Group_1'); // when - modeling.updateLabel(group_1, 'foo'); + modeling.updateLabel(group, 'bar'); // then - expect(group_1.businessObject.categoryValueRef.value).to.equal('foo'); - expect(group_1.label).to.exist; + expect(group.businessObject.categoryValueRef.value).to.equal('bar'); + expect(group.label).to.exist; + })); + + + it('should create group label', inject(function(modeling, elementRegistry) { + + // given + var group = elementRegistry.get('Group_2'); + + // when + modeling.updateLabel(group, 'foo'); + + // then + expect(group.businessObject.categoryValueRef.value).to.equal('foo'); + expect(group.label).to.exist; + })); + + + it('should not create group label on empty text', inject(function(modeling, elementRegistry) { + + // given + var group = elementRegistry.get('Group_2'); + + // when + modeling.updateLabel(group, null); + + // then + expect(group.businessObject.categoryValueRef).to.not.exist; + expect(group.label).to.not.exist; }));