2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
getBpmnJS,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import bpmnCopyPasteModule from 'lib/features/copy-paste';
|
|
|
|
import copyPasteModule from 'diagram-js/lib/features/copy-paste';
|
|
|
|
import coreModule from 'lib/core';
|
2019-08-07 13:17:28 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-09-05 19:37:41 +00:00
|
|
|
import camundaPackage from 'camunda-bpmn-moddle/resources/camunda.json';
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
2019-08-07 13:17:28 +00:00
|
|
|
find,
|
2018-04-02 19:01:53 +00:00
|
|
|
forEach,
|
2019-08-07 13:17:28 +00:00
|
|
|
isArray,
|
|
|
|
isNumber,
|
|
|
|
keys,
|
|
|
|
map,
|
|
|
|
pick,
|
|
|
|
reduce
|
2018-04-02 19:01:53 +00:00
|
|
|
} from 'min-dash';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-05-15 10:49:08 +00:00
|
|
|
import {
|
|
|
|
getBusinessObject,
|
|
|
|
is
|
|
|
|
} from 'lib/util/ModelUtil';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features/copy-paste', function() {
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
var testModules = [
|
|
|
|
bpmnCopyPasteModule,
|
|
|
|
copyPasteModule,
|
2019-08-07 13:17:28 +00:00
|
|
|
coreModule,
|
|
|
|
modelingModule
|
2018-04-02 19:01:53 +00:00
|
|
|
];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var basicXML = require('./basic.bpmn'),
|
|
|
|
copyPropertiesXML = require('./copy-properties.bpmn'),
|
|
|
|
propertiesXML = require('./properties.bpmn'),
|
|
|
|
collaborationXML = require('./collaboration.bpmn'),
|
|
|
|
collaborationMultipleXML = require('./collaboration-multiple.bpmn'),
|
2019-08-12 11:53:49 +00:00
|
|
|
collaborationAssociationsXML = require('./data-associations.bpmn'),
|
|
|
|
eventBasedGatewayXML = require('./event-based-gateway.bpmn');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('basic diagram', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-01-18 10:22:01 +00:00
|
|
|
beforeEach(bootstrapModeler(basicXML, {
|
|
|
|
modules: testModules
|
|
|
|
}));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('copy', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy sub process', inject(function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
var tree = copy('SubProcess_1');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(keys(tree)).to.have.length(3);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(getAllElementsInTree(tree, 0)).to.have.length(1);
|
|
|
|
expect(getAllElementsInTree(tree, 1)).to.have.length(3);
|
|
|
|
expect(getAllElementsInTree(tree, 2)).to.have.length(12);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(findDescriptorInTree('SubProcess_1', tree).isExpanded).to.be.true;
|
2016-05-02 06:57:12 +00:00
|
|
|
}));
|
|
|
|
|
2018-01-18 10:22:01 +00:00
|
|
|
|
2019-10-11 14:39:29 +00:00
|
|
|
describe('should copy boundary events without host', function() {
|
|
|
|
|
|
|
|
it('should copy/paste', inject(function(elementRegistry, canvas, copyPaste) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var boundaryEvent = elementRegistry.get('BoundaryEvent_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy(boundaryEvent);
|
|
|
|
|
|
|
|
var copiedElements = copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(rootElement.children).to.have.length(2);
|
|
|
|
|
|
|
|
expect(copiedElements).to.have.length(1);
|
|
|
|
|
|
|
|
expect(copiedElements[0].type).to.eql('bpmn:IntermediateCatchEvent');
|
|
|
|
|
|
|
|
expect(copiedElements[0].attachedToRef).to.be.undefined;
|
|
|
|
|
|
|
|
expect(copiedElements[0].host).to.be.undefined;
|
|
|
|
|
|
|
|
expect(copiedElements[0].id).not.to.eql(boundaryEvent.id);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy/paste and reattach', inject(function(elementRegistry, canvas, copyPaste) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var boundaryEvent = elementRegistry.get('BoundaryEvent_1'),
|
|
|
|
task = elementRegistry.get('Task_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy(boundaryEvent);
|
|
|
|
|
|
|
|
var copiedElement = copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
copyPaste.copy(copiedElement);
|
|
|
|
|
|
|
|
var attachedBoundaryEvent = copyPaste.paste({
|
|
|
|
element: task,
|
|
|
|
point: {
|
|
|
|
x: task.x,
|
|
|
|
y: task.y
|
|
|
|
},
|
|
|
|
hints: {
|
|
|
|
attach: 'attach'
|
|
|
|
}
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(attachedBoundaryEvent.businessObject.attachedToRef).to.eql(task.businessObject);
|
|
|
|
|
|
|
|
expect(attachedBoundaryEvent.host).to.be.eql(task);
|
|
|
|
|
|
|
|
expect(attachedBoundaryEvent.type).to.eql('bpmn:BoundaryEvent');
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should NOT override type property of descriptor', inject(function(elementRegistry) {
|
2018-01-18 10:22:01 +00:00
|
|
|
|
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
|
|
startEventBo = getBusinessObject(startEvent);
|
2018-01-18 10:22:01 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// add type property to business object
|
|
|
|
startEventBo.type = 'external';
|
2018-01-18 10:22:01 +00:00
|
|
|
|
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
var tree = copy(startEvent);
|
2018-01-18 10:22:01 +00:00
|
|
|
|
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(findDescriptorInTree('StartEvent_1', tree).type).to.eql('bpmn:StartEvent');
|
2018-01-18 10:22:01 +00:00
|
|
|
}));
|
|
|
|
|
2019-11-15 15:30:58 +00:00
|
|
|
|
|
|
|
it.skip('should not mutate copied elements', inject(function(copyPaste, elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var process = elementRegistry.get('Process_1'),
|
|
|
|
intermediateThrowEvent = elementRegistry.get('IntermediateThrowEvent_1');
|
|
|
|
|
|
|
|
copyPaste.copy(intermediateThrowEvent);
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.updateProperties(intermediateThrowEvent, {
|
|
|
|
name: 'foo'
|
|
|
|
});
|
|
|
|
|
|
|
|
var elements = copyPaste.paste({
|
|
|
|
element: process,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
intermediateThrowEvent = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:IntermediateThrowEvent');
|
|
|
|
});
|
|
|
|
|
|
|
|
var intermediateThrowEventBo = getBusinessObject(intermediateThrowEvent);
|
|
|
|
|
|
|
|
// due to https://github.com/bpmn-io/bpmn-js/blob/v5.1.2/lib/features/modeling/behavior/LabelBehavior.js#L97
|
|
|
|
// the business object of the copied element is mutated
|
|
|
|
// see https://github.com/bpmn-io/bpmn-js/issues/798
|
|
|
|
expect(intermediateThrowEventBo.name).not.to.exist;
|
|
|
|
}));
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should paste twice', inject(function(elementRegistry, canvas, copyPaste) {
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// given
|
|
|
|
var subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy(subProcess);
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 2000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
2017-06-20 13:51:19 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// then
|
|
|
|
expect(rootElement.children).to.have.length(9);
|
2017-06-20 13:51:19 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcesses = elements.filter(function(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(subProcesses[0].id).not.to.equal(subProcesses[1].id);
|
|
|
|
}));
|
2017-05-19 10:55:46 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('integration', function() {
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy conditional and default flow properties',
|
|
|
|
inject(function(canvas, copyPaste, elementRegistry, modeling) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.copy(subProcess);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
modeling.removeShape(subProcess);
|
|
|
|
|
|
|
|
var elements = copyPaste.paste({
|
2016-06-07 06:46:45 +00:00
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2019-08-07 13:17:28 +00:00
|
|
|
x: 300,
|
|
|
|
y: 300
|
2016-06-07 06:46:45 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
var task = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Task');
|
2016-06-07 06:46:45 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var taskBo = getBusinessObject(task);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var conditionalFlow = find(elementRegistry.getAll(), function(element) {
|
|
|
|
return is(element, 'bpmn:SequenceFlow') && element.businessObject.conditionExpression;
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var defaultFlow = find(elementRegistry.getAll(), function(element) {
|
|
|
|
return is(element, 'bpmn:SequenceFlow') && taskBo.default.id === element.id;
|
|
|
|
});
|
2016-06-07 06:46:45 +00:00
|
|
|
|
|
|
|
expect(conditionalFlow).to.exist;
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(defaultFlow).to.exist;
|
2016-06-07 06:46:45 +00:00
|
|
|
})
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2019-09-20 14:12:59 +00:00
|
|
|
it('should copy attacher properties', inject(function(canvas, copyPaste, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1'),
|
|
|
|
boundaryEvent = elementRegistry.get('BoundaryEvent_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy([ task, boundaryEvent ]);
|
|
|
|
|
|
|
|
var elements = copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
task = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Task');
|
|
|
|
});
|
|
|
|
|
|
|
|
boundaryEvent = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:BoundaryEvent');
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(getBusinessObject(boundaryEvent).attachedToRef).to.equal(getBusinessObject(task));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy loop characteristics porperties',
|
|
|
|
inject(function(canvas, copyPaste, elementRegistry, modeling) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcess = elementRegistry.get('SubProcess_2'),
|
|
|
|
rootElement = canvas.getRootElement();
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy(subProcess);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
modeling.removeShape(subProcess);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = copyPaste.paste({
|
2016-06-07 06:46:45 +00:00
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2019-08-07 13:17:28 +00:00
|
|
|
x: 300,
|
|
|
|
y: 300
|
2016-06-07 06:46:45 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
subProcess = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess');
|
|
|
|
});
|
|
|
|
|
|
|
|
var subProcessesBo = getBusinessObject(subProcess);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var loopCharacteristics = subProcessesBo.loopCharacteristics;
|
2016-06-07 06:46:45 +00:00
|
|
|
|
|
|
|
expect(loopCharacteristics.$type).to.equal('bpmn:MultiInstanceLoopCharacteristics');
|
|
|
|
expect(loopCharacteristics.isSequential).to.be.true;
|
|
|
|
})
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy color properties',
|
|
|
|
inject(function(canvas, copyPaste, elementRegistry, modeling) {
|
2017-02-03 10:03:50 +00:00
|
|
|
|
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var task = elementRegistry.get('Task_1'),
|
2017-02-03 10:03:50 +00:00
|
|
|
rootElement = canvas.getRootElement(),
|
2019-08-07 13:17:28 +00:00
|
|
|
fill = 'red',
|
|
|
|
stroke = 'green';
|
2017-02-03 10:03:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.setColor(task, { fill: fill, stroke: stroke });
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.copy(task);
|
2017-02-03 10:03:50 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = copyPaste.paste({
|
2017-02-03 10:03:50 +00:00
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2019-08-07 13:17:28 +00:00
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
2017-02-03 10:03:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
task = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Task');
|
|
|
|
});
|
|
|
|
|
|
|
|
var taskBo = getBusinessObject(task);
|
|
|
|
|
|
|
|
expect(taskBo.di.fill).to.equal(fill);
|
|
|
|
expect(taskBo.di.stroke).to.equal(stroke);
|
2017-02-03 10:03:50 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2019-08-07 18:32:47 +00:00
|
|
|
|
|
|
|
it('should copy name property', inject(
|
|
|
|
function(canvas, copyPaste, elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
copyPaste.copy(startEvent);
|
|
|
|
|
|
|
|
modeling.removeShape(startEvent);
|
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 300,
|
|
|
|
y: 300
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements).to.have.length(2);
|
|
|
|
|
|
|
|
startEvent = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:StartEvent');
|
|
|
|
});
|
|
|
|
|
|
|
|
var startEventBo = getBusinessObject(startEvent);
|
|
|
|
|
|
|
|
expect(startEventBo.name).to.equal('hello');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('rules', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-10-11 14:39:29 +00:00
|
|
|
it('should allow copying boundary event without host', inject(function(elementRegistry) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var boundaryEvent1 = elementRegistry.get('BoundaryEvent_1'),
|
|
|
|
boundaryEvent2 = elementRegistry.get('BoundaryEvent_2');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var tree = copy([ boundaryEvent1, boundaryEvent2 ]);
|
|
|
|
|
2019-10-11 14:39:29 +00:00
|
|
|
expect(keys(tree)).to.have.length(1);
|
2019-08-07 13:17:28 +00:00
|
|
|
}));
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
describe('properties', function() {
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(propertiesXML, { modules: testModules }));
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function copyPasteElement(element) {
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return getBpmnJS().invoke(function(canvas, copyPaste, elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
element = elementRegistry.get(element);
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var rootElement = canvas.getRootElement();
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy(element);
|
|
|
|
|
|
|
|
modeling.removeShape(element);
|
|
|
|
|
|
|
|
return copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
});
|
2019-08-07 13:17:28 +00:00
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste non-interrupting boundary event', function() {
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var elements = copyPasteElement('SubProcess_NonInterrupting');
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcess = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess');
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var boundaryEvent = subProcess.attachers[0],
|
|
|
|
boundaryEventBo = getBusinessObject(boundaryEvent);
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// then
|
|
|
|
expect(boundaryEventBo.cancelActivity).to.be.false;
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste interrupting boundary event', function() {
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var elements = copyPasteElement('SubProcess_Interrupting');
|
|
|
|
|
|
|
|
var subProcess = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess');
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var boundaryEvent = subProcess.attachers[0],
|
|
|
|
boundaryEventBo = getBusinessObject(boundaryEvent);
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// then
|
|
|
|
expect(boundaryEventBo.cancelActivity).to.be.true;
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste event sub process', function() {
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var elements = copyPasteElement('SubProcess_Event');
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcess = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess');
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var subProcessesBo = getBusinessObject(subProcess);
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(subProcessesBo.triggeredByEvent).to.be.true;
|
|
|
|
expect(subProcessesBo.isExpanded).to.be.true;
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste transaction', function() {
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var elements = copyPasteElement('SubProcess_Transaction');
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var transaction = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Transaction');
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(transaction).to.exist;
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste group', function() {
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
var elements = copyPasteElement('Group');
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var group = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Group');
|
|
|
|
});
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var groupBo = getBusinessObject(group);
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(groupBo.categoryValueRef).to.exist;
|
|
|
|
});
|
2019-05-15 10:49:08 +00:00
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
describe('collaboration', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
beforeEach(bootstrapModeler(collaborationXML, { modules: testModules }));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('integration', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('expanded participant', integrationTest('Participant_1'));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('collapsed participant', integrationTest('Participant_2'));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
describe('rules', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should NOT allow copying lanes without their parent participant', function() {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
var tree = copy([ 'Lane_1', 'Lane_2' ]);
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-05-19 12:56:23 +00:00
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(keys(tree)).to.have.length(0);
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
describe('collaboration (multiple)', function() {
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
beforeEach(bootstrapModeler(collaborationMultipleXML, { modules: testModules }));
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('basics', function() {
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should paste onto lane', inject(function(copyPaste, elementRegistry) {
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-05-03 14:49:10 +00:00
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var participant = elementRegistry.get('Participant_2'),
|
|
|
|
lane = elementRegistry.get('Lane_5'),
|
|
|
|
laneBo = getBusinessObject(lane),
|
|
|
|
task = elementRegistry.get('Task_1');
|
2016-05-03 14:49:10 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.copy(task);
|
2016-05-03 14:49:10 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
2016-05-03 14:49:10 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: lane,
|
|
|
|
point: {
|
|
|
|
x: 400,
|
|
|
|
y: 450
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(participant.children).to.have.length(7);
|
2019-08-07 13:17:28 +00:00
|
|
|
|
|
|
|
expect(lane.children).to.be.empty;
|
|
|
|
expect(laneBo.flowNodeRef).to.have.length(2);
|
2016-05-03 14:49:10 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should paste onto nested lane', inject(function(copyPaste, elementRegistry) {
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var participant = elementRegistry.get('Participant_1'),
|
|
|
|
lane = elementRegistry.get('Lane_3'),
|
|
|
|
laneBo = getBusinessObject(lane),
|
|
|
|
task = elementRegistry.get('Task_2');
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.copy(task);
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: lane,
|
|
|
|
point: {
|
2019-08-07 13:17:28 +00:00
|
|
|
x: 450,
|
|
|
|
y: 150
|
2016-05-02 06:57:12 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(participant.children).to.have.length(5);
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(lane.children).to.be.empty;
|
2016-05-02 06:57:12 +00:00
|
|
|
expect(lane.parent.children).to.have.length(2);
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(laneBo.flowNodeRef).to.have.length(2);
|
2016-05-02 06:57:12 +00:00
|
|
|
}));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
|
|
|
|
describe('integration', function() {
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste multiple participants', integrationTest([
|
|
|
|
'Participant_1',
|
|
|
|
'Participant_2'
|
|
|
|
]));
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
|
|
|
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
describe('participants', function() {
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2019-09-05 19:37:41 +00:00
|
|
|
beforeEach(bootstrapModeler(collaborationAssociationsXML, {
|
|
|
|
modules: testModules,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
}));
|
2016-05-20 10:40:15 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy process when copying participant', inject(
|
|
|
|
function(canvas, copyPaste, elementRegistry) {
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// given
|
2019-08-07 13:17:28 +00:00
|
|
|
var participantInput = elementRegistry.get('Participant_Input'),
|
|
|
|
participantInputBo = getBusinessObject(participantInput),
|
|
|
|
participantOutput = elementRegistry.get('Participant_Output'),
|
|
|
|
participantOutputBo = getBusinessObject(participantOutput),
|
|
|
|
rootElement = canvas.getRootElement();
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// when
|
2019-08-07 13:17:28 +00:00
|
|
|
copyPaste.copy([ participantInput, participantOutput ]);
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = copyPaste.paste({
|
2017-12-07 22:12:00 +00:00
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2019-08-07 13:17:28 +00:00
|
|
|
x: 5000,
|
|
|
|
y: 5000
|
2017-12-07 22:12:00 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// then
|
2019-08-07 13:17:28 +00:00
|
|
|
var participants = elements.filter(function(element) {
|
|
|
|
return is(element, 'bpmn:Participant');
|
2017-12-07 22:12:00 +00:00
|
|
|
});
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
forEach(participants, function(participant) {
|
|
|
|
var participantBo = getBusinessObject(participant);
|
|
|
|
|
|
|
|
expect(participantBo.processRef).not.to.equal(participantInputBo.processRef);
|
|
|
|
expect(participantBo.processRef).not.to.equal(participantOutputBo.processRef);
|
2019-09-05 19:37:41 +00:00
|
|
|
|
|
|
|
expect(participantBo.processRef.isExecutable).to.be.true;
|
|
|
|
|
|
|
|
expect(participantBo.processRef.extensionElements.values).to.have.length(1);
|
|
|
|
|
|
|
|
var executionListener = participantBo.processRef.extensionElements.values[0];
|
|
|
|
|
|
|
|
expect(executionListener.$type).to.equal('camunda:ExecutionListener');
|
|
|
|
expect(executionListener.class).to.equal('Foo');
|
|
|
|
expect(executionListener.event).to.equal('start');
|
2017-12-07 22:12:00 +00:00
|
|
|
});
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(getBusinessObject(participants[0]).processRef)
|
|
|
|
.not.to.equal(getBusinessObject(participants[1]).processRef);
|
2017-12-07 22:12:00 +00:00
|
|
|
}
|
|
|
|
));
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste participant with DataInputAssociation',
|
|
|
|
integrationTest('Participant_Input'));
|
2016-05-20 13:04:20 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy and paste participant with DataOutputAssociation',
|
|
|
|
integrationTest('Participant_Output'));
|
2016-05-20 10:40:15 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
describe('nested properties', function() {
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
beforeEach(bootstrapModeler(copyPropertiesXML, {
|
2017-01-19 15:16:56 +00:00
|
|
|
modules: testModules,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('integration', integrationTest('Participant_1'));
|
2017-01-19 15:16:56 +00:00
|
|
|
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
it('should copy user task properties', inject(function(copyPaste, elementRegistry) {
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var participant = elementRegistry.get('Participant_1'),
|
|
|
|
task = elementRegistry.get('Task_1'),
|
|
|
|
taskBo = getBusinessObject(task);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy(task);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = copyPaste.paste({
|
|
|
|
element: participant,
|
|
|
|
point: {
|
|
|
|
x: 500,
|
|
|
|
y: 50
|
|
|
|
}
|
|
|
|
});
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// then
|
|
|
|
var newTask = find(elements, function(element) {
|
|
|
|
return is(element, 'bpmn:Task');
|
|
|
|
});
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var newTaskBo = getBusinessObject(newTask);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
expect(newTaskBo.asyncBefore).to.equal(taskBo.asyncBefore);
|
|
|
|
expect(newTaskBo.documentation).to.jsonEqual(taskBo.documentation);
|
|
|
|
expect(newTaskBo.extensionElements).to.jsonEqual(taskBo.extensionElements);
|
|
|
|
}));
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
});
|
2018-04-09 09:25:18 +00:00
|
|
|
|
2019-08-12 11:53:49 +00:00
|
|
|
|
|
|
|
describe('event based gateway', function() {
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(eventBasedGatewayXML, {
|
|
|
|
modules: testModules
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy and paste event based gateway connected to an event', integrationTest([
|
|
|
|
'EventBasedGateway_1',
|
|
|
|
'IntermediateCatchEvent_1'
|
|
|
|
]));
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
});
|
2018-04-09 09:25:18 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// helpers //////////
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
/**
|
|
|
|
* Integration test involving copying, pasting, moving, undoing and redoing.
|
|
|
|
*
|
|
|
|
* @param {String|Array<String>} elementIds
|
|
|
|
*/
|
|
|
|
function integrationTest(elementIds) {
|
|
|
|
if (!isArray(elementIds)) {
|
|
|
|
elementIds = [ elementIds ];
|
|
|
|
}
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return function() {
|
2016-05-19 12:56:23 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
getBpmnJS().invoke(function(canvas, commandStack, copyPaste, elementRegistry, modeling) {
|
2016-05-19 12:56:23 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// given
|
|
|
|
var allElements = elementRegistry.getAll();
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var initialContext = {
|
|
|
|
length: allElements.length,
|
|
|
|
ids: getPropertyForElements(allElements, 'id'),
|
|
|
|
types: getPropertyForElements(allElements, 'type')
|
|
|
|
},
|
|
|
|
currentContext;
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var elements = map(elementIds, function(elementId) {
|
|
|
|
return elementRegistry.get(elementId);
|
|
|
|
});
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// (1) copy elements
|
|
|
|
copyPaste.copy(elements);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// (2) remove elements
|
|
|
|
modeling.removeElements(elements);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var rootElement = canvas.getRootElement();
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// (3) paste elements
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 500,
|
|
|
|
y: 500
|
|
|
|
}
|
|
|
|
});
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// (4) move all elements except root
|
|
|
|
modeling.moveElements(elementRegistry.filter(isRoot), { x: 50, y: -50 });
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
// (5) undo moving, pasting and removing
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
elements = elementRegistry.getAll();
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
currentContext = {
|
|
|
|
length: elements.length,
|
|
|
|
ids: getPropertyForElements(elements, 'id')
|
|
|
|
};
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// then
|
|
|
|
expect(initialContext.length).to.equal(currentContext.length);
|
|
|
|
expectCollection(initialContext.ids, currentContext.ids, true);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// when
|
|
|
|
// (6) redo removing, pasting and moving
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
elements = elementRegistry.getAll();
|
|
|
|
|
|
|
|
currentContext = {
|
|
|
|
length: elements.length,
|
|
|
|
ids: getPropertyForElements(elements, 'id'),
|
|
|
|
types: getPropertyForElements(elements, 'type')
|
|
|
|
};
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(initialContext.length).to.equal(currentContext.length);
|
|
|
|
expectCollection(initialContext.ids, currentContext.ids, false);
|
|
|
|
expectCollection(initialContext.types, currentContext.types, true);
|
2016-06-07 06:46:45 +00:00
|
|
|
});
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRoot(element) {
|
|
|
|
return !!element.parent;
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function getPropertyForElements(elements, property) {
|
|
|
|
return map(elements, function(element) {
|
|
|
|
return element[ property ];
|
|
|
|
});
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function expectCollection(collection1, collection2, contains) {
|
|
|
|
expect(collection1).to.have.length(collection2.length);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
forEach(collection2, function(element) {
|
|
|
|
if (!element.parent) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (contains) {
|
|
|
|
expect(collection1).to.contain(element);
|
|
|
|
} else {
|
|
|
|
expect(collection1).not.to.contain(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function getAllElementsInTree(tree, depth) {
|
|
|
|
var depths;
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (isNumber(depth)) {
|
|
|
|
depths = pick(tree, [ depth ]);
|
|
|
|
} else {
|
|
|
|
depths = tree;
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return reduce(depths, function(allElements, depth) {
|
|
|
|
return allElements.concat(depth);
|
|
|
|
}, []);
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function findDescriptorInTree(elements, tree, depth) {
|
|
|
|
var foundDescriptors = _findDescriptorsInTree(elements, tree, depth);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (foundDescriptors.length !== 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return foundDescriptors[0];
|
2016-06-07 06:46:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function _findDescriptorsInTree(elements, tree, depth) {
|
|
|
|
if (!isArray(elements)) {
|
|
|
|
elements = [ elements ];
|
|
|
|
}
|
|
|
|
|
|
|
|
var depths;
|
|
|
|
|
|
|
|
if (isNumber(depth)) {
|
|
|
|
depths = pick(tree, [ depth ]);
|
|
|
|
} else {
|
|
|
|
depths = tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
return reduce(elements, function(foundDescriptors, element) {
|
|
|
|
var foundDescriptor = reduce(depths, function(foundDescriptor, depth) {
|
|
|
|
return foundDescriptor || find(depth, function(descriptor) {
|
|
|
|
return element === descriptor.id || element.id === descriptor.id;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if (foundDescriptor) {
|
|
|
|
return foundDescriptors.concat(foundDescriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundDescriptors;
|
|
|
|
}, []);
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-05-19 12:56:23 +00:00
|
|
|
/**
|
2019-08-07 13:17:28 +00:00
|
|
|
* Copy elements.
|
2016-05-19 12:56:23 +00:00
|
|
|
*
|
2019-08-07 13:17:28 +00:00
|
|
|
* @param {Array<String|djs.model.Base} elements
|
2016-05-19 12:56:23 +00:00
|
|
|
*
|
2019-08-07 13:17:28 +00:00
|
|
|
* @returns {Object}
|
2016-05-19 12:56:23 +00:00
|
|
|
*/
|
2019-08-07 13:17:28 +00:00
|
|
|
function copy(elements) {
|
|
|
|
if (!isArray(elements)) {
|
|
|
|
elements = [ elements ];
|
|
|
|
}
|
2016-05-19 12:56:23 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
return getBpmnJS().invoke(function(copyPaste, elementRegistry) {
|
2016-05-19 12:56:23 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
elements = elements.map(function(element) {
|
|
|
|
element = elementRegistry.get(element.id || element);
|
2016-05-19 12:56:23 +00:00
|
|
|
|
|
|
|
expect(element).to.exist;
|
|
|
|
|
|
|
|
return element;
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return copyPaste.copy(elements);
|
2016-05-19 12:56:23 +00:00
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
}
|