Add unit test for inline image in extension block. Update internal-extension integration test.

This commit is contained in:
Karishma Chadha 2019-09-20 21:49:49 -07:00
parent 6afbe192d8
commit ebb3f29734
2 changed files with 43 additions and 2 deletions

View file

@ -101,13 +101,16 @@ test('load sync', t => {
t.equal(vm.runtime._blockInfo.length, 1);
// 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.func, 'MAKE_A_VARIABLE');
t.equal(vm.runtime._blockInfo[0].blocks[0].info.blockType, 'button');
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.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
t.equal(vm.runtime._blockInfo[0].blocks[1].info.func(), 'no stage yet');

View file

@ -26,6 +26,17 @@ const testExtensionInfo = {
text: 'simple text',
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
{
opcode: 'command',
@ -108,6 +119,32 @@ const testReporter = function (t, reporter) {
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) {
t.same(separator.json, null); // should be null or undefined
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
const [button, reporter, separator, command, conditional, loop] = blocksInfo;
const [button, reporter, inlineImage, separator, command, conditional, loop] = blocksInfo;
testButton(t, button);
testReporter(t, reporter);
testInlineImage(t, inlineImage);
testSeparator(t, separator);
testCommand(t, command);
testConditional(t, conditional);