diff --git a/src/provider/zeebe/properties/PriorityDefinitionProps.js b/src/provider/zeebe/properties/PriorityDefinitionProps.js index adc617d96..f6f2f4db6 100644 --- a/src/provider/zeebe/properties/PriorityDefinitionProps.js +++ b/src/provider/zeebe/properties/PriorityDefinitionProps.js @@ -25,7 +25,7 @@ export function PriorityDefinitionProps(props) { element } = props; - if (!is(element, 'bpmn:UserTask')) { + if (!isZeebeUserTask(element)) { return []; } @@ -59,32 +59,13 @@ function Priority(props) { let extensionElements = businessObject.get('extensionElements'); - // (1) ensure extension elements - if (!extensionElements) { - extensionElements = createElement( - 'bpmn:ExtensionElements', - { values: [] }, - businessObject, - bpmnFactory - ); - - commands.push({ - cmd: 'element.updateModdleProperties', - context: { - element, - moddleElement: businessObject, - properties: { extensionElements } - } - }); - } - - // (2) ensure PriorityDefinition + // (1) ensure PriorityDefinition let priorityDefinition = getPriorityDefinition(element); const isNullValue = value === null || value === '' || value === undefined; if (priorityDefinition && isNullValue) { - // (3a) remove priority definition if it exists and priority is set to null + // (2a) remove priority definition if it exists and priority is set to null commands.push({ cmd: 'element.updateModdleProperties', context: { @@ -98,7 +79,7 @@ function Priority(props) { } else if (priorityDefinition && !isNullValue) { - // (3b) update priority definition if it already exists + // (2b) update priority definition if it already exists commands.push({ cmd: 'element.updateModdleProperties', context: { @@ -110,7 +91,7 @@ function Priority(props) { } else if (!priorityDefinition && !isNullValue) { - // (3c) create priority definition if it does not exist + // (2c) create priority definition if it does not exist priorityDefinition = createElement( 'zeebe:PriorityDefinition', { priority: value }, @@ -130,7 +111,7 @@ function Priority(props) { }); } - // (4) commit all updates + // (3) commit all updates commandStack.execute('properties-panel.multi-command-executor', commands); }; @@ -153,3 +134,9 @@ export function getPriorityDefinition(element) { return getExtensionElementsList(businessObject, 'zeebe:PriorityDefinition')[0]; } + +function isZeebeUserTask(element) { + const businessObject = getBusinessObject(element); + + return is(element, 'bpmn:UserTask') && !!getExtensionElementsList(businessObject, 'zeebe:UserTask')[0]; +} \ No newline at end of file diff --git a/test/spec/provider/zeebe/PriorityDefinitionProps.bpmn b/test/spec/provider/zeebe/PriorityDefinitionProps.bpmn index dd08f4b8e..0aa59ea45 100644 --- a/test/spec/provider/zeebe/PriorityDefinitionProps.bpmn +++ b/test/spec/provider/zeebe/PriorityDefinitionProps.bpmn @@ -2,20 +2,28 @@ + - + + + + + + + - + - + + diff --git a/test/spec/provider/zeebe/PriorityDefinitionProps.spec.js b/test/spec/provider/zeebe/PriorityDefinitionProps.spec.js index 83fa0bfde..ab90002d2 100644 --- a/test/spec/provider/zeebe/PriorityDefinitionProps.spec.js +++ b/test/spec/provider/zeebe/PriorityDefinitionProps.spec.js @@ -34,6 +34,7 @@ import zeebeModdleExtensions from 'zeebe-bpmn-moddle/resources/zeebe'; import diagramXML from './PriorityDefinitionProps.bpmn'; import { setEditorValue } from '../../../TestHelper'; +import { getExtensionElementsList } from '../../../../src/utils/ExtensionElementsUtil'; describe('provider/zeebe - PriorityDefinitionProps', function() { @@ -83,6 +84,23 @@ describe('provider/zeebe - PriorityDefinitionProps', function() { })); + it('should NOT display for user task without zeebe:UserTask', inject(async function(elementRegistry, selection) { + + // given + const userTask = elementRegistry.get('UserTask_0'); + + await act(() => { + selection.select(userTask); + }); + + // when + const priorityInput = domQuery('input[name=priorityDefinitionPriority]', container); + + // then + expect(priorityInput).to.not.exist; + })); + + it('should display for user task', inject(async function(elementRegistry, selection) { // given @@ -153,14 +171,14 @@ describe('provider/zeebe - PriorityDefinitionProps', function() { ); - it('should create non-existing extension elements and priority definition', + it('should create priority definition', inject(async function(elementRegistry, selection) { // given const userTask = elementRegistry.get('UserTask_2'); // assume - expect(getBusinessObject(userTask).get('extensionElements')).to.not.exist; + expect(getExtensionElementsList(getBusinessObject(userTask), 'zeebe:priorityDefinition')).to.be.empty; await act(() => { selection.select(userTask); @@ -171,7 +189,8 @@ describe('provider/zeebe - PriorityDefinitionProps', function() { changeInput(priorityInput, 'newValue'); // then - expect(getBusinessObject(userTask).get('extensionElements')).to.exist; + const priorityDefinitionElement = getExtensionElementsList(getBusinessObject(userTask), 'zeebe:PriorityDefinition')[0]; + expect(priorityDefinitionElement).to.exist; }) ); @@ -197,7 +216,7 @@ describe('provider/zeebe - PriorityDefinitionProps', function() { // then const extensionElements = getBusinessObject(userTask).get('extensionElements'); expect(getPriorityDefinition(userTask).get('priority')).to.eql('newValue'); - expect(extensionElements.values).to.have.length(2); + expect(extensionElements.values).to.have.length(3); }) );