Make ui events work when block is null; test

This commit is contained in:
Rachel Fenichel
2018-05-03 17:36:08 -07:00
parent c1922a1cd2
commit 02aada1e3d
2 changed files with 53 additions and 6 deletions

View File

@@ -34,6 +34,10 @@ goog.require('goog.math.Coordinate');
/**
* Class for a UI event.
* UI events are events that don't need to be sent over the wire for multi-user
* editing to work (e.g. scrolling the workspace, zooming, opening toolbox
* categories).
* UI events do not undo or redo.
* @param {Blockly.Block} block The affected block.
* @param {string} element One of 'selected', 'comment', 'mutator', etc.
* @param {*} oldValue Previous value of element.
@@ -42,16 +46,13 @@ goog.require('goog.math.Coordinate');
* @constructor
*/
Blockly.Events.Ui = function(block, element, oldValue, newValue) {
if (!block) {
return; // Blank event to be populated by fromJson.
}
Blockly.Events.Ui.superClass_.constructor.call(this);
this.blockId = block.id;
this.workspaceId = block.workspace.id;
this.blockId = block ? block.id : null;
this.workspaceId = block? block.workspace.id : null;
this.element = element;
this.oldValue = oldValue;
this.newValue = newValue;
// UI events do not undo or redo.
this.recordUndo = false;
};
goog.inherits(Blockly.Events.Ui, Blockly.Events.Abstract);

View File

@@ -312,6 +312,52 @@ function test_blockMove_constructoroldParentId() {
}
}
function test_uiEvent_constructor_null() {
try {
Blockly.Events.setGroup('testGroup');
var event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
checkExactEventValues(event,
{
'blockId': null,
'workspaceId': null,
'type': 'ui',
'oldValue': 'bar',
'newValue': 'baz',
'element': 'foo',
'recordUndo': false,
'group': 'testGroup'
}
);
} finally {
Blockly.Events.setGroup(false);
}
}
function test_uiEvent_constructor_block() {
eventTest_setUpWithMockBlocks();
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
try {
var block1 = createSimpleTestBlock(workspace);
Blockly.Events.setGroup('testGroup');
var event = new Blockly.Events.Ui(block1, 'foo', 'bar', 'baz');
checkExactEventValues(event,
{
'blockId': '1',
'workspaceId': workspace.id,
'type': 'ui',
'oldValue': 'bar',
'newValue': 'baz',
'element': 'foo',
'recordUndo': false,
'group': 'testGroup'
}
);
} finally {
Blockly.Events.setGroup(false);
eventTest_tearDownWithMockBlocks();
}
}
function test_varCreate_constructor() {
eventTest_setUp();
try {