diff --git a/lib/features/modeling/behavior/RemoveBehavior.js b/lib/features/modeling/behavior/RemoveBehavior.js index 3c07fe53..99491d8c 100644 --- a/lib/features/modeling/behavior/RemoveBehavior.js +++ b/lib/features/modeling/behavior/RemoveBehavior.js @@ -33,7 +33,7 @@ function RemoveBehavior(eventBus, modeling) { var collaborationRoot = context.collaborationRoot; - if (collaborationRoot && collaborationRoot.businessObject.participants.length < 2) { + if (collaborationRoot && !collaborationRoot.businessObject.participants.length) { // replace empty collaboration with process diagram modeling.makeProcess(); } diff --git a/test/fixtures/bpmn/collaboration/collaboration-message-flows.bpmn b/test/fixtures/bpmn/collaboration/collaboration-message-flows.bpmn index ed430f52..48198f21 100644 --- a/test/fixtures/bpmn/collaboration/collaboration-message-flows.bpmn +++ b/test/fixtures/bpmn/collaboration/collaboration-message-flows.bpmn @@ -1,11 +1,11 @@ - - + + - - + + @@ -28,7 +28,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -77,11 +77,11 @@ - + - + diff --git a/test/spec/features/modeling/CreateParticipantSpec.js b/test/spec/features/modeling/behavior/CreateBehaviorSpec.js similarity index 92% rename from test/spec/features/modeling/CreateParticipantSpec.js rename to test/spec/features/modeling/behavior/CreateBehaviorSpec.js index f7695323..e36c4607 100644 --- a/test/spec/features/modeling/CreateParticipantSpec.js +++ b/test/spec/features/modeling/behavior/CreateBehaviorSpec.js @@ -1,12 +1,12 @@ 'use strict'; -var TestHelper = require('../../../TestHelper'); +var TestHelper = require('../../../../TestHelper'); /* global bootstrapModeler, inject */ -var modelingModule = require('../../../../lib/features/modeling'), - coreModule = require('../../../../lib/core'); +var modelingModule = require('../../../../../lib/features/modeling'), + coreModule = require('../../../../../lib/core'); describe('features/modeling - create participant', function() { @@ -18,7 +18,7 @@ describe('features/modeling - create participant', function() { describe('should transform diagram into collaboration', function() { - var processDiagramXML = require('../../../fixtures/bpmn/collaboration/process-empty.bpmn'); + var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/process-empty.bpmn'); beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); @@ -98,7 +98,7 @@ describe('features/modeling - create participant', function() { describe('should wrap existing elements', function() { - var processDiagramXML = require('../../../fixtures/bpmn/collaboration/process.bpmn'); + var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/process.bpmn'); beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); @@ -151,7 +151,7 @@ describe('features/modeling - create participant', function() { describe('should add to collaboration', function() { - var collaborationDiagramXML = require('../../../fixtures/bpmn/collaboration/collaboration-participant.bpmn'); + var collaborationDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-participant.bpmn'); beforeEach(bootstrapModeler(collaborationDiagramXML, { modules: testModules })); diff --git a/test/spec/features/modeling/behavior/RemoveBehaviorSpec.js b/test/spec/features/modeling/behavior/RemoveBehaviorSpec.js new file mode 100644 index 00000000..fb52df29 --- /dev/null +++ b/test/spec/features/modeling/behavior/RemoveBehaviorSpec.js @@ -0,0 +1,126 @@ +'use strict'; + +var TestHelper = require('../../../../TestHelper'); + +/* global bootstrapModeler, inject */ + +var is = require('../../../../../lib/util/ModelUtil').is; + +var modelingModule = require('../../../../../lib/features/modeling'), + coreModule = require('../../../../../lib/core'); + + +describe('features/modeling - remove behavior', function() { + + var testModules = [ coreModule, modelingModule ]; + + + describe('when removing participant in collaboration', function() { + + var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-message-flows.bpmn'); + + beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); + + + describe('retain collaboration', function() { + + it('execute', inject(function(modeling, elementRegistry, canvas) { + + // given + var participantShape = elementRegistry.get('Participant_2'); + + // when + modeling.removeShape(participantShape); + + // then + var rootElement = canvas.getRootElement(); + + expect(is(rootElement, 'bpmn:Collaboration')).toBeTruthy(); + })); + + }); + + }); + + + describe('when removing last remaining participant', function() { + + var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-empty-participant.bpmn'); + + beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); + + + describe('should transform diagram into process diagram', function() { + + it('execute', inject(function(modeling, elementRegistry, canvas) { + + // given + var participantShape = elementRegistry.get('_Participant_2'), + participant = participantShape.businessObject, + participantDi = participant.di, + process = participant.processRef, + collaborationElement = participantShape.parent, + collaboration = collaborationElement.businessObject, + diPlane = collaboration.di, + bpmnDefinitions = collaboration.$parent; + + // when + modeling.removeShape(participantShape); + + // then + expect(participant.$parent).toBeFalsy(); + + var newRootShape = canvas.getRootElement(), + newRootBusinessObject = newRootShape.businessObject; + + expect(newRootBusinessObject.$instanceOf('bpmn:Process')).toBe(true); + + // collaboration DI is unwired + expect(participantDi.$parent).toBeFalsy(); + expect(collaboration.di).toBeFalsy(); + + expect(bpmnDefinitions.rootElements).not.toContain(process); + expect(bpmnDefinitions.rootElements).not.toContain(collaboration); + + // process DI is wired + expect(diPlane.bpmnElement).toBe(newRootBusinessObject); + expect(newRootBusinessObject.di).toBe(diPlane); + + expect(bpmnDefinitions.rootElements).toContain(newRootBusinessObject); + })); + + + it('undo', inject(function(modeling, elementRegistry, canvas, commandStack) { + + // given + var participantShape = elementRegistry.get('_Participant_2'), + participant = participantShape.businessObject, + originalRootElement = participantShape.parent, + originalRootElementBo = originalRootElement.businessObject, + bpmnDefinitions = originalRootElementBo.$parent, + participantDi = participant.di, + diPlane = participantDi.$parent; + + modeling.removeShape(participantShape); + + // when + commandStack.undo(); + + // then + expect(participant.$parent).toBe(originalRootElementBo); + expect(originalRootElementBo.$parent).toBe(bpmnDefinitions); + + expect(canvas.getRootElement()).toBe(originalRootElement); + + // di is unwired + expect(participantDi.$parent).toBe(originalRootElementBo.di); + + // new di is wired + expect(diPlane.bpmnElement).toBe(originalRootElementBo); + })); + + }); + + }); + +}); \ No newline at end of file