2015-01-19 11:13:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var TestHelper = require('../../../TestHelper');
|
|
|
|
|
|
|
|
/* global bootstrapModeler, inject */
|
|
|
|
|
|
|
|
var modelingModule = require('../../../../lib/features/modeling'),
|
|
|
|
replaceModule = require('../../../../lib/features/replace'),
|
2015-06-24 09:43:07 +00:00
|
|
|
coreModule = require('../../../../lib/core'),
|
|
|
|
is = require('../../../../lib/util/ModelUtil').is;
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features/replace', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/features/replace/01_replace.bpmn');
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
var testModules = [ coreModule, modelingModule, replaceModule ];
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
|
|
|
|
|
|
|
describe('should replace', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('task', inject(function(elementRegistry, modeling, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
var businessObject = newElement.businessObject;
|
|
|
|
|
|
|
|
expect(newElement).toBeDefined();
|
2015-06-24 09:43:07 +00:00
|
|
|
expect(is(businessObject, 'bpmn:UserTask')).toBe(true);
|
2015-01-19 11:13:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('gateway', inject(function(elementRegistry, modeling, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var gateway = elementRegistry.get('ExclusiveGateway_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:InclusiveGateway'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(gateway, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
var businessObject = newElement.businessObject;
|
|
|
|
|
|
|
|
expect(newElement).toBeDefined();
|
2015-06-24 09:43:07 +00:00
|
|
|
expect(is(businessObject, 'bpmn:InclusiveGateway')).toBe(true);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('expanded sub process', inject(function(elementRegistry, modeling, bpmnReplace, canvas) {
|
2015-07-13 13:18:18 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
// given
|
|
|
|
var subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
newElementData = {
|
|
|
|
type: 'bpmn:Transaction',
|
|
|
|
isExpanded: true
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
var newElement = bpmnReplace.replaceElement(subProcess, newElementData);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(newElement).toBeDefined();
|
|
|
|
expect(is(newElement.businessObject, 'bpmn:Transaction')).toBe(true);
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('transaction', inject(function(elementRegistry, modeling, bpmnReplace, canvas) {
|
2015-07-13 13:18:18 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
var transaction = elementRegistry.get('Transaction_1'),
|
|
|
|
newElementData = {
|
|
|
|
type: 'bpmn:SubProcess',
|
|
|
|
isExpanded: true
|
|
|
|
};
|
|
|
|
|
|
|
|
var newElement = bpmnReplace.replaceElement(transaction, newElementData);
|
|
|
|
|
|
|
|
expect(newElement).toBeDefined();
|
|
|
|
expect(is(newElement.businessObject, 'bpmn:SubProcess')).toBe(true);
|
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('position and size', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should keep position', inject(function(elementRegistry, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(newElement.x).toBe(346);
|
|
|
|
expect(newElement.y).toBe(149);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-03-11 15:31:42 +00:00
|
|
|
describe('selection', function() {
|
|
|
|
|
|
|
|
it('should select after replace', inject(function(elementRegistry, selection, bpmnReplace) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(selection.get()).toContain(newElement);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
describe('label', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should keep copy label', inject(function(elementRegistry, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(newElement.businessObject.name).toBe('Task Caption');
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
describe('undo support', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should undo replace', inject(function(elementRegistry, modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var target = elementRegistry.get('Task_1'),
|
|
|
|
businessObject = target.businessObject;
|
|
|
|
|
|
|
|
expect(target).toBeDefined();
|
2015-06-24 09:43:07 +00:00
|
|
|
expect(is(businessObject, 'bpmn:Task')).toBe(true);
|
2015-01-19 11:13:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should redo replace', inject(function(elementRegistry, modeling, bpmnReplace, commandStack, eventBus) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
var newElementData2 = {
|
|
|
|
type: 'bpmn:ServiceTask'
|
|
|
|
};
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
var usertask = bpmnReplace.replaceElement(task, newElementData);
|
|
|
|
var servicetask = bpmnReplace.replaceElement(usertask, newElementData2);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var businessObject = servicetask.businessObject;
|
|
|
|
|
|
|
|
expect(servicetask).toBeDefined();
|
2015-06-24 09:43:07 +00:00
|
|
|
expect(is(businessObject, 'bpmn:ServiceTask')).toBe(true);
|
2015-01-19 11:13:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('connection handling', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should reconnect valid connections', inject(function(elementRegistry, modeling, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0],
|
|
|
|
source = incoming.source,
|
|
|
|
target = outgoing.target;
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeDefined();
|
|
|
|
expect(outgoing).toBeDefined();
|
|
|
|
expect(source).toBe(elementRegistry.get('StartEvent_1'));
|
|
|
|
expect(target).toBe(elementRegistry.get('ExclusiveGateway_1'));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should remove invalid incomming connections', inject(function(elementRegistry, modeling, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('StartEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:EndEvent'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0];
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeUndefined();
|
|
|
|
expect(outgoing).toBeUndefined();
|
|
|
|
}));
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
it('should remove invalid outgoing connections', inject(function(elementRegistry, modeling, bpmnReplace) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('EndEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:StartEvent'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0];
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeUndefined();
|
|
|
|
expect(outgoing).toBeUndefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
describe('undo support', function() {
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should reconnect valid connections', inject(function(elementRegistry, modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var newTask = elementRegistry.get('Task_1');
|
|
|
|
var incoming = newTask.incoming[0],
|
|
|
|
outgoing = newTask.outgoing[0],
|
|
|
|
source = incoming.source,
|
|
|
|
target = outgoing.target;
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeDefined();
|
|
|
|
expect(outgoing).toBeDefined();
|
|
|
|
expect(source).toBe(elementRegistry.get('StartEvent_1'));
|
|
|
|
expect(target).toBe(elementRegistry.get('ExclusiveGateway_1'));
|
|
|
|
}));
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
it('should remove invalid incoming connections', inject(function(elementRegistry,
|
2015-03-11 15:17:19 +00:00
|
|
|
modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:EndEvent'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
bpmnReplace.replaceElement(startEvent, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var newEvent = elementRegistry.get('StartEvent_1');
|
|
|
|
var incoming = newEvent.incoming[0],
|
|
|
|
outgoing = newEvent.outgoing[0],
|
|
|
|
target = outgoing.target;
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeUndefined();
|
|
|
|
expect(outgoing).toBeDefined();
|
|
|
|
expect(target).toBe(elementRegistry.get('Task_1'));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should remove invalid outgoing connections', inject(function(elementRegistry,
|
2015-03-11 15:17:19 +00:00
|
|
|
modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var endEvent = elementRegistry.get('EndEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:StartEvent'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
bpmnReplace.replaceElement(endEvent, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var newEvent = elementRegistry.get('EndEvent_1');
|
|
|
|
var incoming = newEvent.incoming[0],
|
|
|
|
outgoing = newEvent.outgoing[0],
|
|
|
|
source = incoming.source;
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeDefined();
|
|
|
|
expect(outgoing).toBeUndefined();
|
|
|
|
expect(source).toBe(elementRegistry.get('ExclusiveGateway_1'));
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
describe('redo support', function() {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
it('should reconnect valid connections', inject(function(elementRegistry, modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:UserTask'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(task, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0],
|
|
|
|
source = incoming.source,
|
|
|
|
target = outgoing.target;
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeDefined();
|
|
|
|
expect(outgoing).toBeDefined();
|
|
|
|
expect(source).toBe(elementRegistry.get('StartEvent_1'));
|
|
|
|
expect(target).toBe(elementRegistry.get('ExclusiveGateway_1'));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should remove invalid incoming connections', inject(function(elementRegistry,
|
2015-03-11 15:17:19 +00:00
|
|
|
modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:EndEvent'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(startEvent, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0];
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeUndefined();
|
|
|
|
expect(outgoing).toBeUndefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should remove invalid outgoing connections', inject(function(elementRegistry,
|
2015-03-11 15:17:19 +00:00
|
|
|
modeling, bpmnReplace, commandStack) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var endEvent = elementRegistry.get('EndEvent_1');
|
|
|
|
var newElementData = {
|
|
|
|
type: 'bpmn:StartEvent'
|
|
|
|
};
|
2015-03-11 15:17:19 +00:00
|
|
|
var newElement = bpmnReplace.replaceElement(endEvent, newElementData);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
var incoming = newElement.incoming[0],
|
|
|
|
outgoing = newElement.outgoing[0];
|
|
|
|
|
|
|
|
|
|
|
|
expect(incoming).toBeUndefined();
|
|
|
|
expect(outgoing).toBeUndefined();
|
|
|
|
}));
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-07-13 13:18:18 +00:00
|
|
|
|
|
|
|
describe('children handling', function() {
|
|
|
|
|
|
|
|
it('should update bpmn containment properly', inject(function(elementRegistry, modeling, bpmnReplace) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
|
|
|
var startEventShape = elementRegistry.get('StartEvent_2');
|
|
|
|
var taskShape = elementRegistry.get('Task_2');
|
|
|
|
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_4');
|
|
|
|
|
|
|
|
var transactionShapeData = {
|
|
|
|
type: 'bpmn:Transaction'
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
var transactionShape = bpmnReplace.replaceElement(subProcessShape, transactionShapeData);
|
|
|
|
|
|
|
|
// then
|
|
|
|
var subProcess = subProcessShape.businessObject,
|
|
|
|
transaction = transactionShape.businessObject;
|
|
|
|
|
|
|
|
var transactionChildren = transaction.get('flowElements');
|
|
|
|
var subProcessChildren = subProcess.get('flowElements');
|
|
|
|
|
|
|
|
expect(transactionChildren).toContain(startEventShape.businessObject);
|
|
|
|
expect(transactionChildren).toContain(taskShape.businessObject);
|
|
|
|
expect(transactionChildren).toContain(sequenceFlowConnection.businessObject);
|
|
|
|
|
|
|
|
expect(subProcessChildren).not.toContain(startEventShape.businessObject);
|
|
|
|
expect(subProcessChildren).not.toContain(taskShape.businessObject);
|
|
|
|
expect(subProcessChildren).not.toContain(sequenceFlowConnection.businessObject);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
});
|