2018-04-02 19:01:53 +00:00
|
|
|
/* global sinon */
|
2016-04-20 15:31:42 +00:00
|
|
|
|
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 tooltipsModule from 'diagram-js/lib/features/tooltips';
|
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
map,
|
|
|
|
filter,
|
|
|
|
forEach,
|
|
|
|
uniqueBy
|
|
|
|
} from 'min-dash';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import DescriptorTree from './DescriptorTree';
|
|
|
|
|
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,
|
|
|
|
tooltipsModule,
|
|
|
|
modelingModule,
|
|
|
|
coreModule
|
|
|
|
];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
var basicXML = require('../../../fixtures/bpmn/features/copy-paste/basic.bpmn'),
|
2017-01-19 15:16:56 +00:00
|
|
|
clonePropertiesXML = require('../../../fixtures/bpmn/features/replace/clone-properties.bpmn'),
|
2016-06-14 09:06:51 +00:00
|
|
|
propertiesXML = require('../../../fixtures/bpmn/features/copy-paste/properties.bpmn'),
|
2016-04-20 15:31:42 +00:00
|
|
|
collaborationXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration.bpmn'),
|
2016-05-20 10:40:15 +00:00
|
|
|
collaborationMultipleXML = require('../../../fixtures/bpmn/features/copy-paste/collaboration-multiple.bpmn'),
|
|
|
|
collaborationAssociations = require('../../../fixtures/bpmn/features/copy-paste/data-associations.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
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('selected elements', inject(function(elementRegistry, copyPaste) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2016-05-19 12:56:23 +00:00
|
|
|
var tree = copy([ 'SubProcess_1kd6ist' ]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
var subProcess = tree.getElement('SubProcess_1kd6ist');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// then
|
|
|
|
expect(tree.getLength()).to.equal(3);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
expect(tree.getDepthLength(0)).to.equal(1);
|
|
|
|
expect(tree.getDepthLength(1)).to.equal(3);
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(tree.getDepthLength(2)).to.equal(12);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
expect(subProcess.isExpanded).to.be.true;
|
|
|
|
}));
|
|
|
|
|
2018-01-18 10:22:01 +00:00
|
|
|
|
|
|
|
it('selected elements 2', inject(function(elementRegistry, copyPaste) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var event = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// add business object type property
|
|
|
|
event.businessObject.type = 'Foo';
|
|
|
|
|
|
|
|
// when
|
|
|
|
var tree = copy([ event ]);
|
|
|
|
|
|
|
|
var eventDescriptor = tree.getElement('StartEvent_1');
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(tree.getLength()).to.equal(1);
|
|
|
|
|
|
|
|
expect(eventDescriptor.type).to.eql('bpmn:StartEvent');
|
|
|
|
}));
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2017-06-20 13:51:19 +00:00
|
|
|
it('should paste twice', inject(
|
2017-05-19 10:55:46 +00:00
|
|
|
function(elementRegistry, canvas, copyPaste) {
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('SubProcess_1kd6ist'),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy(element);
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2017-06-20 13:51:19 +00:00
|
|
|
x: 1000,
|
2017-05-19 10:55:46 +00:00
|
|
|
y: 100
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
2017-06-20 13:51:19 +00:00
|
|
|
x: 1500,
|
2017-05-19 10:55:46 +00:00
|
|
|
y: 275
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2018-12-04 10:48:36 +00:00
|
|
|
// 3 sub-processes
|
|
|
|
// 6 pasted labels
|
|
|
|
expect(rootElement.children).to.have.length(9);
|
2017-06-20 13:51:19 +00:00
|
|
|
|
|
|
|
var pastedElements = elementRegistry.filter(function(e) {
|
|
|
|
return e !== element && is(e, 'bpmn:SubProcess');
|
|
|
|
});
|
|
|
|
|
2018-05-03 14:37:24 +00:00
|
|
|
expect(pastedElements[0].id).not.to.equal(pastedElements[1].id);
|
2017-05-19 10:55:46 +00:00
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('integration', function() {
|
|
|
|
|
|
|
|
it('should retain label\'s relative position',
|
|
|
|
inject(function(modeling, copyPaste, canvas, elementRegistry) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_1'),
|
|
|
|
startEventLabel = startEvent.label,
|
|
|
|
seqFlow = elementRegistry.get('SequenceFlow_1rtr33r'),
|
|
|
|
seqFlowLabel = seqFlow.label,
|
|
|
|
task = elementRegistry.get('Task_1fo63a7'),
|
|
|
|
rootElement = canvas.getRootElement(),
|
2016-06-14 09:06:51 +00:00
|
|
|
newEvent, newFlow;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy([ startEvent, task ]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1100,
|
|
|
|
y: 250
|
|
|
|
}
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
newEvent = elementRegistry.filter(function(element) {
|
2016-06-07 06:46:45 +00:00
|
|
|
return element.parent === rootElement && element.type === 'bpmn:StartEvent';
|
|
|
|
})[0];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
newFlow = elementRegistry.filter(function(element) {
|
2016-06-07 06:46:45 +00:00
|
|
|
return element.parent === rootElement && element.type === 'bpmn:SequenceFlow';
|
|
|
|
})[0];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// then
|
2016-06-14 09:06:51 +00:00
|
|
|
expect(newEvent.label.x - newEvent.x).to.equal(startEventLabel.x - startEvent.x);
|
|
|
|
expect(newEvent.label.y - newEvent.y).to.equal(startEventLabel.y - startEvent.y);
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-09-01 16:01:04 +00:00
|
|
|
var seqFlowDeltaX = seqFlow.label.x - seqFlow.waypoints[0].x;
|
|
|
|
|
|
|
|
expect(newFlow.label.x - newFlow.waypoints[0].x).to.be.within(seqFlowDeltaX, seqFlowDeltaX + 1);
|
2016-06-14 09:06:51 +00:00
|
|
|
expect(newFlow.label.y - newFlow.waypoints[0].y).to.equal(seqFlowLabel.y - seqFlow.waypoints[0].y);
|
2016-06-07 06:46:45 +00:00
|
|
|
})
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('should retain default & conditional flow property',
|
|
|
|
inject(function(elementRegistry, copyPaste, canvas, modeling) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// given
|
|
|
|
var subProcess = elementRegistry.get('SubProcess_1kd6ist'),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
task, defaultFlow, conditionalFlow;
|
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
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
modeling.removeElements([ subProcess ]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1100,
|
|
|
|
y: 250
|
|
|
|
}
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
task = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:Task';
|
|
|
|
})[0];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
defaultFlow = elementRegistry.filter(function(element) {
|
|
|
|
return !!(element.type === 'bpmn:SequenceFlow' && task.businessObject.default.id === element.id);
|
|
|
|
})[0];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
conditionalFlow = elementRegistry.filter(function(element) {
|
|
|
|
return !!(element.type === 'bpmn:SequenceFlow' && element.businessObject.conditionExpression);
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
expect(defaultFlow).to.exist;
|
|
|
|
expect(conditionalFlow).to.exist;
|
|
|
|
})
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('should retain loop characteristics',
|
|
|
|
inject(function(elementRegistry, copyPaste, canvas, modeling) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// given
|
|
|
|
var subProcess = elementRegistry.get('SubProcess_0gev7mx'),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
loopCharacteristics;
|
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
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
modeling.removeElements([ subProcess ]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1100,
|
|
|
|
y: 250
|
|
|
|
}
|
|
|
|
});
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
subProcess = elementRegistry.filter(function(element) {
|
|
|
|
return !!(element.id !== 'SubProcess_1kd6ist' && element.type === 'bpmn:SubProcess');
|
|
|
|
})[0];
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
loopCharacteristics = subProcess.businessObject.loopCharacteristics;
|
|
|
|
|
|
|
|
expect(loopCharacteristics.$type).to.equal('bpmn:MultiInstanceLoopCharacteristics');
|
|
|
|
expect(loopCharacteristics.isSequential).to.be.true;
|
|
|
|
})
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
it.skip('selected elements', inject(integrationTest([ 'SubProcess_1kd6ist' ])));
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-02-03 10:03:50 +00:00
|
|
|
it('should retain color properties',
|
|
|
|
inject(function(modeling, copyPaste, canvas, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1fo63a7'),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
newTask,
|
|
|
|
fill = '#BBDEFB',
|
|
|
|
stroke = '#1E88E5';
|
|
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.setColor(task, { fill: fill, stroke: stroke });
|
|
|
|
|
|
|
|
copyPaste.copy([ task ]);
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1100,
|
|
|
|
y: 250
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
newTask = elementRegistry.filter(function(element) {
|
|
|
|
return element.parent === rootElement && element.type === 'bpmn:Task' && element.id !== 'Task_1fo63a7';
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(newTask.type).to.equal('bpmn:Task');
|
|
|
|
expect(newTask.businessObject.di.fill).to.equal(fill);
|
|
|
|
expect(newTask.businessObject.di.stroke).to.equal(stroke);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
2018-04-09 09:24:49 +00:00
|
|
|
it('disallow individual boundary events copying', inject(
|
|
|
|
function(copyPaste, elementRegistry, canvas) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-09 09:24:49 +00:00
|
|
|
var boundaryEventA = elementRegistry.get('BoundaryEvent_1404oxd'),
|
|
|
|
boundaryEventB = elementRegistry.get('BoundaryEvent_1c94bi9');
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-09 09:24:49 +00:00
|
|
|
// when
|
|
|
|
var tree = copy([ boundaryEventA, boundaryEventB ]);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2018-04-09 09:24:49 +00:00
|
|
|
expect(tree.getLength()).to.equal(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
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
describe('properties', function() {
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(propertiesXML, { modules: testModules }));
|
|
|
|
|
|
|
|
var subProcesses = [
|
|
|
|
'Sub_non_interrupt',
|
|
|
|
'Sub_event_subprocess',
|
|
|
|
'Sub_interrupt',
|
|
|
|
'Sub_transaction'
|
|
|
|
];
|
|
|
|
|
|
|
|
function copyPasteElement(elementRegistry, canvas, copyPaste, modeling, element) {
|
|
|
|
// given
|
|
|
|
var elem = elementRegistry.get(element),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy(elem);
|
|
|
|
|
|
|
|
modeling.removeElements([ elem ]);
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 175,
|
|
|
|
y: 450
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should copy & paste non interrupting (boundary) events',
|
|
|
|
inject(function(elementRegistry, canvas, copyPaste, modeling) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPasteElement(elementRegistry, canvas, copyPaste, modeling, 'Sub_non_interrupt');
|
|
|
|
|
|
|
|
var subProcess = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:SubProcess' && (subProcesses.indexOf(element.id) === -1);
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
var nonInterruptEvt = subProcess.attachers[0].businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(nonInterruptEvt.cancelActivity).to.be.false;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy & paste event sub processes',
|
|
|
|
inject(function(elementRegistry, canvas, copyPaste, modeling) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPasteElement(elementRegistry, canvas, copyPaste, modeling, 'Sub_event_subprocess');
|
|
|
|
|
|
|
|
var subProcess = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:SubProcess' && (subProcesses.indexOf(element.id) === -1);
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
expect(subProcess.businessObject.triggeredByEvent).to.be.true;
|
|
|
|
expect(subProcess.businessObject.isExpanded).to.be.true;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy & paste interrupting (boundary) events',
|
|
|
|
inject(function(elementRegistry, canvas, copyPaste, modeling) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPasteElement(elementRegistry, canvas, copyPaste, modeling, 'Sub_interrupt');
|
|
|
|
|
|
|
|
var subProcess = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:SubProcess' && (subProcesses.indexOf(element.id) === -1);
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
var interruptEvt = subProcess.attachers[0].businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(interruptEvt.cancelActivity).to.be.true;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy & paste transactions',
|
|
|
|
inject(function(elementRegistry, canvas, copyPaste, modeling) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPasteElement(elementRegistry, canvas, copyPaste, modeling, 'Sub_transaction');
|
|
|
|
|
|
|
|
var transaction = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:Transaction';
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
expect(transaction).to.exist;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2019-05-15 10:49:08 +00:00
|
|
|
|
|
|
|
it('should copy & paste groups',
|
|
|
|
inject(function(elementRegistry, canvas, copyPaste, modeling) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPasteElement(elementRegistry, canvas, copyPaste, modeling, 'Group');
|
|
|
|
|
|
|
|
var group = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:Group';
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
var categoryValue = getBusinessObject(group).categoryValueRef;
|
|
|
|
|
|
|
|
expect(group).to.exist;
|
|
|
|
expect(categoryValue).to.exist;
|
|
|
|
expect(categoryValue.id).to.equal('CategoryValue');
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('basic 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
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('participant with including lanes + elements', inject(integrationTest([ 'Participant_0uu1rvj' ])));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('collapsed pool', inject(integrationTest([ 'Participant_145muai' ])));
|
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
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('disallow individual lanes copying', inject(function(copyPaste, elementRegistry, canvas) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2016-05-19 12:56:23 +00:00
|
|
|
var tree = copy([ 'Lane_13h648l', 'Lane_1gl63sa' ]);
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-05-19 12:56:23 +00:00
|
|
|
// then
|
2016-05-02 06:57:12 +00:00
|
|
|
expect(tree.getLength()).to.equal(0);
|
|
|
|
}));
|
2016-04-26 13:04:24 +00:00
|
|
|
|
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
it('pasting on a collaboration is disallowed when NOT every element is a Participant',
|
2016-05-19 12:56:23 +00:00
|
|
|
inject(function(copyPaste, elementRegistry, canvas, tooltips, eventBus) {
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
var collaboration = canvas.getRootElement();
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
var pasteRejected = sinon.spy(function() {});
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
|
|
|
var tree = copy([ 'Task_13xbgyg', 'Participant_145muai' ]);
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// then
|
|
|
|
expect(tree.getDepthLength(0)).to.equal(2);
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
|
|
|
eventBus.on('elements.paste.rejected', pasteRejected);
|
2016-04-26 13:04:24 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: collaboration,
|
|
|
|
point: {
|
|
|
|
x: 1000,
|
|
|
|
y: 1000
|
|
|
|
}
|
|
|
|
});
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
expect(pasteRejected).to.have.been.called;
|
|
|
|
})
|
|
|
|
);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('pasting participants on a process is disallowed when it\'s not a collaboration',
|
|
|
|
inject(function(copyPaste, elementRegistry, canvas, tooltips, eventBus, modeling, elementFactory) {
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
var participant = elementRegistry.get('Participant_145muai'),
|
|
|
|
otherParticipant = elementRegistry.get('Participant_0uu1rvj'),
|
|
|
|
startEvent = elementFactory.create('shape', { type: 'bpmn:StartEvent' }),
|
|
|
|
rootElement;
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
var pasteRejected = sinon.spy(function() {});
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy([ participant ]);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
modeling.removeElements([ participant, otherParticipant ]);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
rootElement = canvas.getRootElement();
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
modeling.createShape(startEvent, { x: 50, y: 50 }, rootElement);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
eventBus.on('elements.paste.rejected', pasteRejected);
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 500,
|
|
|
|
y: 200
|
|
|
|
}
|
|
|
|
});
|
2016-05-02 06:57:12 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
expect(pasteRejected).to.have.been.called;
|
|
|
|
})
|
|
|
|
);
|
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('complex collaboration', 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
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
describe('basics', function() {
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-03 14:49:10 +00:00
|
|
|
it('pasting on a lane', inject(function(elementRegistry, copyPaste) {
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2016-05-03 14:49:10 +00:00
|
|
|
// given
|
|
|
|
var lane = elementRegistry.get('Lane_0aws6ii'),
|
|
|
|
task = elementRegistry.get('Task_1pamrp2'),
|
|
|
|
participant = elementRegistry.get('Participant_1id96b4');
|
|
|
|
|
|
|
|
// when
|
2016-05-19 12:56:23 +00:00
|
|
|
copyPaste.copy([ task ]);
|
2016-05-03 14:49:10 +00:00
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: lane,
|
|
|
|
point: {
|
|
|
|
x: 400,
|
|
|
|
y: 450
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(lane.children).to.be.empty;
|
|
|
|
expect(lane.businessObject.flowNodeRef).to.have.length(2);
|
|
|
|
|
2018-04-30 09:06:26 +00:00
|
|
|
expect(participant.children).to.have.length(7);
|
2016-05-03 14:49:10 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('pasting on a nested lane', inject(function(elementRegistry, copyPaste) {
|
2016-05-02 06:57:12 +00:00
|
|
|
// given
|
|
|
|
var lane = elementRegistry.get('Lane_1yo0kyz'),
|
|
|
|
task = elementRegistry.get('Task_0n0k2nj'),
|
|
|
|
participant = elementRegistry.get('Participant_0pgdgt4');
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// when
|
2016-05-19 12:56:23 +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: {
|
|
|
|
x: 200,
|
|
|
|
y: 75
|
|
|
|
}
|
|
|
|
});
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
// then
|
|
|
|
expect(lane.children).to.be.empty;
|
|
|
|
expect(lane.businessObject.flowNodeRef).to.have.length(2);
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-02 06:57:12 +00:00
|
|
|
expect(lane.parent.children).to.have.length(2);
|
|
|
|
expect(participant.children).to.have.length(5);
|
|
|
|
}));
|
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() {
|
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
it('multiple participants', inject(integrationTest([
|
|
|
|
'Participant_0pgdgt4',
|
|
|
|
'Participant_1id96b4'
|
|
|
|
])));
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
it('multiple participants', inject(integrationTest([
|
|
|
|
'Participant_0pgdgt4',
|
|
|
|
'Participant_1id96b4'
|
|
|
|
])));
|
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
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(collaborationAssociations, { modules: testModules }));
|
|
|
|
|
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
it('copying participant should copy process as well', inject(
|
|
|
|
function(elementRegistry, copyPaste, canvas) {
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// given
|
|
|
|
var participants = map([ 'Participant_Input', 'Participant_Output' ], function(e) {
|
|
|
|
return elementRegistry.get(e);
|
|
|
|
});
|
|
|
|
var rootElement = canvas.getRootElement();
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// when
|
|
|
|
copyPaste.copy(participants);
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 4000,
|
|
|
|
y: 4500
|
|
|
|
}
|
|
|
|
});
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
// then
|
|
|
|
var elements = elementRegistry.filter(function(element) {
|
|
|
|
return element.type === 'bpmn:Participant';
|
|
|
|
});
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
var processIds = map(elements, function(e) {
|
|
|
|
return e.businessObject.processRef.id;
|
|
|
|
});
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2018-03-14 20:43:53 +00:00
|
|
|
expect(uniqueBy(function(e) {return e;}, processIds)).to.have.length(4);
|
2017-12-07 22:12:00 +00:00
|
|
|
}
|
|
|
|
));
|
2016-05-20 10:40:15 +00:00
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
it('participant with DataOutputAssociation', inject(integrationTest([ 'Participant_Output' ])));
|
2016-05-20 13:04:20 +00:00
|
|
|
|
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
it('participant with DataInputAssociation', inject(integrationTest([ 'Participant_Input' ])));
|
2016-05-20 10:40:15 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
|
|
|
|
describe('deep properties', function() {
|
|
|
|
|
|
|
|
var camundaPackage = require('../../../fixtures/json/model/camunda');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(clonePropertiesXML, {
|
|
|
|
modules: testModules,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('integration', inject(integrationTest([ 'Participant_0x9lnke' ])));
|
|
|
|
|
|
|
|
|
|
|
|
it('should copy UserTask properties',
|
|
|
|
inject(function(elementRegistry, copyPaste, canvas) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_0x9lnke'),
|
|
|
|
task = elementRegistry.get('Task_1'),
|
|
|
|
newTask;
|
|
|
|
|
|
|
|
// when
|
|
|
|
copyPaste.copy([ task ]);
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: participant,
|
|
|
|
point: {
|
|
|
|
x: 500,
|
|
|
|
y: 50
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
newTask = filter(participant.children, function(element) {
|
|
|
|
return is(element, 'bpmn:Task');
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
// then
|
|
|
|
var bo = task.businessObject;
|
|
|
|
var copiedBo = newTask.businessObject;
|
|
|
|
|
|
|
|
|
|
|
|
expect(copiedBo.asyncBefore).to.eql(bo.asyncBefore);
|
|
|
|
expect(copiedBo.documentation).to.jsonEqual(bo.documentation);
|
2018-04-09 09:25:18 +00:00
|
|
|
|
|
|
|
var copiedExtensions = copiedBo.extensionElements;
|
|
|
|
|
|
|
|
expect(copiedExtensions).to.jsonEqual(bo.extensionElements);
|
|
|
|
expect(copiedExtensions.$parent).to.equal(copiedBo);
|
2017-01-19 15:16:56 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
2016-05-19 12:56:23 +00:00
|
|
|
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// test helpers //////////////////////
|
2016-06-07 06:46:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
function integrationTest(ids) {
|
|
|
|
|
|
|
|
return function(canvas, elementRegistry, modeling, copyPaste, commandStack) {
|
|
|
|
// given
|
|
|
|
var shapes = elementRegistry.getAll(),
|
|
|
|
rootElement;
|
|
|
|
|
|
|
|
var initialContext = {
|
|
|
|
type: mapProperty(shapes, 'type'),
|
|
|
|
ids: mapProperty(shapes, 'id'),
|
|
|
|
length: shapes.length
|
|
|
|
},
|
|
|
|
currentContext;
|
|
|
|
|
|
|
|
var elements = map(ids, function(id) {
|
|
|
|
return elementRegistry.get(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
copyPaste.copy(elements);
|
|
|
|
|
|
|
|
modeling.removeElements(elements);
|
|
|
|
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
copyPaste.paste({
|
|
|
|
element: rootElement,
|
|
|
|
point: {
|
|
|
|
x: 1100,
|
|
|
|
y: 250
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
elements = elementRegistry.getAll();
|
|
|
|
|
|
|
|
// remove root
|
|
|
|
elements = elementRegistry.filter(function(element) {
|
|
|
|
return !!element.parent;
|
|
|
|
});
|
|
|
|
|
|
|
|
modeling.moveElements(elements, { x: 50, y: -50 });
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
elements = elementRegistry.getAll();
|
|
|
|
|
|
|
|
currentContext = {
|
|
|
|
type: mapProperty(elements, 'type'),
|
|
|
|
ids: mapProperty(elements, 'id'),
|
|
|
|
length: elements.length
|
|
|
|
};
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(initialContext).to.have.length(currentContext.length);
|
|
|
|
|
|
|
|
expectCollection(initialContext.ids, currentContext.ids, true);
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
elements = elementRegistry.getAll();
|
|
|
|
|
|
|
|
currentContext = {
|
|
|
|
type: mapProperty(elements, 'type'),
|
|
|
|
ids: mapProperty(elements, 'id'),
|
|
|
|
length: elements.length
|
|
|
|
};
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(initialContext).to.have.length(currentContext.length);
|
|
|
|
|
|
|
|
expectCollection(initialContext.type, currentContext.type, true);
|
|
|
|
expectCollection(initialContext.ids, currentContext.ids, false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-19 12:56:23 +00:00
|
|
|
/**
|
|
|
|
* Copy elements (or elements with given ids).
|
|
|
|
*
|
|
|
|
* @param {Array<String|djs.model.Base} ids
|
|
|
|
*
|
|
|
|
* @return {DescriptorTree}
|
|
|
|
*/
|
|
|
|
function copy(ids) {
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
return getBpmnJS().invoke(function(copyPaste, elementRegistry) {
|
2016-05-19 12:56:23 +00:00
|
|
|
|
|
|
|
var elements = ids.map(function(e) {
|
|
|
|
var element = elementRegistry.get(e.id || e);
|
|
|
|
|
|
|
|
expect(element).to.exist;
|
|
|
|
|
|
|
|
return element;
|
|
|
|
});
|
|
|
|
|
|
|
|
var copyResult = copyPaste.copy(elements);
|
|
|
|
|
|
|
|
return new DescriptorTree(copyResult);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapProperty(shapes, prop) {
|
|
|
|
return map(shapes, function(shape) {
|
|
|
|
return shape[prop];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectCollection(collA, collB, contains) {
|
|
|
|
expect(collA).to.have.length(collB.length);
|
|
|
|
|
|
|
|
forEach(collB, function(element) {
|
|
|
|
if (!element.parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contains) {
|
|
|
|
expect(collA).to.contain(element);
|
|
|
|
} else {
|
2018-05-03 14:37:24 +00:00
|
|
|
expect(collA).not.to.contain(element);
|
2016-05-19 12:56:23 +00:00
|
|
|
}
|
|
|
|
});
|
2016-06-14 09:06:51 +00:00
|
|
|
}
|