From d7834e9bee2532266cf32704ad0e34e59a2c6a8c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 20 Jan 2016 11:31:01 +0100 Subject: [PATCH] feat(replace): add compensation morph options * compensation boundary * compensation activity Related to #291 --- lib/features/modeling/ElementFactory.js | 17 +- .../popup-menu/ReplaceMenuProvider.js | 8 + lib/features/popup-menu/util/TypeUtil.js | 6 +- lib/features/replace/BpmnReplace.js | 30 ++-- lib/features/replace/ReplaceOptions.js | 99 ++++++----- .../behavior/ReplaceElementBehaviourSpec.js | 22 +-- ...aceMenuProvider.compensation-activity.bpmn | 13 ++ .../popup-menu/ReplaceMenuProviderSpec.js | 160 ++++++++++-------- .../replace-preview/BpmnReplacePreviewSpec.js | 8 +- .../replace/BpmnReplace.compensation.bpmn | 13 ++ test/spec/features/replace/BpmnReplaceSpec.js | 37 +++- .../spec/features/replace/ReplaceRulesSpec.js | 2 +- 12 files changed, 258 insertions(+), 157 deletions(-) create mode 100644 test/spec/features/popup-menu/ReplaceMenuProvider.compensation-activity.bpmn create mode 100644 test/spec/features/replace/BpmnReplace.compensation.bpmn diff --git a/lib/features/modeling/ElementFactory.js b/lib/features/modeling/ElementFactory.js index 3596cad9..555ec211 100644 --- a/lib/features/modeling/ElementFactory.js +++ b/lib/features/modeling/ElementFactory.js @@ -69,7 +69,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { } } - if (!!attrs.isExpanded) { + if (attrs.isExpanded) { businessObject.di.isExpanded = attrs.isExpanded; } @@ -81,14 +81,23 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) { businessObject.isInterrupting = false; } - if (attrs._eventDefinitionType) { - var eventDefinitions = businessObject.get('eventDefinitions') || [], - newEventDefinition = this._moddle.create(attrs._eventDefinitionType); + var eventDefinitions, + newEventDefinition; + + if (attrs.eventDefinitionType) { + eventDefinitions = businessObject.get('eventDefinitions') || []; + newEventDefinition = this._moddle.create(attrs.eventDefinitionType); eventDefinitions.push(newEventDefinition); + + newEventDefinition.$parent = businessObject; businessObject.eventDefinitions = eventDefinitions; } + if (attrs.isForCompensation) { + businessObject.isForCompensation = true; + } + size = this._getDefaultSize(businessObject); attrs = assign({ diff --git a/lib/features/popup-menu/ReplaceMenuProvider.js b/lib/features/popup-menu/ReplaceMenuProvider.js index 78608076..191d218d 100644 --- a/lib/features/popup-menu/ReplaceMenuProvider.js +++ b/lib/features/popup-menu/ReplaceMenuProvider.js @@ -188,6 +188,14 @@ ReplaceMenuProvider.prototype.getEntries = function(element) { if (is(businessObject, 'bpmn:FlowNode')) { entries = filter(replaceOptions.TASK, differentType); + if (businessObject.isForCompensation) { + + // can only replace to compensation activities + entries = filter(entries, function(entry) { + return !/CallActivity|SubProcess/.test(entry.target.type); + }); + } + return this._createEntries(element, entries); } diff --git a/lib/features/popup-menu/util/TypeUtil.js b/lib/features/popup-menu/util/TypeUtil.js index 379d5b37..362c44ec 100644 --- a/lib/features/popup-menu/util/TypeUtil.js +++ b/lib/features/popup-menu/util/TypeUtil.js @@ -17,10 +17,10 @@ function isDifferentType(element) { var target = entry.target; var businessObject = getBusinessObject(element), - eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0].$type; + eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0]; - var isEventDefinitionEqual = target.eventDefinition == eventDefinition, - isTypeEqual = businessObject.$type == target.type, + var isEventDefinitionEqual = (eventDefinition && eventDefinition.$type) === target.eventDefinitionType, + isTypeEqual = businessObject.$type === target.type, isTriggeredByEventEqual = businessObject.triggeredByEvent == target.triggeredByEvent; return !isTypeEqual || !isEventDefinitionEqual || !isTriggeredByEventEqual; diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index 04c86ca3..b50bbafd 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -37,24 +37,20 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling) { var type = target.type, oldBusinessObject = element.businessObject, - businessObject = bpmnFactory.create(type); + newBusinessObject = bpmnFactory.create(type); var newElement = { type: type, - businessObject: businessObject + businessObject: newBusinessObject }; // initialize custom BPMN extensions - if (target.eventDefinition) { - var eventDefinitions = businessObject.get('eventDefinitions'), - eventDefinition = bpmnFactory.create(target.eventDefinition); - - eventDefinition.$parent = businessObject; - eventDefinitions.push(eventDefinition); + if (target.eventDefinitionType) { + newElement.eventDefinitionType = target.eventDefinitionType; } // initialize special properties defined in target definition - assign(businessObject, pick(target, CUSTOM_PROPERTIES)); + assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES)); // copy size (for activities only) if (is(oldBusinessObject, 'bpmn:Activity')) { @@ -69,20 +65,24 @@ function BpmnReplace(bpmnFactory, replace, selection, modeling) { newElement.isExpanded = isExpanded(oldBusinessObject); } - businessObject.name = oldBusinessObject.name; + newBusinessObject.name = oldBusinessObject.name; // retain loop characteristics if the target element is not an event sub process - if (!isEventSubProcess(businessObject)) { - businessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics; + if (!isEventSubProcess(newBusinessObject)) { + newBusinessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics; } // retain default flow's reference between inclusive <-> exclusive gateways and activities if ((is(oldBusinessObject, 'bpmn:ExclusiveGateway') || is(oldBusinessObject, 'bpmn:InclusiveGateway') || is(oldBusinessObject, 'bpmn:Activity')) && - (is(businessObject, 'bpmn:ExclusiveGateway') || is(businessObject, 'bpmn:InclusiveGateway') || - is(businessObject, 'bpmn:Activity'))) + (is(newBusinessObject, 'bpmn:ExclusiveGateway') || is(newBusinessObject, 'bpmn:InclusiveGateway') || + is(newBusinessObject, 'bpmn:Activity'))) { - businessObject.default = oldBusinessObject.default; + newBusinessObject.default = oldBusinessObject.default; + } + + if (oldBusinessObject.isForCompensation) { + newBusinessObject.isForCompensation = true; } newElement = replace.replaceElement(element, newElement); diff --git a/lib/features/replace/ReplaceOptions.js b/lib/features/replace/ReplaceOptions.js index f7327806..57012865 100644 --- a/lib/features/replace/ReplaceOptions.js +++ b/lib/features/replace/ReplaceOptions.js @@ -31,7 +31,7 @@ module.exports.START_EVENT = [ className: 'bpmn-icon-start-event-message', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -40,7 +40,7 @@ module.exports.START_EVENT = [ className: 'bpmn-icon-start-event-timer', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:TimerEventDefinition' + eventDefinitionType: 'bpmn:TimerEventDefinition' } }, { @@ -49,7 +49,7 @@ module.exports.START_EVENT = [ className: 'bpmn-icon-start-event-condition', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition' + eventDefinitionType: 'bpmn:ConditionalEventDefinition' } }, { @@ -58,7 +58,7 @@ module.exports.START_EVENT = [ className: 'bpmn-icon-start-event-signal', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' } } ]; @@ -94,7 +94,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-message', target: { type: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -103,7 +103,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-throw-message', target: { type: 'bpmn:IntermediateThrowEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -112,7 +112,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-timer', target: { type: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:TimerEventDefinition' + eventDefinitionType: 'bpmn:TimerEventDefinition' } }, { @@ -121,7 +121,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-throw-escalation', target: { type: 'bpmn:IntermediateThrowEvent', - eventDefinition: 'bpmn:EscalationEventDefinition' + eventDefinitionType: 'bpmn:EscalationEventDefinition' } }, { @@ -130,7 +130,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-condition', target: { type: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition' + eventDefinitionType: 'bpmn:ConditionalEventDefinition' } }, { @@ -139,7 +139,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-link', target: { type: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:LinkEventDefinition' + eventDefinitionType: 'bpmn:LinkEventDefinition' } }, { @@ -148,7 +148,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-throw-link', target: { type: 'bpmn:IntermediateThrowEvent', - eventDefinition: 'bpmn:LinkEventDefinition' + eventDefinitionType: 'bpmn:LinkEventDefinition' } }, { @@ -157,7 +157,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-throw-compensation', target: { type: 'bpmn:IntermediateThrowEvent', - eventDefinition: 'bpmn:CompensateEventDefinition' + eventDefinitionType: 'bpmn:CompensateEventDefinition' } }, { @@ -166,7 +166,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-signal', target: { type: 'bpmn:IntermediateCatchEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' } }, { @@ -175,7 +175,7 @@ module.exports.INTERMEDIATE_EVENT = [ className: 'bpmn-icon-intermediate-event-throw-signal', target: { type: 'bpmn:IntermediateThrowEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' } } ]; @@ -211,7 +211,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-message', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -220,7 +220,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-escalation', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:EscalationEventDefinition' + eventDefinitionType: 'bpmn:EscalationEventDefinition' } }, { @@ -229,7 +229,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-error', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:ErrorEventDefinition' + eventDefinitionType: 'bpmn:ErrorEventDefinition' } }, { @@ -238,7 +238,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-cancel', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' } }, { @@ -247,7 +247,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-compensation', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CompensateEventDefinition' + eventDefinitionType: 'bpmn:CompensateEventDefinition' } }, { @@ -256,7 +256,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-signal', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' } }, { @@ -265,7 +265,7 @@ module.exports.END_EVENT = [ className: 'bpmn-icon-end-event-terminate', target: { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:TerminateEventDefinition' + eventDefinitionType: 'bpmn:TerminateEventDefinition' } } ]; @@ -494,7 +494,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-message', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -503,7 +503,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-timer', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:TimerEventDefinition' + eventDefinitionType: 'bpmn:TimerEventDefinition' } }, { @@ -512,7 +512,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-escalation', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:EscalationEventDefinition' + eventDefinitionType: 'bpmn:EscalationEventDefinition' } }, { @@ -521,7 +521,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-condition', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition' + eventDefinitionType: 'bpmn:ConditionalEventDefinition' } }, { @@ -530,7 +530,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-error', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:ErrorEventDefinition' + eventDefinitionType: 'bpmn:ErrorEventDefinition' } }, { @@ -539,7 +539,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-cancel', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' } }, { @@ -548,7 +548,16 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-signal', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' + } + }, + { + label: 'Compensation Boundary Event', + actionName: 'replace-with-compensation-boundary', + className: 'bpmn-icon-intermediate-event-catch-compensation', + target: { + type: 'bpmn:BoundaryEvent', + eventDefinitionType: 'bpmn:CompensateEventDefinition' } }, { @@ -557,7 +566,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-non-interrupting-message', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:MessageEventDefinition', + eventDefinitionType: 'bpmn:MessageEventDefinition', cancelActivity: false } }, @@ -567,7 +576,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-non-interrupting-timer', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:TimerEventDefinition', + eventDefinitionType: 'bpmn:TimerEventDefinition', cancelActivity: false } }, @@ -577,7 +586,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-non-interrupting-escalation', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:EscalationEventDefinition', + eventDefinitionType: 'bpmn:EscalationEventDefinition', cancelActivity: false } }, @@ -587,7 +596,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-non-interrupting-condition', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition', + eventDefinitionType: 'bpmn:ConditionalEventDefinition', cancelActivity: false } }, @@ -597,7 +606,7 @@ module.exports.BOUNDARY_EVENT = [ className: 'bpmn-icon-intermediate-event-catch-non-interrupting-signal', target: { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:SignalEventDefinition', + eventDefinitionType: 'bpmn:SignalEventDefinition', cancelActivity: false } }, @@ -610,7 +619,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-message', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' } }, { @@ -619,7 +628,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-timer', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:TimerEventDefinition' + eventDefinitionType: 'bpmn:TimerEventDefinition' } }, { @@ -628,7 +637,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-condition', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition' + eventDefinitionType: 'bpmn:ConditionalEventDefinition' } }, { @@ -637,7 +646,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-signal', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:SignalEventDefinition' + eventDefinitionType: 'bpmn:SignalEventDefinition' } }, { @@ -646,7 +655,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-error', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:ErrorEventDefinition' + eventDefinitionType: 'bpmn:ErrorEventDefinition' } }, { @@ -655,7 +664,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-escalation', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:EscalationEventDefinition' + eventDefinitionType: 'bpmn:EscalationEventDefinition' } }, { @@ -664,7 +673,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-compensation', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:CompensateEventDefinition' + eventDefinitionType: 'bpmn:CompensateEventDefinition' } }, { @@ -673,7 +682,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-non-interrupting-message', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:MessageEventDefinition', + eventDefinitionType: 'bpmn:MessageEventDefinition', isInterrupting: false } }, @@ -683,7 +692,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-non-interrupting-timer', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:TimerEventDefinition', + eventDefinitionType: 'bpmn:TimerEventDefinition', isInterrupting: false } }, @@ -693,7 +702,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-non-interrupting-condition', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition', + eventDefinitionType: 'bpmn:ConditionalEventDefinition', isInterrupting: false } }, @@ -703,7 +712,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-non-interrupting-signal', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:SignalEventDefinition', + eventDefinitionType: 'bpmn:SignalEventDefinition', isInterrupting: false } }, @@ -713,7 +722,7 @@ module.exports.EVENT_SUB_PROCESS_START_EVENT = [ className: 'bpmn-icon-start-event-non-interrupting-escalation', target: { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:EscalationEventDefinition', + eventDefinitionType: 'bpmn:EscalationEventDefinition', isInterrupting: false } }, diff --git a/test/spec/features/modeling/behavior/ReplaceElementBehaviourSpec.js b/test/spec/features/modeling/behavior/ReplaceElementBehaviourSpec.js index 9d63e1d7..0ed93eab 100644 --- a/test/spec/features/modeling/behavior/ReplaceElementBehaviourSpec.js +++ b/test/spec/features/modeling/behavior/ReplaceElementBehaviourSpec.js @@ -113,7 +113,7 @@ describe('features/modeling - move start event behavior', function() { // when bpmnReplace.replaceElement(endEvent, { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); var subProcess = bpmnReplace.replaceElement(transaction, { type: 'bpmn:SubProcess' }); @@ -122,7 +122,7 @@ describe('features/modeling - move start event behavior', function() { // then expect(subProcess.children).to.have.length(2); - expect(newEndEvent.eventDefinitions).to.not.exist; + expect(newEndEvent.eventDefinitionTypes).to.not.exist; })); @@ -135,7 +135,7 @@ describe('features/modeling - move start event behavior', function() { // when bpmnReplace.replaceElement(endEvent, { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); bpmnReplace.replaceElement(transaction, { type: 'bpmn:SubProcess' }); @@ -162,7 +162,7 @@ describe('features/modeling - move start event behavior', function() { // when var cancelEvent = bpmnReplace.replaceElement(endEvent, { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); modeling.moveElements([ cancelEvent ], { x: 0, y: 150 }, process); @@ -187,7 +187,7 @@ describe('features/modeling - move start event behavior', function() { // when var cancelEvent = bpmnReplace.replaceElement(endEvent, { type: 'bpmn:EndEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); modeling.moveElements([ cancelEvent ], { x: 0, y: 150 }, process); @@ -216,7 +216,7 @@ describe('features/modeling - move start event behavior', function() { // when bpmnReplace.replaceElement(boundaryEvent, { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); var subProcess = bpmnReplace.replaceElement(transaction, { type: 'bpmn:SubProcess' }); @@ -224,7 +224,7 @@ describe('features/modeling - move start event behavior', function() { var newBoundaryEvent = subProcess.attachers[0].businessObject; // then - expect(newBoundaryEvent.eventDefinitions).to.not.exist; + expect(newBoundaryEvent.eventDefinitionTypes).to.not.exist; expect(newBoundaryEvent.attachedToRef).to.equal(subProcess.businessObject); expect(elementRegistry.get('Transaction_1')).to.not.exist; })); @@ -239,7 +239,7 @@ describe('features/modeling - move start event behavior', function() { // when bpmnReplace.replaceElement(boundaryEvent, { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); bpmnReplace.replaceElement(transaction, { type: 'bpmn:SubProcess' }); @@ -268,7 +268,7 @@ describe('features/modeling - move start event behavior', function() { // when var newBoundaryEvent = bpmnReplace.replaceElement(boundaryEvent, { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); modeling.moveElements([ newBoundaryEvent ], { x: 500, y: 0 }, subProcess, true); @@ -298,7 +298,7 @@ describe('features/modeling - move start event behavior', function() { // when var newBoundaryEvent = bpmnReplace.replaceElement(boundaryEvent, { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); modeling.moveElements([ newBoundaryEvent ], { x: 500, y: 0 }, subProcess, true); @@ -327,7 +327,7 @@ describe('features/modeling - move start event behavior', function() { // when var newBoundaryEvent = bpmnReplace.replaceElement(boundaryEvent, { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:CancelEventDefinition' + eventDefinitionType: 'bpmn:CancelEventDefinition' }); move.start(canvasEvent({ x: 0, y: 0 }), newBoundaryEvent); diff --git a/test/spec/features/popup-menu/ReplaceMenuProvider.compensation-activity.bpmn b/test/spec/features/popup-menu/ReplaceMenuProvider.compensation-activity.bpmn new file mode 100644 index 00000000..fe523ead --- /dev/null +++ b/test/spec/features/popup-menu/ReplaceMenuProvider.compensation-activity.bpmn @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js index 92d463a8..7cbd2b91 100644 --- a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js +++ b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js @@ -33,7 +33,7 @@ function queryPopup(popupMenu, selector) { * * @param {PopupMenu} popupMenu * - * @return {} [description] + * @return {} */ function getEntries(popupMenu) { var element = popupMenu._current.element; @@ -52,7 +52,7 @@ function triggerAction(entries, id) { } -describe('features/replace-menu', function() { +describe('features/popup-menu - replace menu provider', function() { var diagramXMLMarkers = require('../../../fixtures/bpmn/draw/activity-markers-simple.bpmn'), diagramXMLReplace = require('../../../fixtures/bpmn/features/replace/01_replace.bpmn'); @@ -83,6 +83,15 @@ describe('features/replace-menu', function() { beforeEach(bootstrapModeler(diagramXMLMarkers, { modules: testModules })); + var toggleActive; + + beforeEach(inject(function(popupMenu) { + toggleActive = function(entryCls) { + return popupMenu._getEntry(entryCls).active; + }; + })); + + describe('active attribute', function(){ it('should be true for parallel marker', inject(function(popupMenu, bpmnReplace, elementRegistry) { @@ -91,16 +100,17 @@ describe('features/replace-menu', function() { var task = elementRegistry.get('ParallelTask'), loopCharacteristics = task.businessObject.loopCharacteristics; + // assume + expect(loopCharacteristics.isSequential).to.be.false; + expect(loopCharacteristics.isSequential).to.exist; + // when openPopup(task); // then expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true; - expect(loopCharacteristics.isSequential).to.be.false; - expect(loopCharacteristics.isSequential).to.exist; - - expect(popupMenu._getEntry('toggle-parallel-mi').active).to.be.true; + expect(toggleActive('toggle-parallel-mi')).to.be.true; })); @@ -110,13 +120,15 @@ describe('features/replace-menu', function() { var task = elementRegistry.get('SequentialTask'), loopCharacteristics = task.businessObject.loopCharacteristics; + // assume + expect(loopCharacteristics.isSequential).to.be.true; + expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true; + // when openPopup(task); // then - expect(loopCharacteristics.isSequential).to.be.true; - expect(popupMenu._getEntry('toggle-sequential-mi').active).to.be.true; - expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.true; + expect(toggleActive('toggle-sequential-mi')).to.be.true; })); @@ -126,13 +138,15 @@ describe('features/replace-menu', function() { var task = elementRegistry.get('LoopTask'), loopCharacteristics = task.businessObject.loopCharacteristics; + // assume + expect(loopCharacteristics.isSequential).not.to.exist; + expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.false; + // when openPopup(task); // then - expect(loopCharacteristics.isSequential).not.to.exist; - expect(popupMenu._getEntry('toggle-loop').active).to.be.true; - expect(is(loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics')).to.be.false; + expect(toggleActive('toggle-loop')).to.be.true; })); @@ -145,7 +159,7 @@ describe('features/replace-menu', function() { openPopup(AdHocSubProcess); // then - expect(popupMenu._getEntry('toggle-adhoc').active).to.be.true; + expect(toggleActive('toggle-adhoc')).to.be.true; })); }); @@ -173,6 +187,7 @@ describe('features/replace-menu', function() { }); + describe('non exclusive toggle buttons', function(){ it('should not toggle exclusive buttons off', @@ -641,11 +656,9 @@ describe('features/replace-menu', function() { // when openPopup(startEvent); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-none-start')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(6); + expect(getEntries(popupMenu)).to.have.length(6); })); @@ -658,12 +671,11 @@ describe('features/replace-menu', function() { // when openPopup(startEvent); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-non-interrupting-message-start')).to.be.null; expect(queryEntry(popupMenu, 'replace-with-message-start')).to.exist; - expect(entriesContainer.childNodes.length).to.equal(11); + + expect(getEntries(popupMenu)).to.have.length(11); })); @@ -675,19 +687,18 @@ describe('features/replace-menu', function() { var newElement = bpmnReplace.replaceElement(startEvent, { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:ConditionalEventDefinition', + eventDefinitionType: 'bpmn:ConditionalEventDefinition', isInterrupting: false }); // when openPopup(newElement); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-conditional-start')).to.exist; expect(queryEntry(popupMenu, 'replace-with-non-interrupting-conditional-start')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(11); + + expect(getEntries(popupMenu)).to.have.length(11); })); @@ -700,11 +711,10 @@ describe('features/replace-menu', function() { // when openPopup(intermediateEvent); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-none-intermediate-throw')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(12); + + expect(getEntries(popupMenu)).to.have.length(12); })); @@ -717,11 +727,10 @@ describe('features/replace-menu', function() { // when openPopup(endEvent); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-none-end')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(8); + + expect(getEntries(popupMenu)).to.have.length(9); })); }); @@ -734,18 +743,16 @@ describe('features/replace-menu', function() { beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); it('should contain cancel event replace option', - inject(function(elementRegistry, bpmnReplace, popupMenu, replaceMenuProvider) { + // given var endEvent = elementRegistry.get('EndEvent_1'); // when openPopup(endEvent); - var entries = getEntries(popupMenu); - // then - expect(entries).to.have.length(9); + expect(getEntries(popupMenu)).to.have.length(9); })); @@ -755,15 +762,11 @@ describe('features/replace-menu', function() { // given var endEvent = elementRegistry.get('EndEvent_2'); - - // when openPopup(endEvent); - var entries = getEntries(popupMenu); - // then - expect(entries).to.have.length(8); + expect(getEntries(popupMenu)).to.have.length(9); })); @@ -773,14 +776,11 @@ describe('features/replace-menu', function() { // given var boundaryEvent = elementRegistry.get('BoundaryEvent_1'); + // when openPopup(boundaryEvent); - // when - var entries = getEntries(popupMenu); - // then - expect(entries).to.have.length(12); - + expect(getEntries(popupMenu)).to.have.length(13); })); @@ -793,11 +793,8 @@ describe('features/replace-menu', function() { // when openPopup(boundaryEvent, 40); - var entries = getEntries(popupMenu); - // then - expect(entries).to.have.length(11); - + expect(getEntries(popupMenu)).to.have.length(13); })); }); @@ -816,11 +813,9 @@ describe('features/replace-menu', function() { // when openPopup(boundaryEvent, 40); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-conditional-intermediate-catch')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(10); + expect(getEntries(popupMenu)).to.have.length(12); })); @@ -833,11 +828,23 @@ describe('features/replace-menu', function() { // when openPopup(boundaryEvent, 40); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then expect(queryEntry(popupMenu, 'replace-with-non-interrupting-message-intermediate-catch')).to.be.null; - expect(entriesContainer.childNodes.length).to.equal(10); + expect(getEntries(popupMenu)).to.have.length(12); + })); + + + it('should contain compensation boundary event', + inject(function(popupMenu, bpmnReplace, elementRegistry) { + + // given + var boundaryEvent = elementRegistry.get('BoundaryEvent_1'); + + // when + openPopup(boundaryEvent, 40); + + // then + expect(queryEntry(popupMenu, 'replace-with-compensation-boundary')).to.exist; })); }); @@ -856,10 +863,8 @@ describe('features/replace-menu', function() { // when openPopup(sequenceFlow); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then - expect(entriesContainer.childNodes.length).to.equal(1); + expect(getEntries(popupMenu)).to.have.length(1); })); @@ -870,10 +875,8 @@ describe('features/replace-menu', function() { // when openPopup(sequenceFlow); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then - expect(entriesContainer.childNodes).to.have.length(2); + expect(getEntries(popupMenu)).to.have.length(2); })); @@ -884,10 +887,8 @@ describe('features/replace-menu', function() { // when openPopup(sequenceFlow); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); - // then - expect(entriesContainer.childNodes.length).to.equal(0); + expect(getEntries(popupMenu)).to.have.length(0); })); }); @@ -946,13 +947,12 @@ describe('features/replace-menu', function() { // when openPopup(sequenceFlow); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'), - conditionalFlowEntry = queryEntry(popupMenu, 'replace-with-conditional-flow'); + var conditionalFlowEntry = queryEntry(popupMenu, 'replace-with-conditional-flow'); // then expect(conditionalFlowEntry).to.exist; - expect(entriesContainer.childNodes).to.have.length(2); + expect(getEntries(popupMenu)).to.have.length(2); })); @@ -960,13 +960,37 @@ describe('features/replace-menu', function() { // given var sequenceFlow = elementRegistry.get('SequenceFlow_1'); - //when + // when openPopup(sequenceFlow); - var entriesContainer = queryPopup(popupMenu, '.djs-popup-body'); + // then + expect(getEntries(popupMenu)).to.have.length(0); + })); + + }); + + + describe('compensate activities', function() { + + var diagramXML = require('./ReplaceMenuProvider.compensation-activity.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should exclude non-activities from options', inject(function(elementRegistry, popupMenu) { + + // given + var taskElement = elementRegistry.get('Task_1'); + + // when + openPopup(taskElement); + + var callActivityEntry = queryEntry(popupMenu, 'replace-with-call-activity'), + subProcessEntry = queryEntry(popupMenu, 'replace-with-collapsed-subprocess'); // then - expect(entriesContainer.childNodes.length).to.equal(0); + expect(callActivityEntry).to.not.exist; + expect(subProcessEntry).to.not.exist; })); }); diff --git a/test/spec/features/replace-preview/BpmnReplacePreviewSpec.js b/test/spec/features/replace-preview/BpmnReplacePreviewSpec.js index 2f050ca3..2bb29fa5 100644 --- a/test/spec/features/replace-preview/BpmnReplacePreviewSpec.js +++ b/test/spec/features/replace-preview/BpmnReplacePreviewSpec.js @@ -147,7 +147,7 @@ describe('features/replace-preview', function() { var startEventGfx = getGfx({ type: 'bpmn:StartEvent', isInterrupting: false, - _eventDefinitionType: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' }); expect(context.dragGroup[0].innerSVG()).to.equal(startEventGfx.innerSVG()); @@ -188,7 +188,7 @@ describe('features/replace-preview', function() { var startEventGfx = getGfx({ type: 'bpmn:StartEvent', isInterrupting: false, - _eventDefinitionType: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' }); expect(context.dragGroup[0].innerSVG()).to.equal(startEventGfx.innerSVG()); @@ -252,13 +252,13 @@ describe('features/replace-preview', function() { var messageStartEventGfx = getGfx({ type: 'bpmn:StartEvent', isInterrupting: false, - _eventDefinitionType: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' }); var timerStartEventGfx = getGfx({ type: 'bpmn:StartEvent', isInterrupting: false, - _eventDefinitionType: 'bpmn:TimerEventDefinition' + eventDefinitionType: 'bpmn:TimerEventDefinition' }); var startEventGfx = getGfx({ type: 'bpmn:StartEvent' }); diff --git a/test/spec/features/replace/BpmnReplace.compensation.bpmn b/test/spec/features/replace/BpmnReplace.compensation.bpmn new file mode 100644 index 00000000..fe523ead --- /dev/null +++ b/test/spec/features/replace/BpmnReplace.compensation.bpmn @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js index c21d1030..2b224480 100644 --- a/test/spec/features/replace/BpmnReplaceSpec.js +++ b/test/spec/features/replace/BpmnReplaceSpec.js @@ -15,7 +15,7 @@ var is = require('../../../../lib/util/ModelUtil').is, isEventSubProcess = require('../../../../lib/util/DiUtil').isEventSubProcess; -describe('features/replace', function() { +describe('features/replace - bpmn replace', function() { var testModules = [ coreModule, modelingModule, replaceModule, moveModule ]; @@ -129,7 +129,7 @@ describe('features/replace', function() { var boundaryEvent = elementRegistry.get('BoundaryEvent_1'), newElementData = { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:EscalationEventDefinition' + eventDefinitionType: 'bpmn:EscalationEventDefinition' }; // when @@ -150,7 +150,7 @@ describe('features/replace', function() { var boundaryEvent = elementRegistry.get('BoundaryEvent_2'), newElementData = { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:SignalEventDefinition', + eventDefinitionType: 'bpmn:SignalEventDefinition', cancelActivity: false }; @@ -159,7 +159,7 @@ describe('features/replace', function() { // then expect(newElement).to.exist; - expect(is(newElement.businessObject, 'bpmn:BoundaryEvent')).to.be.true; + expect(is(newElement, 'bpmn:BoundaryEvent')).to.be.true; expect(newElement.businessObject.eventDefinitions[0].$type).to.equal('bpmn:SignalEventDefinition'); expect(newElement.businessObject.cancelActivity).to.be.false; })); @@ -173,7 +173,7 @@ describe('features/replace', function() { host = elementRegistry.get('Task_1'), newElementData = { type: 'bpmn:BoundaryEvent', - eventDefinition: 'bpmn:ErrorEventDefinition', + eventDefinitionType: 'bpmn:ErrorEventDefinition', }; // when @@ -717,6 +717,31 @@ describe('features/replace', function() { }); + describe('compensation activity', function() { + + var diagramXML = require('./BpmnReplace.compensation.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should keep isForCompensation attr', inject(function(elementRegistry, bpmnReplace) { + + // given + var task = elementRegistry.get('Task_1'); + var newElementData = { + type: 'bpmn:ServiceTask' + }; + + // when + var newElement = bpmnReplace.replaceElement(task, newElementData); + + // then + expect(newElement.businessObject.isForCompensation).to.be.true; + })); + + }); + + describe('event sub processes', function() { var diagramXML = require('./BpmnReplace.eventSubProcesses.bpmn'); @@ -892,7 +917,7 @@ describe('features/replace', function() { var messageEvent = bpmnReplace.replaceElement(startEvent, { type: 'bpmn:StartEvent', - eventDefinition: 'bpmn:MessageEventDefinition' + eventDefinitionType: 'bpmn:MessageEventDefinition' }); var parent = messageEvent.businessObject.eventDefinitions[0].$parent; diff --git a/test/spec/features/replace/ReplaceRulesSpec.js b/test/spec/features/replace/ReplaceRulesSpec.js index 27213ba5..7815c996 100644 --- a/test/spec/features/replace/ReplaceRulesSpec.js +++ b/test/spec/features/replace/ReplaceRulesSpec.js @@ -10,7 +10,7 @@ var modelingModule = require('../../../../lib/features/modeling'), -describe('features/replace', function() { +describe('features/replace - rules', function() { var diagramXML = require('../../../fixtures/bpmn/features/replace/association-gateways.bpmn');