Add a test for 'getAllVariableAndListReferences' function.

This commit is contained in:
Karishma Chadha 2018-06-20 10:32:36 -04:00
parent 9646e3d11e
commit 073bb37c30
2 changed files with 44 additions and 0 deletions

View file

@ -90,5 +90,17 @@
"type": "comment_create",
"commentId": "a comment",
"xy": {"x": 10, "y": 20}
},
"mockVariableBlock": {
"name": "block",
"xml": {
"outerHTML": "<block type='data_variable' id='a block' x='0' y='0'><field name='VARIABLE' id='mock var id' variabletype=''>a mock variable</field></block>"
}
},
"mockListBlock": {
"name": "block",
"xml": {
"outerHTML": "<block type='data_listcontents' id='another block' x='0' y='0'><field name='LIST' id='mock list id' variabletype=''>a mock list</field></block>"
}
}
}

View file

@ -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();
});