From 8c5c68b896e3118be066d25e73c43418e9284236 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 26 Feb 2018 23:17:25 -0500 Subject: [PATCH] Duplicating sprite should give new sprite a fresh name. --- src/sprites/sprite.js | 2 +- test/unit/virtual-machine.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/sprites/sprite.js b/src/sprites/sprite.js index bf68c98d1..941b20403 100644 --- a/src/sprites/sprite.js +++ b/src/sprites/sprite.js @@ -84,7 +84,7 @@ class Sprite { newSprite.blocks = this.blocks.duplicate(); - const allNames = this.runtime.targets.map(t => t.name); + const allNames = this.runtime.targets.map(t => t.sprite.name); newSprite.name = StringUtil.unusedName(this.name, allNames); const assetPromises = []; diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index 0ade2c647..ceee87b79 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -105,7 +105,7 @@ test('renameSprite does not increment when renaming to the same name', t => { t.equal(vm.runtime.targets[0].sprite.name, 'foo'); vm.renameSprite(target.id, 'foo'); t.equal(vm.runtime.targets[0].sprite.name, 'foo'); - + t.end(); }); @@ -276,6 +276,26 @@ test('duplicateSprite duplicates a sprite when given id is associated with known }); +test('duplicateSprite assigns duplicated sprite a fresh name', t => { + const vm = new VirtualMachine(); + const spr = new Sprite(null, vm.runtime); + spr.name = 'sprite1'; + const currTarget = spr.createClone(); + vm.editingTarget = currTarget; + + vm.emitWorkspaceUpdate = () => null; + + vm.runtime.targets = [currTarget]; + t.equal(vm.runtime.targets.length, 1); + vm.duplicateSprite(currTarget.id).then(() => { + t.equal(vm.runtime.targets.length, 2); + t.equal(vm.runtime.targets[0].sprite.name, 'sprite1'); + t.equal(vm.runtime.targets[1].sprite.name, 'sprite2'); + t.end(); + }); + +}); + test('emitWorkspaceUpdate', t => { const vm = new VirtualMachine(); vm.runtime.targets = [