Fix serialization of workspace comment events and add tests (#4578)

* Fix serialization of workspace comment events and add tests
This commit is contained in:
Monica Kozbial
2021-01-11 16:14:34 -08:00
committed by GitHub
parent faf953b18b
commit 540ab16842
2 changed files with 38 additions and 2 deletions

View File

@@ -137,7 +137,7 @@ Blockly.Events.CommentChange.prototype.toJson = function() {
*/
Blockly.Events.CommentChange.prototype.fromJson = function(json) {
Blockly.Events.CommentChange.superClass_.fromJson.call(this, json);
this.newContents_ = json['newValue'];
this.newContents_ = json['newContents'];
};
/**

View File

@@ -593,6 +593,7 @@ suite('Events', function() {
oldXml: '<shadow xmlns="https://developers.google.com/blockly/xml"' +
' type="simple_test_block" id="testBlockId2"></shadow>',
ids: [thisObj.shadowBlock.id], recordUndo: false})},
// TODO(#4577) Test serialization of move event coordinate properties.
{title: 'Block move', class: Blockly.Events.BlockMove,
getArgs: (thisObj) => [thisObj.block],
getExpectedJson: (thisObj) => ({type: 'move',
@@ -602,6 +603,32 @@ suite('Events', function() {
getExpectedJson: (thisObj) => ({type: 'move',
blockId: thisObj.shadowBlock.id, recordUndo: false})},
];
var workspaceEventTestCases = [
{title: 'Finished Loading', class: Blockly.Events.FinishedLoading,
getArgs: (thisObj) => [thisObj.workspace],
getExpectedJson: (thisObj) => ({type: 'finished_loading',
workspaceId: thisObj.workspace.id})},
];
var workspaceCommentEventTestCases = [
{title: 'Comment change', class: Blockly.Events.CommentChange,
getArgs: (thisObj) => [thisObj.comment, '', 'words'],
getExpectedJson: (thisObj) => ({type: 'comment_change',
commentId: thisObj.comment.id, newContents: 'words'})},
{title: 'Comment create', class: Blockly.Events.CommentCreate,
getArgs: (thisObj) => [thisObj.comment],
getExpectedJson: (thisObj) => ({type: 'comment_create',
commentId: thisObj.comment.id,
xml: Blockly.Xml.domToText(thisObj.comment.toXmlWithXY())})},
{title: 'Comment delete', class: Blockly.Events.CommentDelete,
getArgs: (thisObj) => [thisObj.comment],
getExpectedJson: (thisObj) => ({type: 'comment_delete',
commentId: thisObj.comment.id})},
// TODO(#4577) Test serialization of move event coordinate properties.
{title: 'Comment move', class: Blockly.Events.CommentMove,
getArgs: (thisObj) => [thisObj.comment],
getExpectedJson: (thisObj) => ({type: 'comment_move',
commentId: thisObj.comment.id})},
];
var testSuites = [
{title: 'Variable events', testCases: variableEventTestCases,
setup: (thisObj) => {
@@ -618,7 +645,16 @@ suite('Events', function() {
thisObj.block = createSimpleTestBlock(thisObj.workspace);
thisObj.shadowBlock = createSimpleTestBlock(thisObj.workspace);
thisObj.shadowBlock.setShadow(true);
}}
}},
{title: 'Workspace events',
testCases: workspaceEventTestCases,
setup: (_) => {}},
{title: 'WorkspaceComment events',
testCases: workspaceCommentEventTestCases,
setup: (thisObj) => {
thisObj.comment = new Blockly.WorkspaceComment(
thisObj.workspace, 'comment text', 0, 0, 'comment id');
}},
];
testSuites.forEach((testSuite) => {
suite(testSuite.title, function() {