mirror of
https://github.com/google/blockly.git
synced 2026-05-13 07:30:10 +02:00
fix: create and delete events, and the trashcan (#5425)
* fix: create and delete events with JSON serialization * fix: trashcan with JSON serialization * fix: build * fix: tests * fix: PR comments * fix: types * fix: tests
This commit is contained in:
committed by
alschmiedt
parent
dfa56b7b9c
commit
0aa384dd80
+3
-3
@@ -40,8 +40,8 @@ goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.
|
||||
goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_base.js', ['Blockly.Events.BlockBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_change.js', ['Blockly.Events.BlockChange'], ['Blockly.Events', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
@@ -217,7 +217,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem']
|
||||
goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.common', 'Blockly.utils.deprecation', 'Blockly.utils.string'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.string'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.Options', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.global', 'Blockly.utils.idGenerator', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.svgPaths', 'Blockly.utils.toolbox', 'Blockly.utils.userAgent', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], ['Blockly.internalConstants'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
+3
-3
@@ -40,8 +40,8 @@ goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.
|
||||
goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_base.js', ['Blockly.Events.BlockBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_change.js', ['Blockly.Events.BlockChange'], ['Blockly.Events', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.object', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_create.js', ['Blockly.Events.BlockCreate'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_delete.js', ['Blockly.Events.BlockDelete'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.Xml', 'Blockly.registry', 'Blockly.serialization.blocks', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_block_move.js', ['Blockly.Events.BlockMove'], ['Blockly.Events', 'Blockly.Events.BlockBase', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
@@ -217,7 +217,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem']
|
||||
goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.common', 'Blockly.utils.deprecation', 'Blockly.utils.string'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.string'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.Options', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.global', 'Blockly.utils.idGenerator', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.svgPaths', 'Blockly.utils.toolbox', 'Blockly.utils.userAgent', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], ['Blockly.internalConstants'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
+96
-26
@@ -437,48 +437,118 @@ suite('Events', function() {
|
||||
viewLeft: 0, scale: 1.2, oldScale: 1})},
|
||||
];
|
||||
var blockEventTestCases = [
|
||||
{title: 'Block change', class: Blockly.Events.BlockChange,
|
||||
{
|
||||
title: 'Block change',
|
||||
class: Blockly.Events.BlockChange,
|
||||
getArgs: (thisObj) => [thisObj.block, 'collapsed', null, false, true],
|
||||
getExpectedJson: (thisObj) => ({type: 'change',
|
||||
blockId: thisObj.block.id, element: 'collapsed', oldValue: false,
|
||||
newValue: true})},
|
||||
{title: 'Block create', class: Blockly.Events.BlockCreate,
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'change',
|
||||
blockId: thisObj.block.id,
|
||||
element: 'collapsed',
|
||||
oldValue: false,
|
||||
newValue: true
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Block create',
|
||||
class: Blockly.Events.BlockCreate,
|
||||
getArgs: (thisObj) => [thisObj.block],
|
||||
getExpectedJson: (thisObj) => ({type: 'create',
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'create',
|
||||
blockId: thisObj.block.id,
|
||||
xml: '<block xmlns="https://developers.google.com/blockly/xml"' +
|
||||
' type="simple_test_block" id="testBlockId1"></block>',
|
||||
ids: [thisObj.block.id]})},
|
||||
{title: 'Block create (shadow)', class: Blockly.Events.BlockCreate,
|
||||
' type="simple_test_block" id="testBlockId1" x="0" y="0">' +
|
||||
'</block>',
|
||||
ids: [thisObj.block.id],
|
||||
json: {
|
||||
'type': 'simple_test_block',
|
||||
'id': 'testBlockId1',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
},
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Block create (shadow)',
|
||||
class: Blockly.Events.BlockCreate,
|
||||
getArgs: (thisObj) => [thisObj.shadowBlock],
|
||||
getExpectedJson: (thisObj) => ({type: 'create',
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'create',
|
||||
blockId: thisObj.shadowBlock.id,
|
||||
xml: '<shadow xmlns="https://developers.google.com/blockly/xml"' +
|
||||
' type="simple_test_block" id="testBlockId2"></shadow>',
|
||||
ids: [thisObj.shadowBlock.id], recordUndo: false})},
|
||||
{title: 'Block delete', class: Blockly.Events.BlockDelete,
|
||||
' type="simple_test_block" id="testBlockId2" x="0" y="0">' +
|
||||
'</shadow>',
|
||||
ids: [thisObj.shadowBlock.id],
|
||||
json: {
|
||||
'type': 'simple_test_block',
|
||||
'id': 'testBlockId2',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
},
|
||||
recordUndo: false
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Block delete',
|
||||
class: Blockly.Events.BlockDelete,
|
||||
getArgs: (thisObj) => [thisObj.block],
|
||||
getExpectedJson: (thisObj) => ({type: 'delete',
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'delete',
|
||||
blockId: thisObj.block.id,
|
||||
oldXml: '<block xmlns="https://developers.google.com/blockly/xml"' +
|
||||
' type="simple_test_block" id="testBlockId1"></block>',
|
||||
ids: [thisObj.block.id]})},
|
||||
{title: 'Block delete (shadow)', class: Blockly.Events.BlockDelete,
|
||||
' type="simple_test_block" id="testBlockId1" x="0" y="0">' +
|
||||
'</block>',
|
||||
ids: [thisObj.block.id],
|
||||
wasShadow: false,
|
||||
oldJson: {
|
||||
'type': 'simple_test_block',
|
||||
'id': 'testBlockId1',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
},
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Block delete (shadow)',
|
||||
class: Blockly.Events.BlockDelete,
|
||||
getArgs: (thisObj) => [thisObj.shadowBlock],
|
||||
getExpectedJson: (thisObj) => ({type: 'delete',
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'delete',
|
||||
blockId: thisObj.shadowBlock.id,
|
||||
oldXml: '<shadow xmlns="https://developers.google.com/blockly/xml"' +
|
||||
' type="simple_test_block" id="testBlockId2"></shadow>',
|
||||
ids: [thisObj.shadowBlock.id], recordUndo: false})},
|
||||
' type="simple_test_block" id="testBlockId2" x="0" y="0">' +
|
||||
'</shadow>',
|
||||
ids: [thisObj.shadowBlock.id],
|
||||
wasShadow: true,
|
||||
oldJson: {
|
||||
'type': 'simple_test_block',
|
||||
'id': 'testBlockId2',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
},
|
||||
recordUndo: false
|
||||
})
|
||||
},
|
||||
// TODO(#4577) Test serialization of move event coordinate properties.
|
||||
{title: 'Block move', class: Blockly.Events.BlockMove,
|
||||
{
|
||||
title: 'Block move',
|
||||
class: Blockly.Events.BlockMove,
|
||||
getArgs: (thisObj) => [thisObj.block],
|
||||
getExpectedJson: (thisObj) => ({type: 'move',
|
||||
blockId: thisObj.block.id})},
|
||||
{title: 'Block move (shadow)', class: Blockly.Events.BlockMove,
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'move',
|
||||
blockId: thisObj.block.id
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Block move (shadow)',
|
||||
class: Blockly.Events.BlockMove,
|
||||
getArgs: (thisObj) => [thisObj.shadowBlock],
|
||||
getExpectedJson: (thisObj) => ({type: 'move',
|
||||
blockId: thisObj.shadowBlock.id, recordUndo: false})},
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'move',
|
||||
blockId: thisObj.shadowBlock.id,
|
||||
recordUndo: false
|
||||
})
|
||||
},
|
||||
];
|
||||
var workspaceEventTestCases = [
|
||||
{title: 'Finished Loading', class: Blockly.Events.FinishedLoading,
|
||||
|
||||
@@ -689,7 +689,11 @@ suite('JSO Deserialization', function() {
|
||||
Blockly.Blocks['test_block'] = {
|
||||
init: function() { },
|
||||
|
||||
mutationToDom: function() { },
|
||||
mutationToDom: function() {
|
||||
var container = Blockly.utils.xml.createElement('mutation');
|
||||
container.setAttribute('value', 'some value');
|
||||
return container;
|
||||
},
|
||||
|
||||
domToMutation: function(element) {
|
||||
this.someProperty = element.getAttribute('value');
|
||||
|
||||
@@ -481,9 +481,9 @@ function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
|
||||
}
|
||||
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;
|
||||
|
||||
function defineStackBlock() {
|
||||
function defineStackBlock(name = 'stack_block') {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "stack_block",
|
||||
"type": name,
|
||||
"message0": "",
|
||||
"previousStatement": null,
|
||||
"nextStatement": null
|
||||
@@ -491,9 +491,9 @@ function defineStackBlock() {
|
||||
}
|
||||
exports.defineStackBlock = defineStackBlock;
|
||||
|
||||
function defineRowBlock() {
|
||||
function defineRowBlock(name = 'row_block') {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "row_block",
|
||||
"type": name,
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
@@ -506,9 +506,9 @@ function defineRowBlock() {
|
||||
}
|
||||
exports.defineRowBlock = defineRowBlock;
|
||||
|
||||
function defineStatementBlock() {
|
||||
function defineStatementBlock(name = 'statement_block') {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "statement_block",
|
||||
"type": name,
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
@@ -525,9 +525,9 @@ function defineStatementBlock() {
|
||||
}
|
||||
exports.defineStatementBlock = defineStatementBlock;
|
||||
|
||||
function defineBasicBlockWithField() {
|
||||
function defineBasicBlockWithField(name = 'test_field_block') {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "test_field_block",
|
||||
"type": name,
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
goog.module('Blockly.test.trashcan');
|
||||
|
||||
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers');
|
||||
const {assertEventFired, assertEventNotFired, defineBasicBlockWithField, defineRowBlock, defineStatementBlock, defineStackBlock, defineMutatorBlocks, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers');
|
||||
|
||||
|
||||
suite("Trashcan", function() {
|
||||
@@ -15,14 +15,13 @@ suite("Trashcan", function() {
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
xmlString + '</xml>');
|
||||
xml = xml.children[0];
|
||||
var event = new Blockly.Events.BlockDelete();
|
||||
event.oldXml = xml;
|
||||
event.workspaceId = workspace.id;
|
||||
var block = Blockly.Xml.domToBlock(xml, workspace);
|
||||
var event = new Blockly.Events.BlockDelete(block);
|
||||
Blockly.Events.fire(event);
|
||||
}
|
||||
function fireNonDeleteEvent(workspace, oldXml) {
|
||||
var event = new Blockly.Events.Abstract();
|
||||
event.type = 'dummy_type';
|
||||
event.type = 'test_field_block';
|
||||
event.workspaceId = workspace.id;
|
||||
if (oldXml) {
|
||||
event.oldXml = oldXml;
|
||||
@@ -32,17 +31,27 @@ suite("Trashcan", function() {
|
||||
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineBasicBlockWithField();
|
||||
defineRowBlock();
|
||||
defineRowBlock('row_block2');
|
||||
defineStatementBlock();
|
||||
defineStatementBlock('statement_block2');
|
||||
defineStackBlock();
|
||||
defineStackBlock('stack_block2');
|
||||
defineMutatorBlocks();
|
||||
this.workspace = Blockly.inject('blocklyDiv',
|
||||
{'trashcan': true, 'maxTrashcanContents': Infinity});
|
||||
this.trashcan = this.workspace.trashcan;
|
||||
});
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
Blockly.Extensions.unregister('xml_mutator');
|
||||
Blockly.Extensions.unregister('jso_mutator');
|
||||
});
|
||||
|
||||
suite("Events", function() {
|
||||
test("Delete", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Non-Delete", function() {
|
||||
@@ -52,7 +61,7 @@ suite("Trashcan", function() {
|
||||
test("Non-Delete w/ oldXml", function() {
|
||||
var xml = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' <block type="test_field_block"/>' +
|
||||
'</xml>'
|
||||
);
|
||||
xml = xml.children[0];
|
||||
@@ -60,7 +69,7 @@ suite("Trashcan", function() {
|
||||
chai.assert.equal(this.trashcan.contents_.length, 0);
|
||||
});
|
||||
test("Shadow Delete", function() {
|
||||
fireDeleteEvent(this.workspace, '<shadow type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<shadow type="test_field_block"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 0);
|
||||
});
|
||||
test("Click without contents - fires workspace click", function() {
|
||||
@@ -73,7 +82,7 @@ suite("Trashcan", function() {
|
||||
this.workspace.id, null);
|
||||
});
|
||||
test("Click with contents - fires trashcanOpen", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
// Stub flyout interaction.
|
||||
var showFlyoutStub = sinon.stub(this.trashcan.flyout, "show");
|
||||
@@ -107,56 +116,52 @@ suite("Trashcan", function() {
|
||||
});
|
||||
suite("Unique Contents", function() {
|
||||
test("Simple", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Different Coords", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" x="10" y="10"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" x="20" y="20"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block" x="10" y="10"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block" x="20" y="20"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("Different IDs", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" id="id1"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" id="id2"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block" id="id1"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block" id="id2"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("No Disabled - Disabled True", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" disabled="true"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block"/>');
|
||||
fireDeleteEvent(
|
||||
this.workspace, '<block type="test_field_block" disabled="true"/>');
|
||||
// Disabled tags get removed because disabled blocks aren't allowed to
|
||||
// be dragged from flyouts. See #2239 and #3243.
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("No Editable - Editable False", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" editable="false"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Movable - Movable False", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type" movable="false"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Field Values", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value1</field>' +
|
||||
'<block type="test_field_block">' +
|
||||
' <field name="NAME">dummy_value1</field>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <field name="dummy_name">dummy_value2</field>' +
|
||||
'<block type="test_field_block">' +
|
||||
' <field name="NAME">dummy_value2</field>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Values - Values", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="row_block"/>');
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'<block type="row_block">' +
|
||||
' <value name="INPUT">' +
|
||||
' <block type="row_block"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -164,27 +169,27 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Value Blocks", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
'<block type="row_block">' +
|
||||
' <value name="INPUT">' +
|
||||
' <block type="row_block"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <value name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
'<block type="row_block">' +
|
||||
' <value name="INPUT">' +
|
||||
' <block type="row_block2"/>' +
|
||||
' </value>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Statements - Statements", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="statement_block"/>');
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type"/>' +
|
||||
'<block type="statement_block">' +
|
||||
' <statement name="NAME">' +
|
||||
' <block type="statement_block"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -192,27 +197,27 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Statement Blocks", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
'<block type="statement_block">' +
|
||||
' <statement name="NAME">' +
|
||||
' <block type="statement_block"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <statement name="dummy_input">' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
'<block type="test_field_block">' +
|
||||
' <statement name="NAME">' +
|
||||
' <block type="statement_block2"/>' +
|
||||
' </statement>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Next - Next", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="stack_block"/>');
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="stack_block">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type"/>' +
|
||||
' <block type="stack_block"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -220,25 +225,25 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Next Blocks", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="stack_block">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type1"/>' +
|
||||
' <block type="stack_block"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="stack_block">' +
|
||||
' <next>' +
|
||||
' <block type="dummy_type2"/>' +
|
||||
' <block type="stack_block2"/>' +
|
||||
' </next>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("No Comment - Comment", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment>comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -246,12 +251,12 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Comment Text", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment>comment_text1</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment>comment_text2</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -259,12 +264,12 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Comment Size", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment h="10" w="10">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment h="20" w="20">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
@@ -273,36 +278,27 @@ suite("Trashcan", function() {
|
||||
});
|
||||
test("Different Comment Pinned", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment pinned="false">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
'<block type="test_field_block">' +
|
||||
' <comment pinned="true">comment_text</comment>' +
|
||||
'</block>'
|
||||
);
|
||||
// pinned tags are removed b/c the blocks appear the same.
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
});
|
||||
test("No Mutator - Mutator", function() {
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type"/>');
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
});
|
||||
test("Different Mutator", function() {
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value1"></mutation>' +
|
||||
'<block type="xml_block">' +
|
||||
' <mutation hasInput="true"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type">' +
|
||||
' <mutation dummy_attribute="dummy_value2"></mutation>' +
|
||||
'<block type="xml_block">' +
|
||||
' <mutation hasInputt="false"></mutation>' +
|
||||
'</block>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 2);
|
||||
@@ -312,22 +308,10 @@ suite("Trashcan", function() {
|
||||
test("Max 0", function() {
|
||||
this.workspace.options.maxTrashcanContents = 0;
|
||||
fireDeleteEvent(this.workspace,
|
||||
'<block type="dummy_type"/>'
|
||||
'<block type="test_field_block"/>'
|
||||
);
|
||||
chai.assert.equal(this.trashcan.contents_.length, 0);
|
||||
this.workspace.options.maxTrashcanContents = Infinity;
|
||||
});
|
||||
test("Last In First Out", function() {
|
||||
this.workspace.options.maxTrashcanContents = 1;
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type1"/>');
|
||||
fireDeleteEvent(this.workspace, '<block type="dummy_type2"/>');
|
||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||
chai.assert.equal(
|
||||
Blockly.Xml.textToDom(this.trashcan.contents_[0])
|
||||
.getAttribute('type'),
|
||||
'dummy_type2'
|
||||
);
|
||||
this.workspace.options.maxTrashcanContents = Infinity;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user