From fee0a2ecd03ac22e10b7759c7902b6dbace5323a Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 9 Oct 2023 15:26:58 +0200 Subject: [PATCH] fix: set `$parent` when creating properties --- .../cmd/ChangeElementTemplateHandler.js | 4 ++++ .../cmd/ChangeElementTemplateHandler.spec.js | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js b/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js index b75f8159..851a0d63 100644 --- a/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js +++ b/src/cloud-element-templates/cmd/ChangeElementTemplateHandler.js @@ -567,6 +567,8 @@ export default class ChangeElementTemplateHandler { if (!zeebeProperties) { zeebeProperties = bpmnFactory.create('zeebe:Properties'); + zeebeProperties.$parent = businessObject; + commandStack.execute('element.updateModdleProperties', { element, moddleElement: businessObject, @@ -608,6 +610,8 @@ export default class ChangeElementTemplateHandler { else if (shouldUpdate(newPropertyValue, newProperty)) { const newProperty = createZeebeProperty(newBinding, newPropertyValue, bpmnFactory); + newProperty.$parent = zeebeProperties; + commandStack.execute('element.updateModdleProperties', { element, moddleElement: zeebeProperties, diff --git a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js index 8c3a5b73..30c50823 100644 --- a/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js +++ b/test/spec/cloud-element-templates/cmd/ChangeElementTemplateHandler.spec.js @@ -1215,6 +1215,13 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( expect(zeebeProperties).to.exist; expect(zeebeProperties.get('properties')).to.have.length(2); + expect(zeebeProperties.$parent) + .to.equal(getBusinessObject(serviceTask).get('extensionElements')); + + zeebeProperties.get('properties').forEach((property) => { + expect(property.$parent).to.equal(zeebeProperties); + }); + expect(zeebeProperties.get('properties')).to.jsonEqual([ { $type: 'zeebe:Property', @@ -1268,6 +1275,13 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( expect(zeebeProperties).to.exist; expect(zeebeProperties.get('properties')).to.have.length(2); + expect(zeebeProperties.$parent) + .to.equal(getBusinessObject(serviceTask).get('extensionElements')); + + zeebeProperties.get('properties').forEach((property) => { + expect(property.$parent).to.equal(zeebeProperties); + }); + expect(zeebeProperties.get('properties')).to.jsonEqual([ { $type: 'zeebe:Property', @@ -1299,6 +1313,13 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( expect(zeebeProperties).to.exist; expect(zeebeProperties.get('properties')).to.have.length(2); + expect(zeebeProperties.$parent) + .to.equal(getBusinessObject(serviceTask).get('extensionElements')); + + zeebeProperties.get('properties').forEach((property) => { + expect(property.$parent).to.equal(zeebeProperties); + }); + expect(zeebeProperties.get('properties')).to.jsonEqual([ { $type: 'zeebe:Property', @@ -1442,7 +1463,6 @@ describe('cloud-element-templates/cmd - ChangeElementTemplateHandler', function( }); - describe('zeebe:Property not specified', function() { const newTemplate = require('./task-template-no-properties.json');