diff --git a/src/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.js b/src/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.js index 7c89f70ea..37ea70fb4 100644 --- a/src/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.js +++ b/src/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.js @@ -352,8 +352,9 @@ export default class ChangeElementTemplateHandler { } } - // (3) add new inputs and outputs (unless optional) - else if (shouldUpdate(newPropertyValue, newProperty)) { + // (3) add new inputs and outputs (unless optional or undefined value) + else if (newPropertyValue && shouldUpdate(newPropertyValue, newProperty)) { + if (newBindingType === 'zeebe:input') { propertyName = 'inputParameters'; diff --git a/test/spec/provider/cloud-element-templates/ElementTemplateConditionChecker.spec.js b/test/spec/provider/cloud-element-templates/ElementTemplateConditionChecker.spec.js index 76d6ff61b..285961eff 100644 --- a/test/spec/provider/cloud-element-templates/ElementTemplateConditionChecker.spec.js +++ b/test/spec/provider/cloud-element-templates/ElementTemplateConditionChecker.spec.js @@ -382,7 +382,7 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker', }); // then - expectOutputTarget(businessObject, ''); + expectOutputTarget(businessObject, 'nameProp=foo'); // when modeling.updateProperties(element, { diff --git a/test/spec/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js b/test/spec/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js index c20ab5eed..2463762b9 100644 --- a/test/spec/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js +++ b/test/spec/provider/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js @@ -1982,7 +1982,7 @@ describe('cloud-element-templates - ChangeElementTemplateHandler', function() { beforeEach(bootstrap(require('./task.bpmn').default)); - it('should create - optional -> non optional', inject(function(elementRegistry) { + it('should create - optional -> non optional (value)', inject(function(elementRegistry) { // given const task = elementRegistry.get('Task_1'); @@ -2006,12 +2006,14 @@ describe('cloud-element-templates - ChangeElementTemplateHandler', function() { const newTemplate = createTemplate([ { + value: 'input-1-new-value', binding: { type: 'zeebe:input', name: 'input-1-target' } }, { + value: 'output-1-new-value', binding: { type: 'zeebe:output', source: 'output-1-source' @@ -2040,7 +2042,7 @@ describe('cloud-element-templates - ChangeElementTemplateHandler', function() { expect(ioMapping.get('zeebe:inputParameters')).to.jsonEqual([ { $type: 'zeebe:Input', - source: undefined, + source: 'input-1-new-value', target: 'input-1-target', } ]); @@ -2055,6 +2057,63 @@ describe('cloud-element-templates - ChangeElementTemplateHandler', function() { })); + it('should create - optional -> non optional (no value)', inject(function(elementRegistry) { + + // given + const task = elementRegistry.get('Task_1'); + + const oldTemplate = createTemplate([ + { + optional: true, + binding: { + type: 'zeebe:input', + name: 'input-1-target' + } + }, + { + optional: true, + binding: { + type: 'zeebe:output', + source: 'output-1-source' + } + } + ]); + + const newTemplate = createTemplate([ + { + binding: { + type: 'zeebe:input', + name: 'input-1-target' + } + }, + { + binding: { + type: 'zeebe:output', + source: 'output-1-source' + } + } + ]); + + changeTemplate('Task_1', oldTemplate); + + let ioMapping = findExtension(task, 'zeebe:IoMapping'); + + // assume + expect(ioMapping.get('zeebe:inputParameters')).to.be.empty; + expect(ioMapping.get('zeebe:outputParameters')).to.be.empty; + + // when + changeTemplate(task, newTemplate, oldTemplate); + + // then + ioMapping = findExtension(task, 'zeebe:IoMapping'); + + expect(ioMapping).to.exist; + expect(ioMapping.get('zeebe:inputParameters')).to.have.length(0); + expect(ioMapping.get('zeebe:outputParameters')).to.have.length(0); + })); + + it('should remove - non optional -> optional (empty value)', inject(function(elementRegistry) { // given diff --git a/test/spec/provider/cloud-element-templates/fixtures/condition.json b/test/spec/provider/cloud-element-templates/fixtures/condition.json index 780449954..92a71646f 100644 --- a/test/spec/provider/cloud-element-templates/fixtures/condition.json +++ b/test/spec/provider/cloud-element-templates/fixtures/condition.json @@ -81,7 +81,7 @@ }, { "label": "zeebe:input", - "value": "", + "value": "nameProp=foo", "type": "String", "binding": { "type": "zeebe:input", @@ -94,7 +94,7 @@ }, { "label": "zeebe:output", - "value": "", + "value": "nameProp=foo", "type": "String", "binding": { "type": "zeebe:output",