diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 1393ee26913..adfffa78cf4 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1408,13 +1408,13 @@ class Runtime extends EventEmitter { if (!blockInfo.disableMonitor && context.inputList.length === 0) { blockJSON.checkboxInFlyout = true; } - } else if (blockInfo.blockType === BlockType.LOOP) { + } else if (blockInfo.blockType === BlockType.LOOP || blockInfo.branchIconURI) { // Add icon to the bottom right of a loop block blockJSON[`lastDummyAlign${outLineNum}`] = 'RIGHT'; blockJSON[`message${outLineNum}`] = '%1'; blockJSON[`args${outLineNum}`] = [{ type: 'field_image', - src: './static/blocks-media/repeat.svg', // TODO: use a constant or make this configurable? + src: blockInfo.branchIconURI || './static/blocks-media/repeat.svg', width: 24, height: 24, alt: '*', // TODO remove this since we don't use collapsed blocks in scratch diff --git a/test/unit/tw_branch_icon_uri.js b/test/unit/tw_branch_icon_uri.js new file mode 100644 index 00000000000..2de54dab606 --- /dev/null +++ b/test/unit/tw_branch_icon_uri.js @@ -0,0 +1,39 @@ +const {test} = require('tap'); +const VirtualMachine = require('../../src/virtual-machine'); +const BlockType = require('../../src/extension-support/block-type'); + +test('branchIconURI', t => { + const vm = new VirtualMachine(); + vm.extensionManager._registerInternalExtension({ + getInfo: () => ({ + id: 'testextension', + name: 'test', + blocks: [ + { + blockType: BlockType.LOOP, + opcode: 'block1', + text: 'no custom icon' + }, + { + blockType: BlockType.LOOP, + opcode: 'block2', + text: 'LOOP with custom icon', + branchIconURI: 'data:whatever1' + }, + { + blockType: BlockType.CONDITIONAL, + opcode: 'block2', + text: 'CONDITIONAL with custom icon', + branchIconURI: 'data:whatever2' + } + ] + }) + }); + + const blocks = vm.runtime.getBlocksJSON(); + t.equal(blocks[0].args2[0].src, './static/blocks-media/repeat.svg', 'default custom icon'); + t.equal(blocks[1].args2[0].src, 'data:whatever1', 'LOOP with custom icon'); + t.equal(blocks[2].args2[0].src, 'data:whatever2', 'CONDITIONAL with custom icon'); + + t.end(); +});