Convert event svg tests to mocha. (#3864)

This commit is contained in:
Monica Kozbial
2020-04-29 11:16:45 -07:00
committed by GitHub
parent e516a08430
commit c35793bf9c
3 changed files with 25 additions and 75 deletions

View File

@@ -574,6 +574,31 @@ suite('Events', function() {
sinon.restore();
});
test('Block dispose triggers BlockDelete', function() {
try {
var toolbox = document.getElementById('toolbox-categories');
var workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
temporary_fireEvent.firedEvents_ = [];
var block = workspaceSvg.newBlock('');
block.initSvg();
block.setCommentText('test comment');
var event = new Blockly.Events.BlockDelete(block);
workspaceSvg.clearUndo();
block.dispose();
var firedEvents = workspaceSvg.undoStack_;
chai.assert.equal(
Blockly.Xml.domToText(firedEvents[0].oldXml),
Blockly.Xml.domToText(event.oldXml),
'Delete event created by dispose');
} finally {
workspaceSvg.dispose();
}
});
test('New block new var', function() {
// Expect three calls to genUid: one to set the block's ID, one for the event
// group's id, and one for the variable's ID.

View File

@@ -1,74 +0,0 @@
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
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();
}
}

View File

@@ -58,7 +58,6 @@ h1 {
<script src="../jsunit/test_utilities.js"></script>
<script src="procedure_svg_test.js"></script>
<script src="event_svg_test.js"></script>
<script src="../jsunit/mocha_jsunit_test_runner.js"></script>