From 540ab16842f7392caa3dcd09f5aae4f94d27b75f Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Mon, 11 Jan 2021 16:14:34 -0800 Subject: [PATCH] Fix serialization of workspace comment events and add tests (#4578) * Fix serialization of workspace comment events and add tests --- core/events/ws_comment_events.js | 2 +- tests/mocha/event_test.js | 38 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/core/events/ws_comment_events.js b/core/events/ws_comment_events.js index 82369fd37..6a5d0b4f2 100644 --- a/core/events/ws_comment_events.js +++ b/core/events/ws_comment_events.js @@ -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']; }; /** diff --git a/tests/mocha/event_test.js b/tests/mocha/event_test.js index 725e9e4c2..66e414e65 100644 --- a/tests/mocha/event_test.js +++ b/tests/mocha/event_test.js @@ -593,6 +593,7 @@ suite('Events', function() { oldXml: '', 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() {