From 22fc0f8af9967d495e45a6f58cdd6cce641c451f Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Tue, 14 Aug 2018 09:52:02 -0700 Subject: [PATCH] Add test for replacing a rendered shadow block (#1981) PR #1970 created a bug that only occurred when replacing a rendered shadow block. Add a test for this case to prevent breaking it again. --- tests/workspace_svg/workspace_svg_test.js | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/workspace_svg/workspace_svg_test.js b/tests/workspace_svg/workspace_svg_test.js index 99387d797..6d88f6965 100644 --- a/tests/workspace_svg/workspace_svg_test.js +++ b/tests/workspace_svg/workspace_svg_test.js @@ -19,6 +19,42 @@ */ 'use strict'; +function helper_setUpMockBlocks() { + // TODO: Replace with defineGetVarBlock(); + Blockly.defineBlocksWithJsonArray([{ + 'type': 'field_variable_test_block', + 'message0': '%1', + 'args0': [ + { + 'type': 'field_variable', + 'name': 'VAR', + 'variable': 'item' + } + ], + }, + { + 'type': 'simple_test_block', + 'message0': 'simple test block', + 'output': null + }, + { + 'type': 'test_val_in', + 'message0': 'test in %1', + 'args0': [ + { + 'type': 'input_value', + 'name': 'NAME' + } + ] + }]); +} + +function helper_tearDownMockBlocks() { + delete Blockly.Blocks['field_variable_test_block']; + delete Blockly.Blocks['simple_test_block']; + delete Blockly.Blocks['test_val_in']; +} + function helper_createWorkspaceWithToolbox() { var toolbox = document.getElementById('toolbox-categories'); return Blockly.inject('blocklyDiv', {toolbox: toolbox}); @@ -104,3 +140,31 @@ function test_appendDomToWorkspace() { workspace.dispose(); } } + +function test_svgDisposeWithShadow() { + helper_setUpMockBlocks(); + var workspace = helper_createWorkspaceWithToolbox(); + var blockNew; + try { + var dom = Blockly.Xml.textToDom( + '' + + '' + + '' + + '' + + '' + + '' + + ''); + + Blockly.Xml.appendDomToWorkspace(dom, workspace); + assertEquals('Block count', 2, workspace.getAllBlocks().length); + var inputConnection = workspace.getTopBlocks()[0].getInput('NAME').connection; + + blockNew = helper_createNewBlock(workspace, 'simple_test_block'); + inputConnection.connect(blockNew.outputConnection); + + } finally { + workspace.dispose(); + blockNew && blockNew.dispose(); + helper_tearDownMockBlocks(); + } +}