Skip to content

Commit

Permalink
feat: relax zeebe:TaskListeners cleanup based on event types
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Dec 13, 2024
1 parent 2be9142 commit 6151ed9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions lib/camunda-cloud/CleanUpTaskListenersBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
77 changes: 17 additions & 60 deletions test/camunda-cloud/CleanUpTaskListenersBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
}));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/camunda-cloud/task-listeners.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>

0 comments on commit 6151ed9

Please sign in to comment.