fix(label-behavior): properly check for name property change

Related to camunda/camunda-modeler#824
This commit is contained in:
Philipp Fromme 2018-06-06 13:35:57 +02:00
parent a3a597f34b
commit 4a0f6da814
3 changed files with 54 additions and 3 deletions

View File

@ -48,8 +48,8 @@ export default function LabelBehavior(
element = context.element, element = context.element,
properties = context.properties; properties = context.properties;
if (name in properties) { if ('name' in properties) {
modeling.updateLabel(element, name); modeling.updateLabel(element, properties.name);
} }
}); });

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.14.0"> <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.15.1">
<bpmn:process id="Process_1" isExecutable="false"> <bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1" name="foo" /> <bpmn:startEvent id="StartEvent_1" name="foo" />
<bpmn:task id="Task_1" /> <bpmn:task id="Task_1" />
<bpmn:exclusiveGateway id="ExclusiveGateway_1" />
</bpmn:process> </bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
@ -15,6 +16,9 @@
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1"> <bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="353" y="80" width="100" height="80" /> <dc:Bounds x="353" y="80" width="100" height="80" />
</bpmndi:BPMNShape> </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ExclusiveGateway_1gzwevj_di" bpmnElement="ExclusiveGateway_1" isMarkerVisible="true">
<dc:Bounds x="256" y="95" width="50" height="50" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane> </bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram> </bpmndi:BPMNDiagram>
</bpmn:definitions> </bpmn:definitions>

View File

@ -1,3 +1,5 @@
/* global sinon */
import { import {
bootstrapModeler, bootstrapModeler,
inject inject
@ -17,6 +19,51 @@ describe('behavior - LabelBehavior', function() {
beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('updating name property', function() {
it('should update label', inject(function(elementRegistry, eventBus, modeling) {
// given
var startEvent = elementRegistry.get('StartEvent_1'),
spy = sinon.spy();
eventBus.once('commandStack.element.updateLabel.execute', spy);
// when
modeling.updateProperties(startEvent, {
name: 'bar'
});
// then
expect(startEvent.businessObject.name).to.equal('bar');
expect(spy).to.have.been.called;
}));
it('should create label', inject(function(elementRegistry, eventBus, modeling) {
// given
var startEvent = elementRegistry.get('ExclusiveGateway_1'),
spy = sinon.spy();
eventBus.once('commandStack.element.updateLabel.execute', spy);
// when
modeling.updateProperties(startEvent, {
name: 'foo'
});
// then
var labelShape = startEvent.label;
expect(labelShape).to.exist;
expect(startEvent.businessObject.name).to.equal('foo');
expect(spy).to.have.been.called;
}));
});
describe('add label', function() { describe('add label', function() {
it('should add to sequence flow with name', inject( it('should add to sequence flow with name', inject(