Merge pull request #931 from kchadha/bugfix-912

Renaming sprite/costume/sound/backdrop updates corresponding blocks.
This commit is contained in:
kchadha 2018-02-12 11:53:50 -05:00 committed by GitHub
commit 9675a1b8cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 358 additions and 27 deletions

View file

@ -538,3 +538,211 @@ test('delete inputs', t => {
t.equal(b._scripts.length, 0);
t.end();
});
test('updateAssetName function updates name in sound field', t => {
const b = new Blocks();
b.createBlock({
id: 'foo',
fields: {
SOUND_MENU: {
name: 'SOUND_MENU',
value: 'name1'
}
}
});
t.equals(b.getBlock('foo').fields.SOUND_MENU.value, 'name1');
b.updateAssetName('name1', 'name2', 'sound');
t.equals(b.getBlock('foo').fields.SOUND_MENU.value, 'name2');
t.end();
});
test('updateAssetName function updates name in costume field', t => {
const b = new Blocks();
b.createBlock({
id: 'foo',
fields: {
COSTUME: {
name: 'COSTUME',
value: 'name1'
}
}
});
t.equals(b.getBlock('foo').fields.COSTUME.value, 'name1');
b.updateAssetName('name1', 'name2', 'costume');
t.equals(b.getBlock('foo').fields.COSTUME.value, 'name2');
t.end();
});
test('updateAssetName function updates name in backdrop field', t => {
const b = new Blocks();
b.createBlock({
id: 'foo',
fields: {
BACKDROP: {
name: 'BACKDROP',
value: 'name1'
}
}
});
t.equals(b.getBlock('foo').fields.BACKDROP.value, 'name1');
b.updateAssetName('name1', 'name2', 'backdrop');
t.equals(b.getBlock('foo').fields.BACKDROP.value, 'name2');
t.end();
});
test('updateAssetName function updates name in all sprite fields', t => {
const b = new Blocks();
b.createBlock({
id: 'id1',
fields: {
TOWARDS: {
name: 'TOWARDS',
value: 'name1'
}
}
});
b.createBlock({
id: 'id2',
fields: {
TO: {
name: 'TO',
value: 'name1'
}
}
});
b.createBlock({
id: 'id3',
fields: {
OBJECT: {
name: 'OBJECT',
value: 'name1'
}
}
});
b.createBlock({
id: 'id4',
fields: {
VIDEOONMENU2: {
name: 'VIDEOONMENU2',
value: 'name1'
}
}
});
b.createBlock({
id: 'id5',
fields: {
DISTANCETOMENU: {
name: 'DISTANCETOMENU',
value: 'name1'
}
}
});
b.createBlock({
id: 'id6',
fields: {
TOUCHINGOBJECTMENU: {
name: 'TOUCHINGOBJECTMENU',
value: 'name1'
}
}
});
b.createBlock({
id: 'id7',
fields: {
CLONE_OPTION: {
name: 'CLONE_OPTION',
value: 'name1'
}
}
});
t.equals(b.getBlock('id1').fields.TOWARDS.value, 'name1');
t.equals(b.getBlock('id2').fields.TO.value, 'name1');
t.equals(b.getBlock('id3').fields.OBJECT.value, 'name1');
t.equals(b.getBlock('id4').fields.VIDEOONMENU2.value, 'name1');
t.equals(b.getBlock('id5').fields.DISTANCETOMENU.value, 'name1');
t.equals(b.getBlock('id6').fields.TOUCHINGOBJECTMENU.value, 'name1');
t.equals(b.getBlock('id7').fields.CLONE_OPTION.value, 'name1');
b.updateAssetName('name1', 'name2', 'sprite');
t.equals(b.getBlock('id1').fields.TOWARDS.value, 'name2');
t.equals(b.getBlock('id2').fields.TO.value, 'name2');
t.equals(b.getBlock('id3').fields.OBJECT.value, 'name2');
t.equals(b.getBlock('id4').fields.VIDEOONMENU2.value, 'name2');
t.equals(b.getBlock('id5').fields.DISTANCETOMENU.value, 'name2');
t.equals(b.getBlock('id6').fields.TOUCHINGOBJECTMENU.value, 'name2');
t.equals(b.getBlock('id7').fields.CLONE_OPTION.value, 'name2');
t.end();
});
test('updateAssetName function updates name according to asset type', t => {
const b = new Blocks();
b.createBlock({
id: 'id1',
fields: {
SOUND_MENU: {
name: 'SOUND_MENU',
value: 'name1'
}
}
});
b.createBlock({
id: 'id2',
fields: {
COSTUME: {
name: 'COSTUME',
value: 'name1'
}
}
});
t.equals(b.getBlock('id1').fields.SOUND_MENU.value, 'name1');
t.equals(b.getBlock('id2').fields.COSTUME.value, 'name1');
b.updateAssetName('name1', 'name2', 'sound');
// only sound should get renamed
t.equals(b.getBlock('id1').fields.SOUND_MENU.value, 'name2');
t.equals(b.getBlock('id2').fields.COSTUME.value, 'name1');
t.end();
});
test('updateAssetName only updates given name', t => {
const b = new Blocks();
b.createBlock({
id: 'id1',
fields: {
COSTUME: {
name: 'COSTUME',
value: 'name1'
}
}
});
b.createBlock({
id: 'id2',
fields: {
COSTUME: {
name: 'COSTUME',
value: 'foo'
}
}
});
t.equals(b.getBlock('id1').fields.COSTUME.value, 'name1');
t.equals(b.getBlock('id2').fields.COSTUME.value, 'foo');
b.updateAssetName('name1', 'name2', 'costume');
t.equals(b.getBlock('id1').fields.COSTUME.value, 'name2');
t.equals(b.getBlock('id2').fields.COSTUME.value, 'foo');
t.end();
});
test('updateAssetName doesn\'t update name if name isn\'t being used', t => {
const b = new Blocks();
b.createBlock({
id: 'id1',
fields: {
BACKDROP: {
name: 'BACKDROP',
value: 'foo'
}
}
});
t.equals(b.getBlock('id1').fields.BACKDROP.value, 'foo');
b.updateAssetName('name1', 'name2', 'backdrop');
t.equals(b.getBlock('id1').fields.BACKDROP.value, 'foo');
t.end();
});

