diff --git a/lib/features/copy-paste/ModdleCopy.js b/lib/features/copy-paste/ModdleCopy.js index 0332be1c..30c1a840 100644 --- a/lib/features/copy-paste/ModdleCopy.js +++ b/lib/features/copy-paste/ModdleCopy.js @@ -215,8 +215,13 @@ ModdleCopy.prototype.copyProperty = function(property, parent, propertyName) { var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName); - // do NOT copy Ids and references - if (propertyDescriptor.isId || propertyDescriptor.isReference) { + // do NOT copy references + if (propertyDescriptor.isReference) { + return; + } + + // disallow copying IDs if already assigned + if (propertyDescriptor.isId && this._moddle.ids.assigned(property)) { return; } diff --git a/test/spec/features/copy-paste/ModdleCopySpec.js b/test/spec/features/copy-paste/ModdleCopySpec.js index 59c9a3e8..3b2c5f38 100644 --- a/test/spec/features/copy-paste/ModdleCopySpec.js +++ b/test/spec/features/copy-paste/ModdleCopySpec.js @@ -98,18 +98,36 @@ describe('features/copy-paste/ModdleCopy', function() { )); - it('should NOT copy IDs', inject(function(moddle, moddleCopy) { + it('should NOT copy IDs if taken', inject(function(moddle, moddleCopy, canvas, modeling) { // given - var task = moddle.create('bpmn:Task', { - id: 'foo' - }); + var task = modeling.createShape({ type: 'bpmn:Task' }, + { x: 0, y: 0 }, canvas.getRootElement()); + var taskId = task.id; // when - var userTask = moddleCopy.copyElement(task, moddle.create('bpmn:UserTask')); + var userTask = moddleCopy.copyElement(task.businessObject, moddle.create('bpmn:UserTask')); // then - expect(userTask.id).not.to.equal('foo'); + expect(userTask.id).not.to.equal(taskId); + + expectNoAttrs(userTask); + })); + + + it('should copy IDs if free', inject(function(moddle, moddleCopy, canvas, modeling) { + + // given + var task = modeling.createShape({ type: 'bpmn:Task' }, + { x: 0, y: 0 }, canvas.getRootElement()); + var taskId = task.id; + + // when + modeling.removeShape(task); + var userTask = moddleCopy.copyElement(task.businessObject, moddle.create('bpmn:UserTask')); + + // then + expect(userTask.id).to.equal(taskId); expectNoAttrs(userTask); }));