mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
fix: Drag and Resize events for workspace comments (#8217)
* feat: Added a comment_drag event. * Add workspace comment resize events. * Addressing PR feedback. * Fixed chai imports in new test files. * Addressing more PR feedback.
This commit is contained in:
35
tests/mocha/event_comment_drag_test.js
Normal file
35
tests/mocha/event_comment_drag_test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
} from './test_helpers/setup_teardown.js';
|
||||
|
||||
suite('Comment Drag 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.comments.WorkspaceComment(this.workspace);
|
||||
comment.setText('test text');
|
||||
|
||||
const origEvent = new Blockly.Events.CommentDrag(comment, true);
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
tests/mocha/event_comment_resize_test.js
Normal file
38
tests/mocha/event_comment_resize_test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
} from './test_helpers/setup_teardown.js';
|
||||
|
||||
suite('Comment Resize 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.comments.WorkspaceComment(this.workspace);
|
||||
comment.setText('test text');
|
||||
comment.setSize(new Blockly.utils.Size(100, 100));
|
||||
const origEvent = new Blockly.Events.CommentResize(comment);
|
||||
comment.setSize(new Blockly.utils.Size(200, 200));
|
||||
origEvent.recordCurrentSizeAsNewSize();
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -862,7 +862,30 @@ suite('Events', function () {
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'Comment drag start',
|
||||
class: Blockly.Events.CommentDrag,
|
||||
getArgs: (thisObj) => [thisObj.comment, true],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'comment_drag',
|
||||
group: '',
|
||||
isStart: true,
|
||||
commentId: thisObj.comment.id,
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'Comment drag end',
|
||||
class: Blockly.Events.CommentDrag,
|
||||
getArgs: (thisObj) => [thisObj.comment, false],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'comment_drag',
|
||||
group: '',
|
||||
isStart: false,
|
||||
commentId: thisObj.comment.id,
|
||||
}),
|
||||
},
|
||||
// TODO(#4577) Test serialization of move event coordinate properties.
|
||||
// TODO(#4577) Test serialization of comment resize event properties.
|
||||
];
|
||||
const testSuites = [
|
||||
{
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
import './event_comment_create_test.js';
|
||||
import './event_comment_delete_test.js';
|
||||
import './event_comment_move_test.js';
|
||||
import './event_comment_drag_test.js';
|
||||
import './event_comment_resize_test.js';
|
||||
import './event_marker_move_test.js';
|
||||
import './event_selected_test.js';
|
||||
import './event_theme_change_test.js';
|
||||
|
||||
@@ -81,6 +81,28 @@ suite('Workspace comment', function () {
|
||||
);
|
||||
});
|
||||
|
||||
test('resize events are fired when a comment is resized', function () {
|
||||
this.renderedComment = new Blockly.comments.RenderedWorkspaceComment(
|
||||
this.workspace,
|
||||
);
|
||||
const spy = createChangeListenerSpy(this.workspace);
|
||||
|
||||
this.renderedComment.setSize(new Blockly.utils.Size(300, 200));
|
||||
|
||||
this.clock.runAll();
|
||||
|
||||
assertEventFired(
|
||||
spy,
|
||||
Blockly.Events.CommentResize,
|
||||
{
|
||||
commentId: this.renderedComment.id,
|
||||
oldSize: {width: 120, height: 100},
|
||||
newSize: {width: 300, height: 200},
|
||||
},
|
||||
this.workspace.id,
|
||||
);
|
||||
});
|
||||
|
||||
test('change events are fired when a comments text is edited', function () {
|
||||
this.renderedComment = new Blockly.comments.RenderedWorkspaceComment(
|
||||
this.workspace,
|
||||
|
||||
Reference in New Issue
Block a user