fix(modeling/copy-paste): copy referenced message if not present

Related to https://github.com/camunda/camunda-modeler/issues/1639
This commit is contained in:
Maciej Barelkowski 2020-01-30 17:07:03 +01:00 committed by fake-join[bot]
parent 4bafbe5d8b
commit dc5a566e10
2 changed files with 26 additions and 6 deletions

View File

@ -28,7 +28,9 @@ var LOW_PRIORITY = 500;
* Add referenced root elements (error, escalation, message, signal) if they don't exist. * Add referenced root elements (error, escalation, message, signal) if they don't exist.
* Copy referenced root elements on copy & paste. * Copy referenced root elements on copy & paste.
*/ */
export default function RootElementReferenceBehavior(bpmnjs, eventBus, injector) { export default function RootElementReferenceBehavior(
bpmnjs, eventBus, injector, moddleCopy, bpmnFactory
) {
injector.invoke(CommandInterceptor, this); injector.invoke(CommandInterceptor, this);
function hasRootElement(rootElement) { function hasRootElement(rootElement) {
@ -140,6 +142,13 @@ export default function RootElementReferenceBehavior(bpmnjs, eventBus, injector)
return; return;
} }
if (!hasRootElement(referencedRootElement)) {
referencedRootElement = moddleCopy.copyElement(
referencedRootElement,
bpmnFactory.create(referencedRootElement.$type)
);
}
eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), referencedRootElement); eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), referencedRootElement);
}); });
} }
@ -147,7 +156,9 @@ export default function RootElementReferenceBehavior(bpmnjs, eventBus, injector)
RootElementReferenceBehavior.$inject = [ RootElementReferenceBehavior.$inject = [
'bpmnjs', 'bpmnjs',
'eventBus', 'eventBus',
'injector' 'injector',
'moddleCopy',
'bpmnFactory'
]; ];
inherits(RootElementReferenceBehavior, CommandInterceptor); inherits(RootElementReferenceBehavior, CommandInterceptor);

View File

@ -51,9 +51,10 @@ describe('features/modeling - root element reference behavior', function() {
var boundaryEvent, var boundaryEvent,
host, host,
rootElement; rootElement,
pastedRootElement;
describe('should add', function() { describe('should add a copy', function() {
beforeEach(inject(function(bpmnjs, copyPaste, elementRegistry, modeling) { beforeEach(inject(function(bpmnjs, copyPaste, elementRegistry, modeling) {
@ -87,13 +88,19 @@ describe('features/modeling - root element reference behavior', function() {
attach: 'attach' attach: 'attach'
} }
})[0]; })[0];
businessObject = getBusinessObject(boundaryEvent);
pastedRootElement = getRootElementReferenced(
businessObject.get('eventDefinitions')[ 0 ]
);
})); }));
it('<do>', function() { it('<do>', function() {
// then // then
expect(hasRootElement(rootElement)).to.be.true; expect(hasRootElement(rootElement)).to.be.false;
expect(hasRootElement(pastedRootElement)).to.be.true;
}); });
@ -104,6 +111,7 @@ describe('features/modeling - root element reference behavior', function() {
// then // then
expect(hasRootElement(rootElement)).to.be.false; expect(hasRootElement(rootElement)).to.be.false;
expect(hasRootElement(pastedRootElement)).to.be.false;
})); }));
@ -116,7 +124,8 @@ describe('features/modeling - root element reference behavior', function() {
commandStack.redo(); commandStack.redo();
// then // then
expect(hasRootElement(rootElement)).to.be.true; expect(hasRootElement(rootElement)).to.be.false;
expect(hasRootElement(pastedRootElement)).to.be.true;
})); }));
}); });