From 2f7ebcf9276b31485cbe34936d6a35f2b3441e65 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 20 Mar 2024 22:12:27 +0000 Subject: [PATCH] chore: add tests for move and change events --- tests/mocha/workspace_comment_test.js | 42 ++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/mocha/workspace_comment_test.js b/tests/mocha/workspace_comment_test.js index 6cf8b3d4bde..cac1750c7bb 100644 --- a/tests/mocha/workspace_comment_test.js +++ b/tests/mocha/workspace_comment_test.js @@ -23,7 +23,7 @@ suite('Workspace comment', function () { sharedTestTeardown.call(this); }); - suite('Events', function () { + suite.only('Events', function () { test('create events are fired when a comment is constructed', function () { const spy = createChangeListenerSpy(this.workspace); @@ -54,5 +54,45 @@ suite('Workspace comment', function () { this.workspace.id, ); }); + + test('move events are fired when a comment is moved', function () { + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.moveTo(new Blockly.utils.Coordinate(42, 42)); + + assertEventFired( + spy, + Blockly.Events.CommentMove, + { + commentId: this.renderedComment.id, + oldCoordinate_: {x: 0, y: 0}, + newCoordinate_: {x: 42, y: 42}, + }, + this.workspace.id, + ); + }); + + test('change events are fired when a comments text is edited', function () { + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.setText('test text'); + + assertEventFired( + spy, + Blockly.Events.CommentChange, + { + commentId: this.renderedComment.id, + oldContents_: '', + newContents_: 'test text', + }, + this.workspace.id, + ); + }); }); });