From cbe3a0039bf14de1d97c431005ea431f84b97eb3 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 25 Aug 2026 14:32:08 -0700 Subject: [PATCH] test: Reenable a variety of skipped tests --- .../tests/mocha/blocks/procedures_test.js | 24 +- packages/blockly/tests/mocha/input_test.js | 6 +- .../tests/mocha/old_workspace_comment_test.js | 256 ----------------- .../mocha/rendered_workspace_comment_test.js | 198 +++++++++++++ .../tests/mocha/workspace_comment_test.js | 260 +++++++++--------- .../blockly/tests/mocha/workspace_svg_test.js | 23 +- .../test/shadow_block_converter_test.mocha.js | 17 +- .../test/typed_variable_modal_test.mocha.js | 2 +- 8 files changed, 363 insertions(+), 423 deletions(-) delete mode 100644 packages/blockly/tests/mocha/old_workspace_comment_test.js create mode 100644 packages/blockly/tests/mocha/rendered_workspace_comment_test.js diff --git a/packages/blockly/tests/mocha/blocks/procedures_test.js b/packages/blockly/tests/mocha/blocks/procedures_test.js index a43b3c1e5cd..6491ca0eb4d 100644 --- a/packages/blockly/tests/mocha/blocks/procedures_test.js +++ b/packages/blockly/tests/mocha/blocks/procedures_test.js @@ -615,12 +615,6 @@ suite('Procedures', function () { ); }); - test.skip( - 'renaming a variable such that you get a parameter ' + - 'conflict does... something!', - function () {}, - ); - test('undoing renaming a procedure parameter reverts the change', async function () { // Create a stack of container, parameter. const defBlock = createProcDefBlock(this.workspace); @@ -1046,10 +1040,13 @@ suite('Procedures', function () { ); }); - test.skip('callers whose defs are deserialized later do not create defs', function () { + test('callers whose defs are deserialized later do not create defs', function () { Blockly.Xml.domToWorkspace( Blockly.utils.xml.textToDom(` + + x + @@ -1072,8 +1069,6 @@ suite('Procedures', function () { const callBlock = this.workspace.getBlocksByType( 'procedures_callreturn', )[0]; - // TODO: Currently the callers are creating variables with different - // IDs than those serialized to XML, so these assertions fail. assertDefBlockStructure(defBlock, true, ['x'], ['arg']); assertCallBlockStructure(callBlock, ['x'], ['arg'], 'do something'); }); @@ -1188,7 +1183,7 @@ suite('Procedures', function () { ); }); - test.skip('callers whose defs are deserialized later do not create defs', function () { + test('callers whose defs are deserialized later do not create defs', function () { Blockly.serialization.workspaces.load( { 'blocks': { @@ -1197,6 +1192,7 @@ suite('Procedures', function () { { 'type': 'procedures_callreturn', 'extraState': { + 'name': 'do something', 'params': ['x'], }, }, @@ -1216,6 +1212,12 @@ suite('Procedures', function () { }, ], }, + 'variables': [ + { + 'name': 'x', + 'id': 'arg', + }, + ], }, this.workspace, ); @@ -1226,8 +1228,6 @@ suite('Procedures', function () { const callBlock = this.workspace.getBlocksByType( 'procedures_callreturn', )[0]; - // TODO: Currently the callers are creating variables with different - // IDs than those serialized to JSON, so these assertions fail. assertDefBlockStructure(defBlock, true, ['x'], ['arg']); assertCallBlockStructure(callBlock, ['x'], ['arg'], 'do something'); }); diff --git a/packages/blockly/tests/mocha/input_test.js b/packages/blockly/tests/mocha/input_test.js index 9d7ff1daad0..02a0ca7ff0c 100644 --- a/packages/blockly/tests/mocha/input_test.js +++ b/packages/blockly/tests/mocha/input_test.js @@ -163,9 +163,7 @@ suite('Inputs', function () { setBlockSpy.restore(); initSpy.restore(); }); - // TODO: InsertFieldAt does not properly handle initialization in - // headless mode. - test.skip('Headless', function () { + test('Headless', function () { const field = new Blockly.FieldLabel('field'); const setBlockSpy = sinon.spy(field, 'setSourceBlock'); const initModelSpy = sinon.spy(field, 'initModel'); @@ -351,7 +349,7 @@ suite('Inputs', function () { assert.include(label, customLabel); }); - test.skip('Set input ARIA Label Provider to null', function () { + test('Set input ARIA Label Provider to null', function () { const blockA = createRenderedBlock(this.workspace, 'row_block'); const blockB = createRenderedBlock(this.workspace, 'row_block'); diff --git a/packages/blockly/tests/mocha/old_workspace_comment_test.js b/packages/blockly/tests/mocha/old_workspace_comment_test.js deleted file mode 100644 index 1b2acf31c60..00000000000 --- a/packages/blockly/tests/mocha/old_workspace_comment_test.js +++ /dev/null @@ -1,256 +0,0 @@ -/** - * @license - * Copyright 2020 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -import {assert} from 'chai'; -import { - sharedTestSetup, - sharedTestTeardown, -} from './test_helpers/setup_teardown.js'; - -suite.skip('Workspace comment', function () { - setup(function () { - sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); - }); - - teardown(function () { - sharedTestTeardown.call(this); - }); - - suite('getTopComments(ordered=true)', function () { - test('No comments', function () { - assert.equal(this.workspace.getTopComments(true).length, 0); - }); - - test('One comment', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - assert.equal(this.workspace.getTopComments(true).length, 1); - assert.equal(this.workspace.commentDB.get('comment id'), comment); - }); - - test('After clear empty workspace', function () { - this.workspace.clear(); - assert.equal(this.workspace.getTopComments(true).length, 0); - }); - - test('After clear non-empty workspace', function () { - new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - this.workspace.clear(); - assert.equal(this.workspace.getTopComments(true).length, 0); - assert.isFalse(this.workspace.commentDB.has('comment id')); - }); - - test('After dispose', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - comment.dispose(); - assert.equal(this.workspace.getTopComments(true).length, 0); - assert.isFalse(this.workspace.commentDB.has('comment id')); - }); - }); - - suite('getTopComments(ordered=false)', function () { - test('No comments', function () { - assert.equal(this.workspace.getTopComments(false).length, 0); - }); - - test('One comment', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - assert.equal(this.workspace.getTopComments(false).length, 1); - assert.equal(this.workspace.commentDB.get('comment id'), comment); - }); - - test('After clear empty workspace', function () { - this.workspace.clear(); - assert.equal(this.workspace.getTopComments(false).length, 0); - }); - - test('After clear non-empty workspace', function () { - new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - this.workspace.clear(); - assert.equal(this.workspace.getTopComments(false).length, 0); - assert.isFalse(this.workspace.commentDB.has('comment id')); - }); - - test('After dispose', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - comment.dispose(); - assert.equal(this.workspace.getTopComments(false).length, 0); - assert.isFalse(this.workspace.commentDB.has('comment id')); - }); - }); - - suite('getCommentById', function () { - test('Trivial', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - assert.equal(this.workspace.getCommentById(comment.id), comment); - }); - - test('Null id', function () { - assert.isNull(this.workspace.getCommentById(null)); - }); - - test('Non-existent id', function () { - assert.isNull(this.workspace.getCommentById('badId')); - }); - - test('After dispose', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - comment.dispose(); - assert.isNull(this.workspace.getCommentById(comment.id)); - }); - }); - - suite('dispose', function () { - test('Called twice', function () { - const comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - comment.dispose(); - // Nothing should go wrong the second time dispose is called. - comment.dispose(); - }); - }); - - suite('Width and height', function () { - setup(function () { - this.comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 10, - 20, - 'comment id', - ); - }); - - test('Initial values', function () { - assert.equal(this.comment.getWidth(), 20, 'Width'); - assert.equal(this.comment.getHeight(), 10, 'Height'); - }); - - test('setWidth does not affect height', function () { - this.comment.setWidth(30); - assert.equal(this.comment.getWidth(), 30, 'Width'); - assert.equal(this.comment.getHeight(), 10, 'Height'); - }); - - test('setHeight does not affect width', function () { - this.comment.setHeight(30); - assert.equal(this.comment.getWidth(), 20, 'Width'); - assert.equal(this.comment.getHeight(), 30, 'Height'); - }); - }); - - suite('XY position', function () { - setup(function () { - this.comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 10, - 20, - 'comment id', - ); - }); - - test('Initial position', function () { - const xy = this.comment.getRelativeToSurfaceXY(); - assert.equal(xy.x, 0, 'Initial X position'); - assert.equal(xy.y, 0, 'Initial Y position'); - }); - - test('moveBy', function () { - this.comment.moveBy(10, 100); - const xy = this.comment.getRelativeToSurfaceXY(); - assert.equal(xy.x, 10, 'New X position'); - assert.equal(xy.y, 100, 'New Y position'); - }); - }); - - suite('Content', function () { - setup(function () { - this.comment = new Blockly.WorkspaceComment( - this.workspace, - 'comment text', - 0, - 0, - 'comment id', - ); - }); - - teardown(function () { - sinon.restore(); - }); - - test('After creation', function () { - assert.equal(this.comment.getContent(), 'comment text'); - assert.equal(this.workspace.undoStack_.length, 1, 'Workspace undo stack'); - }); - - test('Set to same value', function () { - this.comment.setContent('comment text'); - assert.equal(this.comment.getContent(), 'comment text'); - // Setting the text to the old value does not fire an event. - assert.equal(this.workspace.undoStack_.length, 1, 'Workspace undo stack'); - }); - - test('Set to different value', function () { - this.comment.setContent('new comment text'); - assert.equal(this.comment.getContent(), 'new comment text'); - assert.equal(this.workspace.undoStack_.length, 2, 'Workspace undo stack'); - }); - }); -}); diff --git a/packages/blockly/tests/mocha/rendered_workspace_comment_test.js b/packages/blockly/tests/mocha/rendered_workspace_comment_test.js new file mode 100644 index 00000000000..1e29ed0b500 --- /dev/null +++ b/packages/blockly/tests/mocha/rendered_workspace_comment_test.js @@ -0,0 +1,198 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import {assert} from 'chai'; +import { + assertEventFired, + createChangeListenerSpy, +} from './test_helpers/events.js'; +import { + DEFAULT_INJECT_OPTIONS, + sharedTestSetup, + sharedTestTeardown, +} from './test_helpers/setup_teardown.js'; + +suite('Workspace comment', function () { + setup(function () { + this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock; + this.workspace = new Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); + }); + + teardown(function () { + sharedTestTeardown.call(this); + }); + + suite('Events', function () { + test('create events are fired when a comment is constructed', function () { + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentCreate, + {commentId: this.renderedComment.id}, + this.workspace.id, + ); + }); + + test('delete events are fired when a comment is disposed', function () { + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.dispose(); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentDelete, + {commentId: this.renderedComment.id}, + 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)); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentMove, + { + commentId: this.renderedComment.id, + oldCoordinate_: {x: 0, y: 0}, + newCoordinate_: {x: 42, y: 42}, + }, + this.workspace.id, + ); + }); + + 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, + ); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.setText('test text'); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentChange, + { + commentId: this.renderedComment.id, + oldContents_: '', + newContents_: 'test text', + }, + this.workspace.id, + ); + }); + + test('collapse events are fired when a comment is collapsed', function () { + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.setCollapsed(true); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentCollapse, + { + commentId: this.renderedComment.id, + newCollapsed: true, + }, + this.workspace.id, + ); + }); + + test('collapse events are fired when a comment is uncollapsed', function () { + this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + this.renderedComment.setCollapsed(true); + const spy = createChangeListenerSpy(this.workspace); + + this.renderedComment.setCollapsed(false); + + this.clock.runAll(); + + assertEventFired( + spy, + Blockly.Events.CommentCollapse, + { + commentId: this.renderedComment.id, + newCollapsed: false, + }, + this.workspace.id, + ); + }); + }); + + suite('Focus', function () { + test('moves to the workspace when deleted', function () { + const comment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + Blockly.getFocusManager().focusNode(comment); + assert.equal(Blockly.getFocusManager().getFocusedNode(), comment); + comment.view.getCommentBarButtons()[1].performAction(); + assert.equal(Blockly.getFocusManager().getFocusedNode(), this.workspace); + }); + + test('does not change the layer', function () { + const comment = new Blockly.comments.RenderedWorkspaceComment( + this.workspace, + ); + + this.workspace.getLayerManager()?.moveToDragLayer(comment); + Blockly.getFocusManager().focusNode(comment); + assert.equal( + comment.getSvgRoot().parentElement, + this.workspace.getLayerManager()?.getDragLayer(), + ); + }); + }); +}); diff --git a/packages/blockly/tests/mocha/workspace_comment_test.js b/packages/blockly/tests/mocha/workspace_comment_test.js index 1e29ed0b500..3475f779611 100644 --- a/packages/blockly/tests/mocha/workspace_comment_test.js +++ b/packages/blockly/tests/mocha/workspace_comment_test.js @@ -1,197 +1,209 @@ /** * @license - * Copyright 2024 Google LLC + * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import {assert} from 'chai'; import { - assertEventFired, - createChangeListenerSpy, -} from './test_helpers/events.js'; -import { - DEFAULT_INJECT_OPTIONS, sharedTestSetup, sharedTestTeardown, } from './test_helpers/setup_teardown.js'; suite('Workspace comment', function () { setup(function () { - this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock; - this.workspace = new Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); + sharedTestSetup.call(this); + this.workspace = new Blockly.Workspace(); }); teardown(function () { sharedTestTeardown.call(this); }); - suite('Events', function () { - test('create events are fired when a comment is constructed', function () { - const spy = createChangeListenerSpy(this.workspace); + suite('getTopComments(ordered=true)', function () { + test('No comments', function () { + assert.equal(this.workspace.getTopComments(true).length, 0); + }); - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + test('One comment', function () { + const comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); + assert.equal(this.workspace.getTopComments(true).length, 1); + assert.equal(this.workspace.getCommentById('comment id'), comment); + }); - this.clock.runAll(); + test('After clear empty workspace', function () { + this.workspace.clear(); + assert.equal(this.workspace.getTopComments(true).length, 0); + }); - assertEventFired( - spy, - Blockly.Events.CommentCreate, - {commentId: this.renderedComment.id}, - this.workspace.id, - ); + test('After clear non-empty workspace', function () { + new Blockly.comments.WorkspaceComment(this.workspace, 'comment id'); + this.workspace.clear(); + assert.equal(this.workspace.getTopComments(true).length, 0); + assert.isNull(this.workspace.getCommentById('comment id')); }); - test('delete events are fired when a comment is disposed', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + test('After dispose', function () { + const comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - const spy = createChangeListenerSpy(this.workspace); - - this.renderedComment.dispose(); - - this.clock.runAll(); + comment.dispose(); + assert.equal(this.workspace.getTopComments(true).length, 0); + assert.isNull(this.workspace.getCommentById('comment id')); + }); + }); - assertEventFired( - spy, - Blockly.Events.CommentDelete, - {commentId: this.renderedComment.id}, - this.workspace.id, - ); + suite('getTopComments(ordered=false)', function () { + test('No comments', function () { + assert.equal(this.workspace.getTopComments(false).length, 0); }); - test('move events are fired when a comment is moved', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + test('One comment', function () { + const comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - const spy = createChangeListenerSpy(this.workspace); + assert.equal(this.workspace.getTopComments(false).length, 1); + assert.equal(this.workspace.getCommentById('comment id'), comment); + }); - this.renderedComment.moveTo(new Blockly.utils.Coordinate(42, 42)); + test('After clear empty workspace', function () { + this.workspace.clear(); + assert.equal(this.workspace.getTopComments(false).length, 0); + }); - this.clock.runAll(); + test('After clear non-empty workspace', function () { + new Blockly.comments.WorkspaceComment(this.workspace, 'comment id'); + this.workspace.clear(); + assert.equal(this.workspace.getTopComments(false).length, 0); + assert.isNull(this.workspace.getCommentById('comment id')); + }); - assertEventFired( - spy, - Blockly.Events.CommentMove, - { - commentId: this.renderedComment.id, - oldCoordinate_: {x: 0, y: 0}, - newCoordinate_: {x: 42, y: 42}, - }, - this.workspace.id, + test('After dispose', function () { + const comment = new Blockly.comments.WorkspaceComment( + this.workspace, + 'comment id', ); + comment.dispose(); + assert.equal(this.workspace.getTopComments(false).length, 0); + assert.isNull(this.workspace.getCommentById('comment id')); }); + }); - test('resize events are fired when a comment is resized', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + suite('getCommentById', function () { + test('Trivial', function () { + const comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - const spy = createChangeListenerSpy(this.workspace); + assert.equal(this.workspace.getCommentById(comment.id), comment); + }); - this.renderedComment.setSize(new Blockly.utils.Size(300, 200)); + test('Null id', function () { + assert.isNull(this.workspace.getCommentById(null)); + }); - this.clock.runAll(); + test('Non-existent id', function () { + assert.isNull(this.workspace.getCommentById('badId')); + }); - assertEventFired( - spy, - Blockly.Events.CommentResize, - { - commentId: this.renderedComment.id, - oldSize: {width: 120, height: 100}, - newSize: {width: 300, height: 200}, - }, - this.workspace.id, + test('After dispose', function () { + const comment = new Blockly.comments.WorkspaceComment( + this.workspace, + 'comment id', ); + comment.dispose(); + assert.isNull(this.workspace.getCommentById(comment.id)); }); + }); - test('change events are fired when a comments text is edited', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + suite('Width and height', function () { + setup(function () { + this.comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - const spy = createChangeListenerSpy(this.workspace); - - this.renderedComment.setText('test text'); + this.comment.setSize(new Blockly.utils.Size(20, 10)); + }); - this.clock.runAll(); + test('Initial values', function () { + assert.equal(this.comment.getSize().width, 20, 'Width'); + assert.equal(this.comment.getSize().height, 10, 'Height'); + }); - assertEventFired( - spy, - Blockly.Events.CommentChange, - { - commentId: this.renderedComment.id, - oldContents_: '', - newContents_: 'test text', - }, - this.workspace.id, - ); + test('setSize adjusts dimensions', function () { + this.comment.setSize(new Blockly.utils.Size(100, 200)); + assert.equal(this.comment.getSize().width, 100, 'Width'); + assert.equal(this.comment.getSize().height, 200, 'Height'); }); + }); - test('collapse events are fired when a comment is collapsed', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + suite('XY position', function () { + setup(function () { + this.comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - const spy = createChangeListenerSpy(this.workspace); - - this.renderedComment.setCollapsed(true); + }); - this.clock.runAll(); + test('Initial position', function () { + const xy = this.comment.getRelativeToSurfaceXY(); + assert.equal(xy.x, 0, 'Initial X position'); + assert.equal(xy.y, 0, 'Initial Y position'); + }); - assertEventFired( - spy, - Blockly.Events.CommentCollapse, - { - commentId: this.renderedComment.id, - newCollapsed: true, - }, - this.workspace.id, - ); + test('moveTo', function () { + this.comment.moveTo(new Blockly.utils.Coordinate(10, 100)); + const xy = this.comment.getRelativeToSurfaceXY(); + assert.equal(xy.x, 10, 'New X position'); + assert.equal(xy.y, 100, 'New Y position'); }); + }); - test('collapse events are fired when a comment is uncollapsed', function () { - this.renderedComment = new Blockly.comments.RenderedWorkspaceComment( + suite('Content', function () { + setup(function () { + this.comment = new Blockly.comments.WorkspaceComment( this.workspace, + 'comment id', ); - this.renderedComment.setCollapsed(true); - const spy = createChangeListenerSpy(this.workspace); - - this.renderedComment.setCollapsed(false); - - this.clock.runAll(); + this.comment.setText('comment text'); + }); - assertEventFired( - spy, - Blockly.Events.CommentCollapse, - { - commentId: this.renderedComment.id, - newCollapsed: false, - }, - this.workspace.id, - ); + teardown(function () { + sinon.restore(); }); - }); - suite('Focus', function () { - test('moves to the workspace when deleted', function () { - const comment = new Blockly.comments.RenderedWorkspaceComment( - this.workspace, + test('After creation', function () { + assert.equal(this.comment.getText(), 'comment text'); + assert.equal( + this.workspace.getUndoStack().length, + 2, + 'Workspace undo stack', ); - Blockly.getFocusManager().focusNode(comment); - assert.equal(Blockly.getFocusManager().getFocusedNode(), comment); - comment.view.getCommentBarButtons()[1].performAction(); - assert.equal(Blockly.getFocusManager().getFocusedNode(), this.workspace); }); - test('does not change the layer', function () { - const comment = new Blockly.comments.RenderedWorkspaceComment( - this.workspace, + test('Set to same value', function () { + this.comment.setText('comment text'); + assert.equal(this.comment.getText(), 'comment text'); + // Setting the text to the old value does not fire an event. + assert.equal( + this.workspace.getUndoStack().length, + 2, + 'Workspace undo stack', ); + }); - this.workspace.getLayerManager()?.moveToDragLayer(comment); - Blockly.getFocusManager().focusNode(comment); + test('Set to different value', function () { + this.comment.setText('new comment text'); + assert.equal(this.comment.getText(), 'new comment text'); assert.equal( - comment.getSvgRoot().parentElement, - this.workspace.getLayerManager()?.getDragLayer(), + this.workspace.getUndoStack().length, + 3, + 'Workspace undo stack', ); }); }); diff --git a/packages/blockly/tests/mocha/workspace_svg_test.js b/packages/blockly/tests/mocha/workspace_svg_test.js index 6fe2edbd7a7..57c6b6566e7 100644 --- a/packages/blockly/tests/mocha/workspace_svg_test.js +++ b/packages/blockly/tests/mocha/workspace_svg_test.js @@ -262,12 +262,6 @@ suite('WorkspaceSvg', function () { expectedProperties, workspace.id, ); - assertEventFired( - spy, - Blockly.Events.ViewportChange, - expectedProperties, - workspace.id, - ); } function assertViewportEventFired( changeListenerSpy, @@ -473,8 +467,7 @@ suite('WorkspaceSvg', function () { {type: EventType.VIEWPORT_CHANGE}, ); }); - test.skip('domToWorkspace multiple blocks triggers one viewport event', function () { - // TODO: Un-skip after adding filtering for consecutive viewport events. + test('domToWorkspace multiple blocks triggers one viewport event', function () { const addingMultipleBlocks = () => { Blockly.Xml.domToWorkspace( Blockly.utils.xml.textToDom( @@ -482,7 +475,7 @@ suite('WorkspaceSvg', function () { '' + '' + '' + - '' + + '' + '', ), this.workspace, @@ -623,8 +616,7 @@ suite('WorkspaceSvg', function () { assert.blockIsAtNotOrigin(allBlocks[1]); // Child block. }); - // TODO(#8676): Reenable once test passes reliably. - test.skip('two blocks first at (10, 15) second at (0, 0) do not switch places', function () { + test('two blocks first at (10, 15) second at (0, 0) do not switch places', function () { const blockJson1 = { 'type': 'math_number', 'id': 'block1', @@ -650,8 +642,7 @@ suite('WorkspaceSvg', function () { assert.blockIsBelow(block1, block2); }); - // TODO(#8676): Reenable once test passes reliably. - test.skip('two overlapping blocks are moved to origin and below', function () { + test('two overlapping blocks are moved to origin and below', function () { const blockJson1 = { 'type': 'math_number', 'id': 'block1', @@ -711,8 +702,7 @@ suite('WorkspaceSvg', function () { assert.blockIsBelow(block2, block1); }); - // TODO(#8676): Reenable once test passes reliably. - test.skip('two overlapping blocks are moved to origin and below including children', function () { + test('two overlapping blocks are moved to origin and below including children', function () { const blockJson1 = { 'type': 'logic_negate', 'id': 'block1', @@ -768,8 +758,7 @@ suite('WorkspaceSvg', function () { assert.blockIsBelow(block2Child, block1); }); - // TODO(#8676): Reenable once test passes reliably. - test.skip('two large overlapping blocks are moved to origin and below', function () { + test('two large overlapping blocks are moved to origin and below', function () { const blockJson1 = { 'type': 'controls_repeat_ext', 'id': 'block1', diff --git a/packages/plugins/shadow-block-converter/test/shadow_block_converter_test.mocha.js b/packages/plugins/shadow-block-converter/test/shadow_block_converter_test.mocha.js index 97dc3a73f5a..0c5cf3317b0 100644 --- a/packages/plugins/shadow-block-converter/test/shadow_block_converter_test.mocha.js +++ b/packages/plugins/shadow-block-converter/test/shadow_block_converter_test.mocha.js @@ -38,6 +38,7 @@ suite('shadowBlockConversionChangeListener', function () { ); // See https://github.com/RaspberryPiFoundation/blockly-samples/issues/2528 for context. global.SVGElement = window.SVGElement; + global.FocusEvent = window.FocusEvent; this.workspace = Blockly.inject('blocklyDiv', { media: 'media/', @@ -93,8 +94,7 @@ suite('shadowBlockConversionChangeListener', function () { assert.isTrue(connection.targetBlock().isShadow()); }); - // TODO(#2535): This test requires the focus manager to work correctly - test.skip('undo shadow change', function () { + test('undo shadow change', function () { const connection = makeEmptyConnection(this.workspace); const shadowBlock = attachShadowBlock(connection, { type: 'text', @@ -118,8 +118,7 @@ suite('shadowBlockConversionChangeListener', function () { ); }); - // TODO(#2535): This test requires the focus manager to work correctly - test.skip('redo shadow change', function () { + test('redo shadow change', function () { const connection = makeEmptyConnection(this.workspace); const shadowBlock = attachShadowBlock(connection, { type: 'text', @@ -156,8 +155,7 @@ suite('shadowBlockConversionChangeListener', function () { ); }); - // TODO(#2535): This test requires the focus manager to work correctly - test.skip('preserves original shadow state after undo and redo', function () { + test('preserves original shadow state after undo and redo', function () { const connection = makeEmptyConnection(this.workspace); const shadowState = {type: 'text', id: '123', fields: {TEXT: 'abc'}}; const shadowBlock = attachShadowBlock(connection, shadowState); @@ -228,9 +226,8 @@ suite('shadowBlockConversionChangeListener', function () { ); }); - // TODO(#2535): These tests require the focus manager to work correctly - suite.skip('Selection', function () { - test('Transfers selection to new block', function () { + suite('Selection', function () { + test('Transfers selection to new block', async function () { const connection = this.workspace.newBlock('text_reverse').inputList[0].connection; const shadowBlock = attachShadowBlock(connection, {type: 'text'}); @@ -250,6 +247,8 @@ suite('shadowBlockConversionChangeListener', function () { 'Expected modifed block to no longer be a shadow', ); + await Blockly.renderManagement.finishQueuedRenders(); + // The replacement block should now be selected. assert.isTrue( Blockly.common.getSelected() === connection.targetBlock(), diff --git a/packages/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js b/packages/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js index 2c9c931791c..4200854d7a3 100644 --- a/packages/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js +++ b/packages/plugins/typed-variable-modal/test/typed_variable_modal_test.mocha.js @@ -96,7 +96,7 @@ suite('TypedVariableModal', function () { // plugins each getting separate copies of Blockly due to updates // to dev-tool's webpack.config.js in RaspberryPiFoundation/blockly-samples#2228 // to support having an exports stanza in Blockly's package.json. - test.skip('Elements focused', function () { + test('Elements focused', function () { this.typedVarModal.init(); this.typedVarModal.show(); assert.equal(