diff --git a/lib/features/modeling/behavior/GroupBehavior.js b/lib/features/modeling/behavior/GroupBehavior.js index 193beffe..11e5114c 100644 --- a/lib/features/modeling/behavior/GroupBehavior.js +++ b/lib/features/modeling/behavior/GroupBehavior.js @@ -145,13 +145,19 @@ export default function GroupBehavior(eventBus, bpmnFactory, canvas, elementRegi var context = event.context, shape = context.shape, - businessObject = getBusinessObject(shape); + businessObject = getBusinessObject(shape), + oldBusinessObject = shape.oldBusinessObject; if (is(businessObject, 'bpmn:Group') && !businessObject.categoryValueRef) { var definitions = getDefinitions(), categoryValue = createCategoryValue(definitions, bpmnFactory); + // set name from copied group if existing + if (oldBusinessObject && oldBusinessObject.categoryValueRef) { + categoryValue.value = oldBusinessObject.categoryValueRef.value; + } + // link the reference to the Group businessObject.categoryValueRef = categoryValue; diff --git a/test/spec/features/modeling/behavior/GroupBehaviorSpec.js b/test/spec/features/modeling/behavior/GroupBehaviorSpec.js index 29a740a4..8ae9c30e 100644 --- a/test/spec/features/modeling/behavior/GroupBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/GroupBehaviorSpec.js @@ -1,3 +1,4 @@ +/* global sinon */ import { bootstrapModeler, inject @@ -11,13 +12,19 @@ import { indexOf as collectionIndexOf } from 'diagram-js/lib/util/Collections'; +import bpmnCopyPasteModule from 'lib/features/copy-paste'; +import copyPasteModule from 'diagram-js/lib/features/copy-paste'; import modelingModule from 'lib/features/modeling'; import coreModule from 'lib/core'; describe('features/modeling/behavior - groups', function() { - var testModules = [ coreModule, modelingModule ]; + var testModules = [ + coreModule, + copyPasteModule, + bpmnCopyPasteModule, + modelingModule ]; var processDiagramXML = require('./GroupBehaviorSpec.bpmn'); @@ -146,6 +153,46 @@ describe('features/modeling/behavior - groups', function() { }); + + describe('should set copied name for pasted group', function() { + + it('execute', inject(function(canvas, elementRegistry, copyPaste, eventBus) { + + // given + var groupShape = elementRegistry.get('Group_1'), + categoryValue = getBusinessObject(groupShape).categoryValueRef, + root = canvas.getRootElement(), + listener = sinon.spy(function(event) { + + var context = event.context, + createdElement = context.shape, + businessObject = createdElement.businessObject, + categoryValueRef = businessObject.categoryValueRef; + + expect(categoryValueRef).to.exist; + expect(categoryValueRef).to.not.eql(categoryValue); + expect(categoryValueRef.value).to.equal(categoryValue.value); + + }); + + eventBus.on('commandStack.shape.create.postExecute', listener); + + // when + copyPaste.copy(groupShape); + copyPaste.paste({ + element: root, + point: { + x: 50, + y: 50 + } + }); + + // then + expect(listener).to.have.been.called; + + })); + }); + });