Skip to content

Commit 9a50379

Browse files
authored
4 workspace files
4 workspace files for this directory, in HTML and JS formats.
1 parent f3b66d3 commit 9a50379

File tree

4 files changed

+1036
-0
lines changed

4 files changed

+1036
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @license
3+
* Blockly Tests
4+
*
5+
* Copyright 2018 Google Inc.
6+
* https://developers.google.com/blockly/
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
'use strict';
21+
22+
goog.require('goog.testing');
23+
goog.require('goog.testing.MockControl');
24+
25+
function eventSvg_setUpMockBlocks() {
26+
// TODO: Replace with defineGetVarBlock();
27+
Blockly.defineBlocksWithJsonArray([{
28+
'type': 'field_variable_test_block',
29+
'message0': '%1',
30+
'args0': [
31+
{
32+
'type': 'field_variable',
33+
'name': 'VAR',
34+
'variable': 'item'
35+
}
36+
],
37+
},
38+
{
39+
'type': 'simple_test_block',
40+
'message0': 'simple test block',
41+
'output': null
42+
},
43+
{
44+
'type': 'test_val_in',
45+
'message0': 'test in %1',
46+
'args0': [
47+
{
48+
'type': 'input_value',
49+
'name': 'NAME'
50+
}
51+
]
52+
}]);
53+
}
54+
55+
function eventSvg_tearDownMockBlocks() {
56+
delete Blockly.Blocks['field_variable_test_block'];
57+
delete Blockly.Blocks['simple_test_block'];
58+
delete Blockly.Blocks['test_val_in'];
59+
}
60+
61+
function eventSvg_createWorkspaceWithToolbox() {
62+
var toolbox = document.getElementById('toolbox-categories');
63+
return Blockly.inject('blocklyDiv', {toolbox: toolbox});
64+
}
65+
66+
function eventSvg_createNewBlock(workspace, type) {
67+
var block = workspace.newBlock(type);
68+
block.initSvg();
69+
return block;
70+
}
71+
72+
function test_blockDelete_svgDispose() {
73+
eventSvg_setUpMockBlocks();
74+
var workspace = eventSvg_createWorkspaceWithToolbox();
75+
Blockly.Events.fire = temporary_fireEvent;
76+
temporary_fireEvent.firedEvents_ = [];
77+
try {
78+
var block = eventSvg_createNewBlock(workspace);
79+
block.setCommentText('test comment');
80+
var event = new Blockly.Events.BlockDelete(block);
81+
workspace.clearUndo();
82+
block.dispose();
83+
var firedEvents = workspace.undoStack_;
84+
assertEquals('Delete event created by dispose matches constructed delete event',
85+
Blockly.Xml.domToText(event.oldXml), Blockly.Xml.domToText(firedEvents[0].oldXml));
86+
} finally {
87+
eventSvg_tearDownMockBlocks();
88+
workspace.dispose();
89+
}
90+
}

0 commit comments

Comments
 (0)