mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
feat: refactor event serialization to use static fromJson method (#6614)
* feat: add new path for deserialization of events * chore: add tests for round-tripping events * chore: add static fromJson methods to all events * chore: add inline docs to new static methods * chore: add deprecation warnings * chore: cleanup * chore: add deprecation and docs to abstract * chore: format * chore: cleanup from rebase * chore: update docs comment
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.blockChangeEvent');
|
||||
goog.declareModuleId('Blockly.test.eventBlockChange');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
import {defineMutatorBlocks} from './test_helpers/block_definitions.js';
|
||||
@@ -71,4 +71,28 @@ suite('Block Change Event', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
setup(function() {
|
||||
defineMutatorBlocks();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
Blockly.Extensions.unregister('xml_mutator');
|
||||
Blockly.Extensions.unregister('jso_mutator');
|
||||
});
|
||||
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('xml_block', 'block_id');
|
||||
block.domToMutation(
|
||||
Blockly.Xml.textToDom('<mutation hasInput="true"/>'));
|
||||
const origEvent = new Blockly.Events.BlockChange(
|
||||
block, 'mutation', null, '', '<mutation hasInput="true"/>');
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -4,16 +4,18 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.blockCreateEvent');
|
||||
goog.declareModuleId('Blockly.test.eventBlockCreate');
|
||||
|
||||
import {assertEventFired} from './test_helpers/events.js';
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
|
||||
|
||||
suite('Block Create Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
@@ -25,28 +27,22 @@ suite('Block Create Event', function() {
|
||||
Blockly.Events.disable();
|
||||
const block = Blockly.serialization.blocks.append(
|
||||
{
|
||||
"type": "text_print",
|
||||
"type": "row_block",
|
||||
"inputs": {
|
||||
"TEXT": {
|
||||
"INPUT": {
|
||||
"shadow": {
|
||||
"type": "text",
|
||||
"type": "row_block",
|
||||
"id": "shadowId",
|
||||
"fields": {
|
||||
"TEXT": "abc",
|
||||
},
|
||||
},
|
||||
"block": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"TEXT": "",
|
||||
},
|
||||
"type": "row_block",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
this.workspace);
|
||||
Blockly.Events.enable();
|
||||
block.getInput('TEXT').connection.disconnect();
|
||||
block.getInput('INPUT').connection.disconnect();
|
||||
assertEventFired(
|
||||
this.eventsFireStub,
|
||||
Blockly.Events.BlockCreate,
|
||||
@@ -57,4 +53,18 @@ suite('Block Create Event', function() {
|
||||
const event = calls[calls.length - 1].args[0];
|
||||
chai.assert.equal(event.xml.tagName, 'shadow');
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('row_block', 'block_id');
|
||||
const origEvent = new Blockly.Events.BlockCreate(block);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -4,14 +4,16 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.blockDeleteEvent');
|
||||
goog.declareModuleId('Blockly.test.eventBlockDelete');
|
||||
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
suite('Block Delete Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
@@ -36,4 +38,18 @@ suite('Block Delete Event', function() {
|
||||
chai.assert.isTrue(spy.getCall(0).args[0] instanceof deleteClass);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('row_block', 'block_id');
|
||||
const origEvent = new Blockly.Events.BlockDelete(block);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
delete origEvent.oldXml; // xml fails deep equals for some reason.
|
||||
delete newEvent.oldXml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
35
tests/mocha/event_block_drag_test.js
Normal file
35
tests/mocha/event_block_drag_test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventBlockDrag');
|
||||
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Block Drag Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('row_block', 'block_id');
|
||||
const origEvent = new Blockly.Events.BlockDrag(block, true, []);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
tests/mocha/event_block_move_test.js
Normal file
38
tests/mocha/event_block_move_test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventBlockMove');
|
||||
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Block Move Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block1 = this.workspace.newBlock('row_block', 'block_id');
|
||||
const block2 = this.workspace.newBlock('row_block', 'block_id');
|
||||
const origEvent = new Blockly.Events.BlockMove(block1);
|
||||
block2.getInput('INPUT').connection.connect(block2.outputConnection);
|
||||
origEvent.recordNew();
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
39
tests/mocha/event_bubble_open_test.js
Normal file
39
tests/mocha/event_bubble_open_test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventBubbleOpen');
|
||||
|
||||
import {defineMutatorBlocks} from './test_helpers/block_definitions.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Bubble Open Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineMutatorBlocks();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
Blockly.Extensions.unregister('xml_mutator');
|
||||
Blockly.Extensions.unregister('jso_mutator');
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('jso_block', 'block_id');
|
||||
const origEvent =
|
||||
new Blockly.Events.BubbleOpen(
|
||||
block, true, Blockly.Events.BubbleType.MUTATOR);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
37
tests/mocha/event_click_test.js
Normal file
37
tests/mocha/event_click_test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventClick');
|
||||
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Click Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block = this.workspace.newBlock('row_block', 'block_id');
|
||||
const origEvent =
|
||||
new Blockly.Events.Click(
|
||||
block, undefined, Blockly.Events.ClickTarget.BLOCK);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
35
tests/mocha/event_comment_change_test.js
Normal file
35
tests/mocha/event_comment_change_test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventCommentChange');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Comment Change Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const comment =
|
||||
new Blockly.WorkspaceComment(this.workspace, 'old text', 10, 10);
|
||||
const origEvent =
|
||||
new Blockly.Events.CommentChange(comment, 'old text', 'new text');
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
37
tests/mocha/event_comment_create_test.js
Normal file
37
tests/mocha/event_comment_create_test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventCommentCreate');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Comment Create Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const comment =
|
||||
new Blockly.WorkspaceComment(this.workspace, 'test text', 10, 10);
|
||||
const origEvent = new Blockly.Events.CommentCreate(comment);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
37
tests/mocha/event_comment_delete_test.js
Normal file
37
tests/mocha/event_comment_delete_test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventCommentDelete');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Comment Delete Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const comment =
|
||||
new Blockly.WorkspaceComment(this.workspace, 'test text', 10, 10);
|
||||
const origEvent = new Blockly.Events.CommentDelete(comment);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
delete origEvent.xml; // xml fails deep equals for some reason.
|
||||
delete newEvent.xml; // xml fails deep equals for some reason.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
39
tests/mocha/event_comment_move_test.js
Normal file
39
tests/mocha/event_comment_move_test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventCommentMove');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Comment Move Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const comment =
|
||||
new Blockly.WorkspaceComment(this.workspace, 'test text', 10, 10);
|
||||
const origEvent = new Blockly.Events.CommentMove(comment);
|
||||
comment.moveBy(10, 10);
|
||||
origEvent.recordNew();
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
delete origEvent.comment_; // Ignore private properties.
|
||||
delete newEvent.comment_; // Ignore private properties.
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
39
tests/mocha/event_marker_move_test.js
Normal file
39
tests/mocha/event_marker_move_test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventMarkerMove');
|
||||
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js;';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Marker Move Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite.only('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block1 = this.workspace.newBlock('row_block', 'test_id1');
|
||||
const block2 = this.workspace.newBlock('row_block', 'test_id2');
|
||||
const node1 = new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block1);
|
||||
const node2 = new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block2);
|
||||
const origEvent = new Blockly.Events.MarkerMove(block2, false, node1, node2);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
tests/mocha/event_selected_test.js
Normal file
38
tests/mocha/event_selected_test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventSelected');
|
||||
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js;';
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Selected Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite.only('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const block1 = this.workspace.newBlock('row_block', 'test_id1');
|
||||
const block2 = this.workspace.newBlock('row_block', 'test_id2');
|
||||
const origEvent =
|
||||
new Blockly.Events.Selected(block1.id, block2.id, this.workspace.id);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -547,6 +547,7 @@ suite('Events', function() {
|
||||
type: 'move',
|
||||
group: '',
|
||||
blockId: thisObj.block.id,
|
||||
oldCoordinate: "0, 0",
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -557,6 +558,7 @@ suite('Events', function() {
|
||||
type: 'move',
|
||||
group: '',
|
||||
blockId: thisObj.shadowBlock.id,
|
||||
oldCoordinate: "0, 0",
|
||||
recordUndo: false,
|
||||
}),
|
||||
},
|
||||
@@ -581,7 +583,8 @@ suite('Events', function() {
|
||||
{title: 'Comment delete', class: Blockly.Events.CommentDelete,
|
||||
getArgs: (thisObj) => [thisObj.comment],
|
||||
getExpectedJson: (thisObj) => ({type: 'comment_delete', group: '',
|
||||
commentId: thisObj.comment.id})},
|
||||
commentId: thisObj.comment.id,
|
||||
xml: Blockly.Xml.domToText(thisObj.comment.toXmlWithXY())})},
|
||||
// TODO(#4577) Test serialization of move event coordinate properties.
|
||||
];
|
||||
const testSuites = [
|
||||
@@ -620,9 +623,8 @@ suite('Events', function() {
|
||||
testSuite.testCases.forEach((testCase) => {
|
||||
test(testCase.title, function() {
|
||||
const event = new testCase.class(...testCase.getArgs(this));
|
||||
const event2 = new testCase.class();
|
||||
const json = event.toJson();
|
||||
event2.fromJson(json);
|
||||
const event2 = Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.equal(
|
||||
safeStringify(event2.toJson()), safeStringify(json));
|
||||
|
||||
34
tests/mocha/event_theme_change_test.js
Normal file
34
tests/mocha/event_theme_change_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventThemeChange');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Theme Change Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const origEvent =
|
||||
new Blockly.Events.ThemeChange('new theme name', this.workspace.id);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
62
tests/mocha/event_toolbox_item_select_test.js
Normal file
62
tests/mocha/event_toolbox_item_select_test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventToolboxItemSelect');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Toolbox Item Select Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = Blockly.inject('blocklyDiv', {
|
||||
toolbox: {
|
||||
"kind": "categoryToolbox",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "category",
|
||||
"name": "Control",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "controls_if",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"kind": "category",
|
||||
"name": "Logic",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "block",
|
||||
"type": "logic_compare",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const items = this.workspace.getToolbox().getToolboxItems();
|
||||
const origEvent =
|
||||
new Blockly.Events.ToolboxItemSelect(
|
||||
items[0].getName(), items[1].getName(), this.workspace.id);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
34
tests/mocha/event_trashcan_open_test.js
Normal file
34
tests/mocha/event_trashcan_open_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventTrashcanOpen');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Trashcan Open Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const origEvent =
|
||||
new Blockly.Events.TrashcanOpen(true, this.workspace.id);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
35
tests/mocha/event_var_create_test.js
Normal file
35
tests/mocha/event_var_create_test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventVarCreate');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Var Create Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', 'type', 'id');
|
||||
const origEvent = new Blockly.Events.VarCreate(varModel);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
34
tests/mocha/event_var_delete_test.js
Normal file
34
tests/mocha/event_var_delete_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventVarDelete');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Var Delete Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'name', 'type', 'id');
|
||||
const origEvent = new Blockly.Events.VarDelete(varModel);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
34
tests/mocha/event_var_rename_test.js
Normal file
34
tests/mocha/event_var_rename_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventVarRename');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Var Rename Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const varModel =
|
||||
new Blockly.VariableModel(this.workspace, 'old name', 'type', 'id');
|
||||
const origEvent = new Blockly.Events.VarRename(varModel, 'new name');
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
34
tests/mocha/event_viewport_test.js
Normal file
34
tests/mocha/event_viewport_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.declareModuleId('Blockly.test.eventViewportChange');
|
||||
|
||||
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
|
||||
|
||||
|
||||
suite('Viewport Change Event', function() {
|
||||
setup(function() {
|
||||
sharedTestSetup.call(this);
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
test('events round-trip through JSON', function() {
|
||||
const origEvent =
|
||||
new Blockly.Events.ViewportChange(10, 10, 1, this.workspace.id, .8);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
chai.assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -50,9 +50,6 @@
|
||||
|
||||
// Test modules.
|
||||
'Blockly.test.astNode',
|
||||
'Blockly.test.blockChangeEvent',
|
||||
'Blockly.test.blockDeleteEvent',
|
||||
'Blockly.test.blockCreateEvent',
|
||||
'Blockly.test.blockJson',
|
||||
'Blockly.test.blocks',
|
||||
'Blockly.test.comments',
|
||||
@@ -64,6 +61,26 @@
|
||||
'Blockly.test.cursor',
|
||||
'Blockly.test.dropdown',
|
||||
'Blockly.test.event',
|
||||
'Blockly.test.eventBlockChange',
|
||||
'Blockly.test.eventBlockCreate',
|
||||
'Blockly.test.eventBlockDelete',
|
||||
'Blockly.test.eventBlockDrag',
|
||||
'Blockly.test.eventBlockMove',
|
||||
'Blockly.test.eventBubbleOpen',
|
||||
'Blockly.test.eventClick',
|
||||
'Blockly.test.eventCommentChange',
|
||||
'Blockly.test.eventCommentCreate',
|
||||
'Blockly.test.eventCommentDelete',
|
||||
'Blockly.test.eventCommentMove',
|
||||
'Blockly.test.eventMarkerMove',
|
||||
'Blockly.test.eventSelected',
|
||||
'Blockly.test.eventThemeChange',
|
||||
'Blockly.test.eventToolboxItemSelect',
|
||||
'Blockly.test.eventTrashcanOpen',
|
||||
'Blockly.test.eventVarCreate',
|
||||
'Blockly.test.eventVarDelete',
|
||||
'Blockly.test.eventVarRename',
|
||||
'Blockly.test.eventViewportChange',
|
||||
'Blockly.test.extensions',
|
||||
'Blockly.test.fieldAngle',
|
||||
'Blockly.test.fieldCheckbox',
|
||||
|
||||
@@ -67,4 +67,3 @@ suite('Mutator', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user