From 6151ed9d88d13d5bf4661f05d73d6584d17132b9 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Thu, 12 Dec 2024 18:09:56 +0100 Subject: [PATCH] feat: relax `zeebe:TaskListeners` cleanup based on event types Related to https://github.com/camunda/camunda-modeler/issues/4748 --- CHANGELOG.md | 4 + .../CleanUpTaskListenersBehavior.js | 2 - .../CleanUpTaskListenersBehaviorSpec.js | 77 ++++--------------- test/camunda-cloud/task-listeners.bpmn | 2 +- 4 files changed, 22 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eb59da..8c49c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to [camunda-bpmn-js-behaviors](https://github.com/camunda/ca ___Note:__ Yet to be released changes appear here._ +## 1.9.0 + +* `FEAT`: relax `zeebe:TaskListeners` cleanup based on event types ([#92](https://github.com/camunda/camunda-bpmn-js-behaviors/pull/92)) + ## 1.8.0 * `FEAT`: make `Zeebe user task` the default implementation of user task ([#86](https://github.com/camunda/camunda-bpmn-js-behaviors/pull/86)) diff --git a/lib/camunda-cloud/CleanUpTaskListenersBehavior.js b/lib/camunda-cloud/CleanUpTaskListenersBehavior.js index dbfc98f..7f13b4e 100644 --- a/lib/camunda-cloud/CleanUpTaskListenersBehavior.js +++ b/lib/camunda-cloud/CleanUpTaskListenersBehavior.js @@ -4,7 +4,6 @@ import { without } from 'min-dash'; import { getExtensionElementsList } from '../util/ExtensionElementsUtil'; -const ALLOWED_EVENT_TYPES = [ 'complete', 'assignment' ]; export default class CleanUpTaskListenersBehavior extends CommandInterceptor { constructor(eventBus, modeling) { @@ -74,7 +73,6 @@ function withoutDisallowedListeners(element, listeners) { return listeners.filter(listener => { if ( !is(element, 'bpmn:UserTask') || - !ALLOWED_EVENT_TYPES.includes(listener.eventType) || !hasZeebeTaskExtensionElement(element) ) { return false; diff --git a/test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js b/test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js index 55d6aa0..f5beb98 100644 --- a/test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js +++ b/test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js @@ -94,66 +94,7 @@ describe('camunda-cloud/features/modeling - CleanUpTaskListenersBehavior', funct } }); - describe('should remove task listeners of disallowed type', function() { - - it('should execute', inject(function(bpmnReplace, elementRegistry) { - - // given - let el = elementRegistry.get('UserTaskWrongType'); - - // when - bpmnReplace.replaceElement(el, { - type: 'bpmn:UserTask' - }); - - // then - el = elementRegistry.get('UserTaskWrongType'); - const taskListenersContainer = getTaskListenersContainer(el); - - expect(taskListenersContainer.get('listeners')).to.have.lengthOf(1); - })); - - - it('should undo', inject(function(bpmnReplace, commandStack, elementRegistry) { - - // given - let el = elementRegistry.get('UserTaskWrongType'); - - // when - bpmnReplace.replaceElement(el, { - type: 'bpmn:UserTask' - }); - - commandStack.undo(); - - // then - el = elementRegistry.get('UserTaskWrongType'); - const taskListenersContainer = getTaskListenersContainer(el); - - expect(taskListenersContainer.get('listeners')).to.have.lengthOf(2); - })); - - - it('should redo', inject(function(bpmnReplace, commandStack, elementRegistry) { - - // given - let el = elementRegistry.get('UserTaskWrongType'); - - // when - bpmnReplace.replaceElement(el, { - type: 'bpmn:UserTask' - }); - - commandStack.undo(); - commandStack.redo(); - - // then - el = elementRegistry.get('UserTaskWrongType'); - const taskListenersContainer = getTaskListenersContainer(el); - - expect(taskListenersContainer.get('listeners')).to.have.lengthOf(1); - })); - + describe('zeebe:TaskListeners removal', function() { it('should remove zeebe:TaskListeners container when empty', inject(function(elementRegistry, modeling) { @@ -206,6 +147,22 @@ describe('camunda-cloud/features/modeling - CleanUpTaskListenersBehavior', funct expect(userTask).to.exist; expect(formDefinition).to.exist; })); + + + it('should NOT remove task listeners of unknown event type', inject(function(elementRegistry, modeling) { + + // given + const el = elementRegistry.get('UserTaskWrongType'); + + // when + modeling.updateModdleProperties(el, getBusinessObject(el), { name: 'newName' }); + + // then + const taskListenersContainer = getTaskListenersContainer(el); + + expect(taskListenersContainer).to.exist; + expect(taskListenersContainer.get('listeners')).to.have.lengthOf(2); + })); }); }); diff --git a/test/camunda-cloud/task-listeners.bpmn b/test/camunda-cloud/task-listeners.bpmn index 99bedb8..e45c5a0 100644 --- a/test/camunda-cloud/task-listeners.bpmn +++ b/test/camunda-cloud/task-listeners.bpmn @@ -42,4 +42,4 @@ - + \ No newline at end of file