mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Make ui events work when block is null; test
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user