From 1639444a4d89686264dd5f38713a723f89cbef49 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 21 May 2018 13:51:43 -0400 Subject: [PATCH] Fix lint and tests. --- src/engine/blocks.js | 2 ++ src/sprites/rendered-target.js | 3 --- test/integration/import_sb2.js | 2 -- test/unit/engine_target.js | 1 - test/unit/serialization_sb2.js | 2 -- test/unit/virtual-machine.js | 43 +++++++++++++++++++++++++++++++--- 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 360d3fe9b..e73f4b27f 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -735,6 +735,7 @@ class Blocks { /** * Encode all of `this._blocks` as an XML string usable * by a Blockly/scratch-blocks workspace. + * @param {object} comments Map of comments referenced by id * @return {string} String of XML representing this object's blocks. */ toXML (comments) { @@ -745,6 +746,7 @@ class Blocks { * Recursively encode an individual block and its children * into a Blockly/scratch-blocks XML string. * @param {!string} blockId ID of block to encode. + * @param {object} comments Map of comments referenced by id * @return {string} String of XML representing this block and any children. */ blockToXML (blockId, comments) { diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index f8a4bb1eb..b6df05e6c 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -930,7 +930,6 @@ class RenderedTarget extends Target { newClone.rotationStyle = this.rotationStyle; newClone.effects = JSON.parse(JSON.stringify(this.effects)); newClone.variables = JSON.parse(JSON.stringify(this.variables)); - newClone.lists = JSON.parse(JSON.stringify(this.lists)); newClone.initDrawable(StageLayering.SPRITE_LAYER); newClone.updateAllDrawableProperties(); // Place behind the current target. @@ -957,7 +956,6 @@ class RenderedTarget extends Target { newTarget.rotationStyle = this.rotationStyle; newTarget.effects = JSON.parse(JSON.stringify(this.effects)); newTarget.variables = JSON.parse(JSON.stringify(this.variables)); - newTarget.lists = JSON.parse(JSON.stringify(this.lists)); newTarget.updateAllDrawableProperties(); newTarget.goBehindOther(this); return newTarget; @@ -1049,7 +1047,6 @@ class RenderedTarget extends Target { rotationStyle: this.rotationStyle, blocks: this.blocks._blocks, variables: this.variables, - lists: this.lists, costumes: costumes, sounds: this.getSounds(), tempo: this.tempo, diff --git a/test/integration/import_sb2.js b/test/integration/import_sb2.js index 04c41d46a..905ce8fe0 100644 --- a/test/integration/import_sb2.js +++ b/test/integration/import_sb2.js @@ -30,7 +30,6 @@ test('default', t => { t.type(targets[0].id, 'string'); t.type(targets[0].blocks, 'object'); t.type(targets[0].variables, 'object'); - t.type(targets[0].lists, 'object'); t.equal(targets[0].isOriginal, true); t.equal(targets[0].currentCostume, 0); @@ -41,7 +40,6 @@ test('default', t => { t.type(targets[1].id, 'string'); t.type(targets[1].blocks, 'object'); t.type(targets[1].variables, 'object'); - t.type(targets[1].lists, 'object'); t.equal(targets[1].isOriginal, true); t.equal(targets[1].currentCostume, 0); diff --git a/test/unit/engine_target.js b/test/unit/engine_target.js index 30ff5eb82..df327f698 100644 --- a/test/unit/engine_target.js +++ b/test/unit/engine_target.js @@ -12,7 +12,6 @@ test('spec', t => { t.type(target.id, 'string'); t.type(target.blocks, 'object'); t.type(target.variables, 'object'); - t.type(target.lists, 'object'); t.type(target._customState, 'object'); t.type(target.createVariable, 'function'); diff --git a/test/unit/serialization_sb2.js b/test/unit/serialization_sb2.js index 4d8c906b4..e20834314 100644 --- a/test/unit/serialization_sb2.js +++ b/test/unit/serialization_sb2.js @@ -29,7 +29,6 @@ test('default', t => { t.type(targets[0].id, 'string'); t.type(targets[0].blocks, 'object'); t.type(targets[0].variables, 'object'); - t.type(targets[0].lists, 'object'); t.equal(targets[0].isOriginal, true); t.equal(targets[0].currentCostume, 0); @@ -40,7 +39,6 @@ test('default', t => { t.type(targets[1].id, 'string'); t.type(targets[1].blocks, 'object'); t.type(targets[1].variables, 'object'); - t.type(targets[1].lists, 'object'); t.equal(targets[1].isOriginal, true); t.equal(targets[1].currentCostume, 0); diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index f6731b194..70d06fee3 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -307,6 +307,17 @@ test('duplicateSprite assigns duplicated sprite a fresh name', t => { test('emitWorkspaceUpdate', t => { const vm = new VirtualMachine(); + const blocksToXML = comments => { + let blockString = 'blocks\n'; + if (comments) { + for (const commentId in comments) { + const comment = comments[commentId]; + blockString += `A Block Comment: ${comment.toXML()}`; + } + + } + return blockString; + }; vm.runtime.targets = [ { isStage: true, @@ -316,7 +327,13 @@ test('emitWorkspaceUpdate', t => { } }, blocks: { - toXML: () => 'blocks' + toXML: blocksToXML + }, + comments: { + aStageComment: { + toXML: () => 'aStageComment', + blockId: null + } } }, { variables: { @@ -325,7 +342,13 @@ test('emitWorkspaceUpdate', t => { } }, blocks: { - toXML: () => 'blocks' + toXML: blocksToXML + }, + comments: { + someBlockComment: { + toXML: () => 'someBlockComment', + blockId: 'someBlockId' + } } }, { variables: { @@ -334,7 +357,17 @@ test('emitWorkspaceUpdate', t => { } }, blocks: { - toXML: () => 'blocks' + toXML: blocksToXML + }, + comments: { + someOtherComment: { + toXML: () => 'someOtherComment', + blockId: null + }, + aBlockComment: { + toXML: () => 'aBlockComment', + blockId: 'a block' + } } } ]; @@ -347,6 +380,10 @@ test('emitWorkspaceUpdate', t => { t.notEqual(xml.indexOf('local'), -1); t.equal(xml.indexOf('unused'), -1); t.notEqual(xml.indexOf('blocks'), -1); + t.equal(xml.indexOf('aStageComment'), -1); + t.equal(xml.indexOf('someBlockComment'), -1); + t.notEqual(xml.indexOf('someOtherComment'), -1); + t.notEqual(xml.indexOf('A Block Comment: aBlockComment'), -1); t.end(); });