fix(modeling): create ConditionalEventDefinition with condition

This ensures we always create valid BPMN 2.0 XML when
creating conditional start and intermediate events.

Closes #747
This commit is contained in:
Nico Rehwaldt 2018-01-03 14:19:01 +01:00
parent f15407d95b
commit 1f5c69a58b
2 changed files with 35 additions and 10 deletions

View File

@ -103,6 +103,10 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
eventDefinitions = businessObject.get('eventDefinitions') || []; eventDefinitions = businessObject.get('eventDefinitions') || [];
newEventDefinition = this._moddle.create(attrs.eventDefinitionType); newEventDefinition = this._moddle.create(attrs.eventDefinitionType);
if (attrs.eventDefinitionType === 'bpmn:ConditionalEventDefinition') {
newEventDefinition.condition = this._moddle.create('bpmn:FormalExpression');
}
eventDefinitions.push(newEventDefinition); eventDefinitions.push(newEventDefinition);
newEventDefinition.$parent = businessObject; newEventDefinition.$parent = businessObject;

View File

@ -1226,20 +1226,41 @@ describe('features/replace - bpmn replace', function() {
})); }));
it('should properly set parent of event definitions', inject(function(elementRegistry, modeling, bpmnReplace) { it('should properly set parent of event definitions', inject(
function(elementRegistry, modeling, bpmnReplace) {
var startEvent = elementRegistry.get('StartEvent_1'); var startEvent = elementRegistry.get('StartEvent_1');
var messageEvent = bpmnReplace.replaceElement(startEvent, { var messageEvent = bpmnReplace.replaceElement(startEvent, {
type: 'bpmn:StartEvent', type: 'bpmn:StartEvent',
eventDefinitionType: 'bpmn:MessageEventDefinition' eventDefinitionType: 'bpmn:MessageEventDefinition'
}); });
var parent = messageEvent.businessObject.eventDefinitions[0].$parent; var parent = messageEvent.businessObject.eventDefinitions[0].$parent;
expect(parent).to.exist; expect(parent).to.exist;
expect(parent).to.equal(messageEvent.businessObject); expect(parent).to.equal(messageEvent.businessObject);
})); })
);
it('should add condition with ConditionalEventDefinition', inject(
function(elementRegistry, modeling, bpmnReplace) {
var startEvent = elementRegistry.get('StartEvent_1');
// when
var messageEvent = bpmnReplace.replaceElement(startEvent, {
type: 'bpmn:StartEvent',
eventDefinitionType: 'bpmn:ConditionalEventDefinition'
});
var definition = messageEvent.businessObject.eventDefinitions[0];
// then
expect(definition.condition).to.exist;
})
);
}); });