View file

@ -78,36 +78,34 @@ test('renameSprite does not set sprite names to reserved names', t => {
test('renameSprite increments from existing sprite names', t => {
const vm = new VirtualMachine();
vm.emitTargetsUpdate = () => {};
vm.runtime.targets = [{
id: 'id1',
isSprite: () => true,
sprite: {
name: 'this name'
}
}, {
id: 'id2',
isSprite: () => true,
sprite: {
name: 'that name'
}
}];
vm.renameSprite('id1', 'that name');
t.equal(vm.runtime.targets[0].sprite.name, 'that name2');
const spr1 = new Sprite(null, vm.runtime);
const target1 = spr1.createClone();
const spr2 = new Sprite(null, vm.runtime);
const target2 = spr2.createClone();
vm.runtime.targets = [target1, target2];
vm.renameSprite(target1.id, 'foo');
t.equal(vm.runtime.targets[0].sprite.name, 'foo');
vm.renameSprite(target2.id, 'foo');
t.equal(vm.runtime.targets[1].sprite.name, 'foo2');
t.end();
});
test('renameSprite does not increment when renaming to the same name', t => {
const vm = new VirtualMachine();
vm.emitTargetsUpdate = () => {};
vm.runtime.targets = [{
id: 'id1',
isSprite: () => true,
sprite: {
name: 'this name'
}
}];
vm.renameSprite('id1', 'this name');
t.equal(vm.runtime.targets[0].sprite.name, 'this name');
const spr = new Sprite(null, vm.runtime);
spr.name = 'foo';
const target = spr.createClone();
vm.runtime.targets = [target];
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();
});