diff --git a/test/fixtures/events.json b/test/fixtures/events.json index a5a126f07..dbddd2777 100644 --- a/test/fixtures/events.json +++ b/test/fixtures/events.json @@ -90,5 +90,17 @@ "type": "comment_create", "commentId": "a comment", "xy": {"x": 10, "y": 20} + }, + "mockVariableBlock": { + "name": "block", + "xml": { + "outerHTML": "a mock variable" + } + }, + "mockListBlock": { + "name": "block", + "xml": { + "outerHTML": "a mock list" + } } } diff --git a/test/unit/engine_blocks.js b/test/unit/engine_blocks.js index 08b0b414e..5659b6878 100644 --- a/test/unit/engine_blocks.js +++ b/test/unit/engine_blocks.js @@ -1,5 +1,8 @@ const test = require('tap').test; const Blocks = require('../../src/engine/blocks'); +const Variable = require('../../src/engine/variable'); +const adapter = require('../../src/engine/adapter'); +const events = require('../fixtures/events.json'); test('spec', t => { const b = new Blocks(); @@ -776,3 +779,32 @@ test('updateTargetSpecificBlocks changes sprite clicked hat to stage clicked for t.end(); }); + +test('getAllVariableAndListReferences returns an empty map references when variable blocks do not exist', t => { + const b = new Blocks(); + t.equal(Object.keys(b.getAllVariableAndListReferences()).length, 0); + t.end(); +}); + +test('getAllVariableAndListReferences returns references when variable blocks exist', t => { + const b = new Blocks(); + + let varListRefs = b.getAllVariableAndListReferences(); + t.equal(Object.keys(varListRefs).length, 0); + + b.createBlock(adapter(events.mockVariableBlock)[0]); + b.createBlock(adapter(events.mockListBlock)[0]); + + varListRefs = b.getAllVariableAndListReferences(); + t.equal(Object.keys(varListRefs).length, 2); + t.equal(Array.isArray(varListRefs['mock var id']), true); + t.equal(varListRefs['mock var id'].length, 1); + t.equal(varListRefs['mock var id'][0].type, Variable.SCALAR_TYPE); + t.equal(varListRefs['mock var id'][0].referencingField.value, 'a mock variable'); + t.equal(Array.isArray(varListRefs['mock list id']), true); + t.equal(varListRefs['mock list id'].length, 1); + t.equal(varListRefs['mock list id'][0].type, Variable.LIST_TYPE); + t.equal(varListRefs['mock list id'][0].referencingField.value, 'a mock list'); + + t.end(); +});