mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-03 17:50:28 -04:00
add tests for new e16n support features
This commit is contained in:
parent
de8ef1224a
commit
ab715901a6
3 changed files with 82 additions and 4 deletions
|
@ -25,7 +25,7 @@ test('spec', t => {
|
||||||
t.type(b.getNextBlock, 'function');
|
t.type(b.getNextBlock, 'function');
|
||||||
t.type(b.getBranch, 'function');
|
t.type(b.getBranch, 'function');
|
||||||
t.type(b.getOpcode, 'function');
|
t.type(b.getOpcode, 'function');
|
||||||
|
t.type(b.mutationToXML, 'function');
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -239,6 +239,25 @@ test('getOpcode', t => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('mutationToXML', t => {
|
||||||
|
const b = new Blocks(new Runtime());
|
||||||
|
const testStringRaw = '"arbitrary" & \'complicated\' test string';
|
||||||
|
const testStringEscaped = '\\"arbitrary\\" & 'complicated' test string';
|
||||||
|
const mutation = {
|
||||||
|
tagName: 'mutation',
|
||||||
|
children: [],
|
||||||
|
blockInfo: {
|
||||||
|
text: testStringRaw
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const xml = b.mutationToXML(mutation);
|
||||||
|
t.equals(
|
||||||
|
xml,
|
||||||
|
`<mutation blockInfo="{"text":"${testStringEscaped}"}"></mutation>`
|
||||||
|
);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
// Block events tests
|
// Block events tests
|
||||||
test('create', t => {
|
test('create', t => {
|
||||||
const b = new Blocks(new Runtime());
|
const b = new Blocks(new Runtime());
|
||||||
|
|
26
test/unit/engine_mutation-adapter.js
Normal file
26
test/unit/engine_mutation-adapter.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const test = require('tap').test;
|
||||||
|
|
||||||
|
const mutationAdapter = require('../../src/engine/mutation-adapter');
|
||||||
|
|
||||||
|
test('spec', t => {
|
||||||
|
t.type(mutationAdapter, 'function');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert DOM to Scratch object', t => {
|
||||||
|
const testStringRaw = '"arbitrary" & \'complicated\' test string';
|
||||||
|
const testStringEscaped = '\\"arbitrary\\" & 'complicated' test string';
|
||||||
|
const xml = `<mutation blockInfo="{"text":"${testStringEscaped}"}"></mutation>`;
|
||||||
|
const expectedMutation = {
|
||||||
|
tagName: 'mutation',
|
||||||
|
children: [],
|
||||||
|
blockInfo: {
|
||||||
|
text: testStringRaw
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: do we want to test passing a DOM node to `mutationAdapter`? Node.js doesn't have built-in DOM support...
|
||||||
|
const mutationFromString = mutationAdapter(xml);
|
||||||
|
t.deepEqual(mutationFromString, expectedMutation);
|
||||||
|
t.end();
|
||||||
|
});
|
|
@ -11,6 +11,9 @@ const ScratchBlocksConstants = require('../../src/engine/scratch-blocks-constant
|
||||||
const testExtensionInfo = {
|
const testExtensionInfo = {
|
||||||
id: 'test',
|
id: 'test',
|
||||||
name: 'fake test extension',
|
name: 'fake test extension',
|
||||||
|
color1: '#111111',
|
||||||
|
color2: '#222222',
|
||||||
|
color3: '#333333',
|
||||||
blocks: [
|
blocks: [
|
||||||
{
|
{
|
||||||
func: 'MAKE_A_VARIABLE',
|
func: 'MAKE_A_VARIABLE',
|
||||||
|
@ -20,7 +23,8 @@ const testExtensionInfo = {
|
||||||
{
|
{
|
||||||
opcode: 'reporter',
|
opcode: 'reporter',
|
||||||
blockType: BlockType.REPORTER,
|
blockType: BlockType.REPORTER,
|
||||||
text: 'simple text'
|
text: 'simple text',
|
||||||
|
blockIconURI: 'invalid icon URI' // trigger the 'scratch_extension' path
|
||||||
},
|
},
|
||||||
'---', // separator between groups of blocks in an extension
|
'---', // separator between groups of blocks in an extension
|
||||||
{
|
{
|
||||||
|
@ -63,6 +67,14 @@ const testExtensionInfo = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const testCategoryInfo = function (t, block) {
|
||||||
|
t.equal(block.json.category, 'fake test extension');
|
||||||
|
t.equal(block.json.colour, '#111111');
|
||||||
|
t.equal(block.json.colourSecondary, '#222222');
|
||||||
|
t.equal(block.json.colourTertiary, '#333333');
|
||||||
|
t.equal(block.json.inputsInline, true);
|
||||||
|
};
|
||||||
|
|
||||||
const testButton = function (t, button) {
|
const testButton = function (t, button) {
|
||||||
t.same(button.json, null); // should be null or undefined
|
t.same(button.json, null); // should be null or undefined
|
||||||
t.equal(button.xml, '<button text="this is a button" callbackKey="MAKE_A_VARIABLE"></button>');
|
t.equal(button.xml, '<button text="this is a button" callbackKey="MAKE_A_VARIABLE"></button>');
|
||||||
|
@ -70,13 +82,28 @@ const testButton = function (t, button) {
|
||||||
|
|
||||||
const testReporter = function (t, reporter) {
|
const testReporter = function (t, reporter) {
|
||||||
t.equal(reporter.json.type, 'test_reporter');
|
t.equal(reporter.json.type, 'test_reporter');
|
||||||
|
testCategoryInfo(t, reporter);
|
||||||
|
t.equal(reporter.json.checkboxInFlyout, true);
|
||||||
t.equal(reporter.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_ROUND);
|
t.equal(reporter.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_ROUND);
|
||||||
t.equal(reporter.json.output, 'String');
|
t.equal(reporter.json.output, 'String');
|
||||||
t.notOk(reporter.json.hasOwnProperty('previousStatement'));
|
t.notOk(reporter.json.hasOwnProperty('previousStatement'));
|
||||||
t.notOk(reporter.json.hasOwnProperty('nextStatement'));
|
t.notOk(reporter.json.hasOwnProperty('nextStatement'));
|
||||||
t.equal(reporter.json.message0, 'simple text');
|
t.same(reporter.json.extensions, ['scratch_extension']);
|
||||||
|
t.equal(reporter.json.message0, '%1 %2simple text'); // "%1 %2" from the block icon
|
||||||
t.notOk(reporter.json.hasOwnProperty('message1'));
|
t.notOk(reporter.json.hasOwnProperty('message1'));
|
||||||
t.notOk(reporter.json.hasOwnProperty('args0'));
|
t.same(reporter.json.args0, [
|
||||||
|
// %1 in message0: the block icon
|
||||||
|
{
|
||||||
|
type: 'field_image',
|
||||||
|
src: 'invalid icon URI',
|
||||||
|
width: 40,
|
||||||
|
height: 40
|
||||||
|
},
|
||||||
|
// %2 in message0: separator between icon and text (only added when there's also an icon)
|
||||||
|
{
|
||||||
|
type: 'field_vertical_separator'
|
||||||
|
}
|
||||||
|
]);
|
||||||
t.notOk(reporter.json.hasOwnProperty('args1'));
|
t.notOk(reporter.json.hasOwnProperty('args1'));
|
||||||
t.equal(reporter.xml, '<block type="test_reporter"></block>');
|
t.equal(reporter.xml, '<block type="test_reporter"></block>');
|
||||||
};
|
};
|
||||||
|
@ -88,9 +115,11 @@ const testSeparator = function (t, separator) {
|
||||||
|
|
||||||
const testCommand = function (t, command) {
|
const testCommand = function (t, command) {
|
||||||
t.equal(command.json.type, 'test_command');
|
t.equal(command.json.type, 'test_command');
|
||||||
|
testCategoryInfo(t, command);
|
||||||
t.equal(command.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
t.equal(command.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||||
t.assert(command.json.hasOwnProperty('previousStatement'));
|
t.assert(command.json.hasOwnProperty('previousStatement'));
|
||||||
t.assert(command.json.hasOwnProperty('nextStatement'));
|
t.assert(command.json.hasOwnProperty('nextStatement'));
|
||||||
|
t.notOk(command.json.extensions && command.json.extensions.length); // OK if it's absent or empty
|
||||||
t.equal(command.json.message0, 'text with %1');
|
t.equal(command.json.message0, 'text with %1');
|
||||||
t.notOk(command.json.hasOwnProperty('message1'));
|
t.notOk(command.json.hasOwnProperty('message1'));
|
||||||
t.strictSame(command.json.args0[0], {
|
t.strictSame(command.json.args0[0], {
|
||||||
|
@ -105,9 +134,11 @@ const testCommand = function (t, command) {
|
||||||
|
|
||||||
const testConditional = function (t, conditional) {
|
const testConditional = function (t, conditional) {
|
||||||
t.equal(conditional.json.type, 'test_ifElse');
|
t.equal(conditional.json.type, 'test_ifElse');
|
||||||
|
testCategoryInfo(t, conditional);
|
||||||
t.equal(conditional.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
t.equal(conditional.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||||
t.ok(conditional.json.hasOwnProperty('previousStatement'));
|
t.ok(conditional.json.hasOwnProperty('previousStatement'));
|
||||||
t.ok(conditional.json.hasOwnProperty('nextStatement'));
|
t.ok(conditional.json.hasOwnProperty('nextStatement'));
|
||||||
|
t.notOk(conditional.json.extensions && conditional.json.extensions.length); // OK if it's absent or empty
|
||||||
t.equal(conditional.json.message0, 'test if %1 is spiffy and if so then');
|
t.equal(conditional.json.message0, 'test if %1 is spiffy and if so then');
|
||||||
t.equal(conditional.json.message1, '%1'); // placeholder for substack #1
|
t.equal(conditional.json.message1, '%1'); // placeholder for substack #1
|
||||||
t.equal(conditional.json.message2, 'or elsewise');
|
t.equal(conditional.json.message2, 'or elsewise');
|
||||||
|
@ -133,9 +164,11 @@ const testConditional = function (t, conditional) {
|
||||||
|
|
||||||
const testLoop = function (t, loop) {
|
const testLoop = function (t, loop) {
|
||||||
t.equal(loop.json.type, 'test_loop');
|
t.equal(loop.json.type, 'test_loop');
|
||||||
|
testCategoryInfo(t, loop);
|
||||||
t.equal(loop.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
t.equal(loop.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||||
t.ok(loop.json.hasOwnProperty('previousStatement'));
|
t.ok(loop.json.hasOwnProperty('previousStatement'));
|
||||||
t.notOk(loop.json.hasOwnProperty('nextStatement')); // isTerminal is set on this block
|
t.notOk(loop.json.hasOwnProperty('nextStatement')); // isTerminal is set on this block
|
||||||
|
t.notOk(loop.json.extensions && loop.json.extensions.length); // OK if it's absent or empty
|
||||||
t.equal(loop.json.message0, 'loopty %1 loops');
|
t.equal(loop.json.message0, 'loopty %1 loops');
|
||||||
t.equal(loop.json.message1, '%1'); // placeholder for substack
|
t.equal(loop.json.message1, '%1'); // placeholder for substack
|
||||||
t.equal(loop.json.message2, '%1'); // placeholder for loop arrow
|
t.equal(loop.json.message2, '%1'); // placeholder for loop arrow
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue