From 61803167d895fffb6c0e2a159ecb2899419b55df Mon Sep 17 00:00:00 2001 From: RoboErikG Date: Mon, 23 Jul 2018 10:56:37 -0700 Subject: [PATCH] Add test for deleting a rendered block with a comment (#1984) Disabled for now as it fails due to #1960. --- tests/jsunit/event_test.js | 3 +- tests/workspace_svg/event_svg_test.js | 90 +++++++++++++++++++++++++++ tests/workspace_svg/index.html | 3 + 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tests/workspace_svg/event_svg_test.js diff --git a/tests/jsunit/event_test.js b/tests/jsunit/event_test.js index 8e88d651e..e297ee939 100644 --- a/tests/jsunit/event_test.js +++ b/tests/jsunit/event_test.js @@ -191,6 +191,7 @@ function test_blockDelete_constructor() { setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']); try { var block = createSimpleTestBlock(workspace); + block.setCommentText('test comment'); var event = new Blockly.Events.BlockDelete(block); checkDeleteEventValues(event, block, ['1'], 'delete'); } finally { @@ -810,4 +811,4 @@ function test_events_filter_nomerge_move() { } finally { eventTest_tearDownWithMockBlocks(); } -} +} \ No newline at end of file diff --git a/tests/workspace_svg/event_svg_test.js b/tests/workspace_svg/event_svg_test.js new file mode 100644 index 000000000..ae1055109 --- /dev/null +++ b/tests/workspace_svg/event_svg_test.js @@ -0,0 +1,90 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +goog.require('goog.testing'); +goog.require('goog.testing.MockControl'); + +function eventSvg_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 eventSvg_tearDownMockBlocks() { + delete Blockly.Blocks['field_variable_test_block']; + delete Blockly.Blocks['simple_test_block']; + delete Blockly.Blocks['test_val_in']; +} + +function eventSvg_createWorkspaceWithToolbox() { + var toolbox = document.getElementById('toolbox-categories'); + return Blockly.inject('blocklyDiv', {toolbox: toolbox}); +} + +function eventSvg_createNewBlock(workspace, type) { + var block = workspace.newBlock(type); + block.initSvg(); + return block; +} + +function test_blockDelete_svgDispose() { + eventSvg_setUpMockBlocks(); + var workspace = eventSvg_createWorkspaceWithToolbox(); + Blockly.Events.fire = temporary_fireEvent; + temporary_fireEvent.firedEvents_ = []; + try { + var block = eventSvg_createNewBlock(workspace); + block.setCommentText('test comment'); + var event = new Blockly.Events.BlockDelete(block); + workspace.clearUndo(); + block.dispose(); + var firedEvents = workspace.undoStack_; + assertEquals('Delete event created by dispose matches constructed delete event', + Blockly.Xml.domToText(event.oldXml), Blockly.Xml.domToText(firedEvents[0].oldXml)); + } finally { + eventSvg_tearDownMockBlocks(); + workspace.dispose(); + } +} \ No newline at end of file diff --git a/tests/workspace_svg/index.html b/tests/workspace_svg/index.html index 65890169a..41d4a88e5 100644 --- a/tests/workspace_svg/index.html +++ b/tests/workspace_svg/index.html @@ -51,7 +51,10 @@ h1 {

Blockly Workspace testing

+ + +