Update unit tests for new adapter, blocks module

This commit is contained in:
Tim Mickel 2016-06-06 15:59:21 -04:00
parent feea7a0566
commit 7732409102
3 changed files with 118 additions and 82 deletions

View file

@ -10,11 +10,27 @@ test('spec', function (t) {
test('create event', function (t) {
var result = adapter(events.create);
t.type(result, 'object');
t.type(result.id, 'string');
t.type(result.opcode, 'string');
t.type(result.fields, 'object');
t.type(result.fields['DURATION'], 'object');
t.ok(Array.isArray(result));
t.equal(result.length, 2);
// Outer block
t.type(result[0].id, 'string');
t.type(result[0].opcode, 'string');
t.type(result[0].fields, 'object');
t.type(result[0].inputs, 'object');
t.type(result[0].inputs['DURATION'], 'object');
t.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true);
// Enclosed shadow block
t.type(result[1].id, 'string');
t.type(result[1].opcode, 'string');
t.type(result[1].fields, 'object');
t.type(result[1].inputs, 'object');
t.type(result[1].fields['NUM'], 'object');
t.type(result[1].fields['NUM'].value, '10');
t.type(result[1].topLevel, 'boolean');
t.equal(result[1].topLevel, false);
t.end();
});

97
test/unit/blocks.js Normal file
View file

@ -0,0 +1,97 @@
var test = require('tap').test;
var Blocks = require('../../src/engine/Blocks');
test('spec', function (t) {
var b = new Blocks();
t.type(Blocks, 'function');
t.type(b, 'object');
t.ok(b instanceof Blocks);
t.type(b._blocks, 'object');
t.type(b._stacks, 'object');
t.ok(Array.isArray(b._stacks));
t.type(b.createBlock, 'function');
t.type(b.moveBlock, 'function');
t.type(b.changeBlock, 'function');
t.type(b.deleteBlock, 'function');
t.end();
});
test('create', function (t) {
var b = new Blocks();
b.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {},
inputs: {},
topLevel: true
});
t.type(b._blocks['foo'], 'object');
t.equal(b._blocks['foo'].opcode, 'TEST_BLOCK');
t.notEqual(b._stacks.indexOf('foo'), -1);
t.end();
});
test('move', function (t) {
var b = new Blocks();
b.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {},
inputs: {},
topLevel: true
});
b.createBlock({
id: 'bar',
opcode: 'TEST_BLOCK',
next: null,
fields: {},
inputs: {},
topLevel: true
});
// Attach 'bar' to the end of 'foo'
b.moveBlock({
id: 'bar',
newParent: 'foo'
});
t.equal(b._stacks.length, 1);
t.equal(Object.keys(b._blocks).length, 2);
t.equal(b._blocks['foo'].next, 'bar');
// Detach 'bar' from 'foo'
b.moveBlock({
id: 'bar',
oldParent: 'foo'
});
t.equal(b._stacks.length, 2);
t.equal(Object.keys(b._blocks).length, 2);
t.equal(b._blocks['foo'].next, null);
t.end();
});
test('delete', function (t) {
var b = new Blocks();
b.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {},
inputs: {},
topLevel: true
});
b.deleteBlock({
id: 'foo'
});
t.type(b._blocks['foo'], 'undefined');
t.equal(b._stacks.indexOf('foo'), -1);
t.end();
});

View file

@ -8,82 +8,5 @@ test('spec', function (t) {
t.type(r, 'object');
t.ok(r instanceof Runtime);
t.type(r.blocks, 'object');
t.type(r.stacks, 'object');
t.ok(Array.isArray(r.stacks));
t.type(r.createBlock, 'function');
t.type(r.moveBlock, 'function');
t.type(r.changeBlock, 'function');
t.type(r.deleteBlock, 'function');
t.end();
});
test('create', function (t) {
var r = new Runtime();
r.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {}
});
t.type(r.blocks['foo'], 'object');
t.equal(r.blocks['foo'].opcode, 'TEST_BLOCK');
t.notEqual(r.stacks.indexOf('foo'), -1);
t.end();
});
test('move', function (t) {
var r = new Runtime();
r.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {}
});
r.createBlock({
id: 'bar',
opcode: 'TEST_BLOCK',
next: null,
fields: {}
});
// Attach 'bar' to the end of 'foo'
r.moveBlock({
id: 'bar',
newParent: 'foo'
});
t.equal(r.stacks.length, 1);
t.equal(Object.keys(r.blocks).length, 2);
t.equal(r.blocks['foo'].next, 'bar');
// Detach 'bar' from 'foo'
r.moveBlock({
id: 'bar',
oldParent: 'foo'
});
t.equal(r.stacks.length, 2);
t.equal(Object.keys(r.blocks).length, 2);
t.equal(r.blocks['foo'].next, null);
t.end();
});
test('delete', function (t) {
var r = new Runtime();
r.createBlock({
id: 'foo',
opcode: 'TEST_BLOCK',
next: null,
fields: {}
});
r.deleteBlock({
id: 'foo'
});
t.type(r.blocks['foo'], 'undefined');
t.equal(r.stacks.indexOf('foo'), -1);
t.end();
});