Skip to content

Commit

Permalink
fix(tests): Make test imports correct and more consistent (#7260)
Browse files Browse the repository at this point in the history
* 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 extends IIcon>(/* ... */): 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.
  • Loading branch information
cpcallen authored Jul 7, 2023
1 parent 07ba841 commit aefb97d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
4 changes: 1 addition & 3 deletions tests/mocha/comment_deserialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions tests/mocha/contextmenu_items_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions tests/mocha/field_multilineinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
10 changes: 5 additions & 5 deletions tests/mocha/generator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions tests/mocha/xml_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand All @@ -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');
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit aefb97d

Please sign in to comment.