mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-04 18:20:24 -04:00
Add unit test for inline image in extension block. Update internal-extension integration test.
This commit is contained in:
parent
6afbe192d8
commit
ebb3f29734
2 changed files with 43 additions and 2 deletions
test
|
@ -101,13 +101,16 @@ test('load sync', t => {
|
||||||
t.equal(vm.runtime._blockInfo.length, 1);
|
t.equal(vm.runtime._blockInfo.length, 1);
|
||||||
|
|
||||||
// blocks should be an array of two items: a button pseudo-block and a reporter block.
|
// blocks should be an array of two items: a button pseudo-block and a reporter block.
|
||||||
t.equal(vm.runtime._blockInfo[0].blocks.length, 2);
|
t.equal(vm.runtime._blockInfo[0].blocks.length, 3);
|
||||||
t.type(vm.runtime._blockInfo[0].blocks[0].info, 'object');
|
t.type(vm.runtime._blockInfo[0].blocks[0].info, 'object');
|
||||||
t.type(vm.runtime._blockInfo[0].blocks[0].info.func, 'MAKE_A_VARIABLE');
|
t.type(vm.runtime._blockInfo[0].blocks[0].info.func, 'MAKE_A_VARIABLE');
|
||||||
t.equal(vm.runtime._blockInfo[0].blocks[0].info.blockType, 'button');
|
t.equal(vm.runtime._blockInfo[0].blocks[0].info.blockType, 'button');
|
||||||
t.type(vm.runtime._blockInfo[0].blocks[1].info, 'object');
|
t.type(vm.runtime._blockInfo[0].blocks[1].info, 'object');
|
||||||
t.equal(vm.runtime._blockInfo[0].blocks[1].info.opcode, 'exampleOpcode');
|
t.equal(vm.runtime._blockInfo[0].blocks[1].info.opcode, 'exampleOpcode');
|
||||||
t.equal(vm.runtime._blockInfo[0].blocks[1].info.blockType, 'reporter');
|
t.equal(vm.runtime._blockInfo[0].blocks[1].info.blockType, 'reporter');
|
||||||
|
t.type(vm.runtime._blockInfo[0].blocks[2].info, 'object');
|
||||||
|
t.equal(vm.runtime._blockInfo[0].blocks[2].info.opcode, 'exampleWithInlineImage');
|
||||||
|
t.equal(vm.runtime._blockInfo[0].blocks[2].info.blockType, 'command');
|
||||||
|
|
||||||
// Test the opcode function
|
// Test the opcode function
|
||||||
t.equal(vm.runtime._blockInfo[0].blocks[1].info.func(), 'no stage yet');
|
t.equal(vm.runtime._blockInfo[0].blocks[1].info.func(), 'no stage yet');
|
||||||
|
|
|
@ -26,6 +26,17 @@ const testExtensionInfo = {
|
||||||
text: 'simple text',
|
text: 'simple text',
|
||||||
blockIconURI: 'invalid icon URI' // trigger the 'scratch_extension' path
|
blockIconURI: 'invalid icon URI' // trigger the 'scratch_extension' path
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
opcode: 'inlineImage',
|
||||||
|
blockType: BlockType.REPORTER,
|
||||||
|
text: 'text and [IMAGE]',
|
||||||
|
arguments: {
|
||||||
|
IMAGE: {
|
||||||
|
type: ArgumentType.IMAGE,
|
||||||
|
dataURI: 'invalid image URI'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
'---', // separator between groups of blocks in an extension
|
'---', // separator between groups of blocks in an extension
|
||||||
{
|
{
|
||||||
opcode: 'command',
|
opcode: 'command',
|
||||||
|
@ -108,6 +119,32 @@ const testReporter = function (t, reporter) {
|
||||||
t.equal(reporter.xml, '<block type="test_reporter"></block>');
|
t.equal(reporter.xml, '<block type="test_reporter"></block>');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const testInlineImage = function (t, inlineImage) {
|
||||||
|
t.equal(inlineImage.json.type, 'test_inlineImage');
|
||||||
|
testCategoryInfo(t, inlineImage);
|
||||||
|
t.equal(inlineImage.json.checkboxInFlyout, true);
|
||||||
|
t.equal(inlineImage.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_ROUND);
|
||||||
|
t.equal(inlineImage.json.output, 'String');
|
||||||
|
t.notOk(inlineImage.json.hasOwnProperty('previousStatement'));
|
||||||
|
t.notOk(inlineImage.json.hasOwnProperty('nextStatement'));
|
||||||
|
t.notOk(inlineImage.json.extensions && inlineImage.json.extensions.length); // OK if it's absent or empty
|
||||||
|
t.equal(inlineImage.json.message0, 'text and %1'); // block text followed by inline image
|
||||||
|
t.notOk(inlineImage.json.hasOwnProperty('message1'));
|
||||||
|
t.same(inlineImage.json.args0, [
|
||||||
|
// %1 in message0: the block icon
|
||||||
|
{
|
||||||
|
type: 'field_image',
|
||||||
|
src: 'invalid image URI',
|
||||||
|
alt: '', // Empty because not specified
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
flip_rtl: false // False by default
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
t.notOk(inlineImage.json.hasOwnProperty('args1'));
|
||||||
|
t.equal(inlineImage.xml, '<block type="test_inlineImage"></block>');
|
||||||
|
};
|
||||||
|
|
||||||
const testSeparator = function (t, separator) {
|
const testSeparator = function (t, separator) {
|
||||||
t.same(separator.json, null); // should be null or undefined
|
t.same(separator.json, null); // should be null or undefined
|
||||||
t.equal(separator.xml, '<sep gap="36"/>');
|
t.equal(separator.xml, '<sep gap="36"/>');
|
||||||
|
@ -203,10 +240,11 @@ test('registerExtensionPrimitives', t => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Note that this also implicitly tests that block order is preserved
|
// Note that this also implicitly tests that block order is preserved
|
||||||
const [button, reporter, separator, command, conditional, loop] = blocksInfo;
|
const [button, reporter, inlineImage, separator, command, conditional, loop] = blocksInfo;
|
||||||
|
|
||||||
testButton(t, button);
|
testButton(t, button);
|
||||||
testReporter(t, reporter);
|
testReporter(t, reporter);
|
||||||
|
testInlineImage(t, inlineImage);
|
||||||
testSeparator(t, separator);
|
testSeparator(t, separator);
|
||||||
testCommand(t, command);
|
testCommand(t, command);
|
||||||
testConditional(t, conditional);
|
testConditional(t, conditional);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue