From aefb97d7801f1efc014d6f68aeb95dfc1a37ffe1 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 7 Jul 2023 17:15:03 +0100 Subject: [PATCH] fix(tests): Make test `import`s correct and more consistent (#7260) * fix(tests): Fix invalid import paths in mocha tests This resolves the warnings generated during buildDeps by closure-make-deps. This commit does not attempt to address #7224 or otherwise rationalise the imports and usage thereof. * fix(tests): Fix failing context menu item test Test appears to have been wrong: Block.prototype.getIcon is typed as getIcon(/* ... */): T | undefined and documented as "@returns The icon with the given type if it exists on the block, undefined otherwise." * refactor(tests): Clean up inconsistent usage of CommentIcon Tweak the test files touched by PR #7200 to be consistent with existing usage of Blockly.icons.CommentIcon instead of importing this separately. --- tests/mocha/comment_deserialization_test.js | 4 +--- tests/mocha/contextmenu_items_test.js | 7 +++---- tests/mocha/field_multilineinput_test.js | 10 +++++----- tests/mocha/generator_test.js | 10 +++++----- tests/mocha/xml_test.js | 11 ++++++----- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/tests/mocha/comment_deserialization_test.js b/tests/mocha/comment_deserialization_test.js index 08fe164b3..4adba246f 100644 --- a/tests/mocha/comment_deserialization_test.js +++ b/tests/mocha/comment_deserialization_test.js @@ -10,7 +10,6 @@ import { sharedTestSetup, sharedTestTeardown, } from './test_helpers/setup_teardown.js'; -import {CommentIcon} from '../../core/icons/comment_icon.js'; import {simulateClick} from './test_helpers/user_input.js'; suite('Comment Deserialization', function () { @@ -62,8 +61,7 @@ suite('Comment Deserialization', function () { const icon = block.getIcon(Blockly.icons.CommentIcon.TYPE); icon.setBubbleVisible(true); // Check comment bubble size. - const comment = block.getIcon(CommentIcon.TYPE); - const bubbleSize = comment.getBubbleSize(); + const bubbleSize = icon.getBubbleSize(); chai.assert.isNotNaN(bubbleSize.width); chai.assert.isNotNaN(bubbleSize.height); chai.assert.equal(icon.getText(), text); diff --git a/tests/mocha/contextmenu_items_test.js b/tests/mocha/contextmenu_items_test.js index 4c551742b..566b33748 100644 --- a/tests/mocha/contextmenu_items_test.js +++ b/tests/mocha/contextmenu_items_test.js @@ -11,7 +11,6 @@ import { sharedTestTeardown, workspaceTeardown, } from './test_helpers/setup_teardown.js'; -import {CommentIcon} from '../../core/icons/comment_icon.js'; suite('Context Menu Items', function () { setup(function () { @@ -459,12 +458,12 @@ suite('Context Menu Items', function () { }); test('Creates comment if one did not exist', function () { - chai.assert.isNull( - this.block.getIcon(CommentIcon.TYPE), + chai.assert.isUndefined( + this.block.getIcon(Blockly.icons.CommentIcon.TYPE), 'New block should not have a comment' ); this.commentOption.callback(this.scope); - chai.assert.exists(this.block.getIcon(CommentIcon.TYPE)); + chai.assert.exists(this.block.getIcon(Blockly.icons.CommentIcon.TYPE)); chai.assert.isEmpty( this.block.getCommentText(), 'Block should have empty comment text' diff --git a/tests/mocha/field_multilineinput_test.js b/tests/mocha/field_multilineinput_test.js index cf1102f3e..8daaad828 100644 --- a/tests/mocha/field_multilineinput_test.js +++ b/tests/mocha/field_multilineinput_test.js @@ -23,11 +23,11 @@ import { workspaceTeardown, } from './test_helpers/setup_teardown.js'; import {runCodeGenerationTestSuites} from './test_helpers/code_generation.js'; -import {dartGenerator} from '../../generators/dart.js'; -import {javascriptGenerator} from '../../generators/javascript.js'; -import {luaGenerator} from '../../generators/lua.js'; -import {phpGenerator} from '../../generators/php.js'; -import {pythonGenerator} from '../../generators/python.js'; +import {dartGenerator} from '../../build/src/generators/dart.js'; +import {javascriptGenerator} from '../../build/src/generators/javascript.js'; +import {luaGenerator} from '../../build/src/generators/lua.js'; +import {phpGenerator} from '../../build/src/generators/php.js'; +import {pythonGenerator} from '../../build/src/generators/python.js'; suite('Multiline Input Fields', function () { setup(function () { diff --git a/tests/mocha/generator_test.js b/tests/mocha/generator_test.js index 60f6190dc..a60c0cd86 100644 --- a/tests/mocha/generator_test.js +++ b/tests/mocha/generator_test.js @@ -7,11 +7,11 @@ goog.declareModuleId('Blockly.test.generator'); import * as Blockly from '../../build/src/core/blockly.js'; -import {DartGenerator} from '../../generators/dart/dart_generator.js'; -import {JavascriptGenerator} from '../../generators/javascript/javascript_generator.js'; -import {LuaGenerator} from '../../generators/lua/lua_generator.js'; -import {PhpGenerator} from '../../generators/php/php_generator.js'; -import {PythonGenerator} from '../../generators/python/python_generator.js'; +import {DartGenerator} from '../../build/src/generators/dart/dart_generator.js'; +import {JavascriptGenerator} from '../../build/src/generators/javascript/javascript_generator.js'; +import {LuaGenerator} from '../../build/src/generators/lua/lua_generator.js'; +import {PhpGenerator} from '../../build/src/generators/php/php_generator.js'; +import {PythonGenerator} from '../../build/src/generators/python/python_generator.js'; import { sharedTestSetup, sharedTestTeardown, diff --git a/tests/mocha/xml_test.js b/tests/mocha/xml_test.js index fe4c75050..948d6cd0c 100644 --- a/tests/mocha/xml_test.js +++ b/tests/mocha/xml_test.js @@ -13,7 +13,6 @@ import { sharedTestTeardown, workspaceTeardown, } from './test_helpers/setup_teardown.js'; -import {CommentIcon} from '../../core/icons/comment_icon.js'; import {assertVariableValues} from './test_helpers/variables.js'; suite('XML', function () { @@ -443,7 +442,7 @@ suite('XML', function () { test('Size', function () { this.block.setCommentText('test text'); this.block - .getIcon(CommentIcon.TYPE) + .getIcon(Blockly.icons.CommentIcon.TYPE) .setBubbleSize(new Blockly.utils.Size(100, 200)); const xml = Blockly.Xml.blockToDom(this.block); const commentXml = xml.firstChild; @@ -453,7 +452,9 @@ suite('XML', function () { }); test('Pinned True', function () { this.block.setCommentText('test text'); - this.block.getIcon(CommentIcon.TYPE).setBubbleVisible(true); + this.block + .getIcon(Blockly.icons.CommentIcon.TYPE) + .setBubbleVisible(true); const xml = Blockly.Xml.blockToDom(this.block); const commentXml = xml.firstChild; chai.assert.equal(commentXml.tagName, 'comment'); @@ -698,7 +699,7 @@ suite('XML', function () { this.workspace ); chai.assert.equal(block.getCommentText(), 'test text'); - chai.assert.isOk(block.getIcon(CommentIcon.TYPE)); + chai.assert.isOk(block.getIcon(Blockly.icons.CommentIcon.TYPE)); }); test('No Text', function () { const block = Blockly.Xml.domToBlock( @@ -723,7 +724,7 @@ suite('XML', function () { ); chai.assert.isOk(block.getIcon(Blockly.icons.CommentIcon.TYPE)); chai.assert.deepEqual( - block.getIcon(CommentIcon.TYPE).getBubbleSize(), + block.getIcon(Blockly.icons.CommentIcon.TYPE).getBubbleSize(), { width: 100, height: 200,