Skip to content

Commit

Permalink
fix(delete-participant-behavior): ignore empty participants
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Nov 2, 2023
1 parent 2f47deb commit 546a1f8
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 66 deletions.
17 changes: 11 additions & 6 deletions lib/shared/DeleteParticipantBehaviour.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { is } from 'bpmn-js/lib/util/ModelUtil';
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

import { is } from 'bpmn-js/lib/util/ModelUtil';

const LOW_PRIORITY = 250;

/**
* Camunda specific behavior ensuring process.isExecutable is kept after deleting
* the last Participant.
* Camunda-specific behavior ensuring `isExecutable` is kept after deleting
* the last participant.
*/
export default class DeleteParticipantBehaviour extends CommandInterceptor {
constructor(eventBus, canvas, modeling) {
Expand All @@ -21,12 +22,16 @@ export default class DeleteParticipantBehaviour extends CommandInterceptor {

if (is(shape, 'bpmn:Participant') &&
collaborationRoot &&
!collaborationRoot.businessObject.participants.length &&
!collaborationRoot.businessObject.get('participants').length &&
is(newRoot, 'bpmn:Process')) {

const oldProcessBo = shape.businessObject.processRef;
const oldProcessBusinessObject = shape.businessObject.get('processRef');

if (!oldProcessBusinessObject) {
return;
}

modeling.updateProperties(newRoot, { isExecutable: oldProcessBo.isExecutable });
modeling.updateProperties(newRoot, { isExecutable: oldProcessBusinessObject.get('isExecutable') });
}

}, true);
Expand Down
114 changes: 84 additions & 30 deletions test/camunda-cloud/DeleteParticipantBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,110 @@ import {

import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';

import diagramXML from './process-executable-participant.bpmn';
import participantXML from './process-executable-participant.bpmn';
import emptyParticipantXML from './process-empty-participant.bpmn';


describe('camunda-platform/features/modeling - DeleteParticipantBehaviour', function() {

beforeEach(bootstrapCamundaCloudModeler(diagramXML));
describe('set isExecuteable on new process after deleting last participant', function() {

describe('remove set isExecuteable on new Process', function() {
describe('non-empty participant', function() {

beforeEach(inject(function(elementRegistry, modeling) {
beforeEach(bootstrapCamundaCloudModeler(participantXML));

// given
const shape = elementRegistry.get('Participant_1');
beforeEach(inject(function(elementRegistry, modeling) {

// when
modeling.removeShape(shape);
}));
// given
const shape = elementRegistry.get('Participant_1');

// when
modeling.removeShape(shape);
}));

it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));
it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));

it('should undo', inject(function(canvas, commandStack) {

// given
const newRoot = getBusinessObject(canvas.getRootElement());
it('should undo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
// given
const newRoot = getBusinessObject(canvas.getRootElement());

// then
expect(newRoot.isExecutable).not.to.exist;
}));
// when
commandStack.undo();

// then
expect(newRoot.isExecutable).not.to.exist;
}));

it('should redo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
commandStack.redo();
it('should redo', inject(function(canvas, commandStack) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));
// when
commandStack.undo();
commandStack.redo();

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));

});


describe('empty participant', function() {

beforeEach(bootstrapCamundaCloudModeler(emptyParticipantXML));

beforeEach(inject(function(elementRegistry, modeling) {

// given
const shape = elementRegistry.get('Participant_1');

// when
modeling.removeShape(shape);
}));


it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).not.to.exist;
}));


it('should undo', inject(function(canvas, commandStack) {

// given
const newRoot = getBusinessObject(canvas.getRootElement());

// when
commandStack.undo();

// then
expect(newRoot.isExecutable).not.to.exist;
}));


it('should redo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
commandStack.redo();

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).not.to.exist;
}));

});

});

Expand Down
13 changes: 13 additions & 0 deletions test/camunda-cloud/process-empty-participant.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1c4sv4m" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.16.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.3.0">
<bpmn:collaboration id="Collaboration_1">
<bpmn:participant id="Participant_1" />
</bpmn:collaboration>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_00m8alv_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="160" y="80" width="600" height="60" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
114 changes: 84 additions & 30 deletions test/camunda-platform/DeleteParticipantBehaviorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,110 @@ import {

import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';

import diagramXML from './camunda-executable-participant.bpmn';
import participantXML from './camunda-executable-participant.bpmn';
import emptyParticipantXML from './camunda-empty-participant.bpmn';


describe('camunda-platform/features/modeling - DeleteParticipantBehaviour', function() {

beforeEach(bootstrapCamundaPlatformModeler(diagramXML));
describe('set isExecuteable on new process after deleting last participant', function() {

describe('remove set isExecuteable on new Process', function() {
describe('non-empty participant', function() {

beforeEach(inject(function(elementRegistry, modeling) {
beforeEach(bootstrapCamundaPlatformModeler(participantXML));

// given
const shape = elementRegistry.get('Participant_1');
beforeEach(inject(function(elementRegistry, modeling) {

// when
modeling.removeShape(shape);
}));
// given
const shape = elementRegistry.get('Participant_1');

// when
modeling.removeShape(shape);
}));

it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));
it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));

it('should undo', inject(function(canvas, commandStack) {

// given
const newRoot = getBusinessObject(canvas.getRootElement());
it('should undo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
// given
const newRoot = getBusinessObject(canvas.getRootElement());

// then
expect(newRoot.isExecutable).not.to.exist;
}));
// when
commandStack.undo();

// then
expect(newRoot.isExecutable).not.to.exist;
}));

it('should redo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
commandStack.redo();
it('should redo', inject(function(canvas, commandStack) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));
// when
commandStack.undo();
commandStack.redo();

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).to.be.true;
}));

});


describe('empty participant', function() {

beforeEach(bootstrapCamundaPlatformModeler(emptyParticipantXML));

beforeEach(inject(function(elementRegistry, modeling) {

// given
const shape = elementRegistry.get('Participant_1');

// when
modeling.removeShape(shape);
}));


it('should execute', inject(function(canvas) {

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).not.to.exist;
}));


it('should undo', inject(function(canvas, commandStack) {

// given
const newRoot = getBusinessObject(canvas.getRootElement());

// when
commandStack.undo();

// then
expect(newRoot.isExecutable).not.to.exist;
}));


it('should redo', inject(function(canvas, commandStack) {

// when
commandStack.undo();
commandStack.redo();

// then
const newRoot = getBusinessObject(canvas.getRootElement());
expect(newRoot.isExecutable).not.to.exist;
}));

});

});

Expand Down
13 changes: 13 additions & 0 deletions test/camunda-platform/camunda-empty-participant.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0w6issw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.16.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.3.0">
<bpmn:collaboration id="Collaboration_1">
<bpmn:participant id="Participant_1" />
</bpmn:collaboration>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_188ecvg_di" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds x="160" y="80" width="600" height="60" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 546a1f8

Please sign in to comment.