From 07663706ee9a6fa8a317086c7f2cd02f7976dd06 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Tue, 1 Mar 2022 20:15:33 +0000 Subject: [PATCH] fix: split variable helper into new file --- tests/deps.mocha.js | 13 ++++++------ tests/mocha/event_test.js | 3 ++- tests/mocha/test_helpers/test_helpers.js | 17 ---------------- tests/mocha/test_helpers/variables.js | 25 ++++++++++++++++++++++++ tests/mocha/test_helpers/workspace.js | 3 ++- tests/mocha/theme_test.js | 2 +- tests/mocha/variable_map_test.js | 3 ++- tests/mocha/workspace_svg_test.js | 3 ++- tests/mocha/workspace_test.js | 3 ++- tests/mocha/xml_test.js | 3 ++- 10 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 tests/mocha/test_helpers/variables.js diff --git a/tests/deps.mocha.js b/tests/deps.mocha.js index 4ed69ef49..4c7cf6d02 100644 --- a/tests/deps.mocha.js +++ b/tests/deps.mocha.js @@ -11,7 +11,7 @@ goog.addDependency('../../tests/mocha/connection_test.js', ['Blockly.test.connec goog.addDependency('../../tests/mocha/contextmenu_items_test.js', ['Blockly.test.contextMenuItem'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/cursor_test.js', ['Blockly.test.cursor'], ['Blockly.ASTNode', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/dropdowndiv_test.js', ['Blockly.test.dropdown'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/event_test.js', ['Blockly.test.event'], ['Blockly.ASTNode', 'Blockly.Events.utils', 'Blockly.WorkspaceComment', 'Blockly.test.helpers', 'Blockly.test.helpers.events'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/event_test.js', ['Blockly.test.event'], ['Blockly.ASTNode', 'Blockly.Events.utils', 'Blockly.WorkspaceComment', 'Blockly.test.helpers', 'Blockly.test.helpers.events', 'Blockly.test.helpers.variables'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/extensions_test.js', ['Blockly.test.extensions'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/field_angle_test.js', ['Blockly.test.fieldAngle'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.fields'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/field_checkbox_test.js', ['Blockly.test.fieldCheckbox'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.fields'], {'lang': 'es6', 'module': 'goog'}); @@ -54,19 +54,20 @@ goog.addDependency('../../tests/mocha/test_helpers/serialization.js', ['Blockly. goog.addDependency('../../tests/mocha/test_helpers/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/toolbox_definitions.js', ['Blockly.test.helpers.toolbox_definitions'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/user_input.js', ['Blockly.test.helpers.userInput'], ['Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/test_helpers/variables.js', ['Blockly.test.helpers.variables'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/warnings.js', ['Blockly.test.helpers.warnings'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers.common', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.variables', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.events'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/toolbox_test.js', ['Blockly.test.toolbox'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.toolbox_definitions'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/tooltip_test.js', ['Blockly.test.tooltip'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/trashcan_test.js', ['Blockly.test.trashcan'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.events', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/utils_test.js', ['Blockly.test.utils'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/variable_map_test.js', ['Blockly.test.variableMap'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/variable_map_test.js', ['Blockly.test.variableMap'], ['Blockly.test.helpers', 'Blockly.test.helpers.variables'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/variable_model_test.js', ['Blockly.test.variableModel'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/variables_test.js', ['Blockly.test.variables'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/widget_div_test.js', ['Blockly.test.widgetDiv'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/workspace_comment_test.js', ['Blockly.test.workspaceComment'], ['Blockly.WorkspaceComment', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/workspace_svg_test.js', ['Blockly.test.workspaceSvg'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.events', 'Blockly.test.helpers.workspace'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/workspace_test.js', ['Blockly.test.workspace'], ['Blockly.test.helpers', 'Blockly.test.helpers.workspace'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/xml_test.js', ['Blockly.test.xml'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/workspace_svg_test.js', ['Blockly.test.workspaceSvg'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.events', 'Blockly.test.helpers.variables', 'Blockly.test.helpers.workspace'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/workspace_test.js', ['Blockly.test.workspace'], ['Blockly.test.helpers', 'Blockly.test.helpers.variables', 'Blockly.test.helpers.workspace'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/xml_test.js', ['Blockly.test.xml'], ['Blockly.test.helpers', 'Blockly.test.helpers.variables'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/zoom_controls_test.js', ['Blockly.test.zoomControls'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.events', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'}); diff --git a/tests/mocha/event_test.js b/tests/mocha/event_test.js index 3eae28604..13edc698a 100644 --- a/tests/mocha/event_test.js +++ b/tests/mocha/event_test.js @@ -7,8 +7,9 @@ goog.module('Blockly.test.event'); const {ASTNode} = goog.require('Blockly.ASTNode'); -const {assertVariableValues, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); const {assertEventEquals, assertNthCallEventArgEquals, createFireChangeListenerSpy} = goog.require('Blockly.test.helpers.events'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); +const {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); const eventUtils = goog.require('Blockly.Events.utils'); goog.require('Blockly.WorkspaceComment'); diff --git a/tests/mocha/test_helpers/test_helpers.js b/tests/mocha/test_helpers/test_helpers.js index a0b25e0a0..e6c84a8df 100644 --- a/tests/mocha/test_helpers/test_helpers.js +++ b/tests/mocha/test_helpers/test_helpers.js @@ -10,23 +10,6 @@ const eventUtils = goog.require('Blockly.Events.utils'); const {Blocks} = goog.require('Blockly.blocks'); -/** - * Check if a variable with the given values exists. - * @param {Blockly.Workspace|Blockly.VariableMap} container The workspace or - * variableMap the checked variable belongs to. - * @param {!string} name The expected name of the variable. - * @param {!string} type The expected type of the variable. - * @param {!string} id The expected id of the variable. - */ -function assertVariableValues(container, name, type, id) { - const variable = container.getVariableById(id); - chai.assert.isDefined(variable); - chai.assert.equal(variable.name, name); - chai.assert.equal(variable.type, type); - chai.assert.equal(variable.getId(), id); -} -exports.assertVariableValues = assertVariableValues; - /** * Safely disposes of Blockly workspace, logging any errors. * Assumes that sharedTestSetup has also been called. This should be called diff --git a/tests/mocha/test_helpers/variables.js b/tests/mocha/test_helpers/variables.js new file mode 100644 index 000000000..0429c4372 --- /dev/null +++ b/tests/mocha/test_helpers/variables.js @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +goog.module('Blockly.test.helpers.variables'); + + +/** + * Check if a variable with the given values exists. + * @param {Blockly.Workspace|Blockly.VariableMap} container The workspace or + * variableMap the checked variable belongs to. + * @param {!string} name The expected name of the variable. + * @param {!string} type The expected type of the variable. + * @param {!string} id The expected id of the variable. + */ +function assertVariableValues(container, name, type, id) { + const variable = container.getVariableById(id); + chai.assert.isDefined(variable); + chai.assert.equal(variable.name, name); + chai.assert.equal(variable.type, type); + chai.assert.equal(variable.getId(), id); +} +exports.assertVariableValues = assertVariableValues; \ No newline at end of file diff --git a/tests/mocha/test_helpers/workspace.js b/tests/mocha/test_helpers/workspace.js index cf4d9e7d6..638616b8f 100644 --- a/tests/mocha/test_helpers/workspace.js +++ b/tests/mocha/test_helpers/workspace.js @@ -6,9 +6,10 @@ goog.module('Blockly.test.helpers.workspace'); -const {assertVariableValues, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); const {assertWarnings} = goog.require('Blockly.test.helpers.warnings'); const eventUtils = goog.require('Blockly.Events.utils'); +const {workspaceTeardown} = goog.require('Blockly.test.helpers'); function testAWorkspace() { diff --git a/tests/mocha/theme_test.js b/tests/mocha/theme_test.js index b909d752e..ba98d6aa7 100644 --- a/tests/mocha/theme_test.js +++ b/tests/mocha/theme_test.js @@ -6,8 +6,8 @@ goog.module('Blockly.test.theme'); -const eventUtils = goog.require('Blockly.Events.utils'); const {assertEventFired} = goog.require('Blockly.test.helpers.events'); +const eventUtils = goog.require('Blockly.Events.utils'); const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); diff --git a/tests/mocha/variable_map_test.js b/tests/mocha/variable_map_test.js index b86d4e4fd..969b9d1cd 100644 --- a/tests/mocha/variable_map_test.js +++ b/tests/mocha/variable_map_test.js @@ -6,7 +6,8 @@ goog.module('Blockly.test.variableMap'); -const {assertVariableValues, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); +const {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); suite('Variable Map', function() { diff --git a/tests/mocha/workspace_svg_test.js b/tests/mocha/workspace_svg_test.js index 86778e5d9..626986e20 100644 --- a/tests/mocha/workspace_svg_test.js +++ b/tests/mocha/workspace_svg_test.js @@ -7,8 +7,9 @@ goog.module('Blockly.test.workspaceSvg'); const {assertEventFired, assertEventNotFired, createFireChangeListenerSpy} = goog.require('Blockly.test.helpers.events'); -const {assertVariableValues, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); const {defineStackBlock} = goog.require('Blockly.test.helpers.blockDefinitions'); +const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); const {testAWorkspace} = goog.require('Blockly.test.helpers.workspace'); diff --git a/tests/mocha/workspace_test.js b/tests/mocha/workspace_test.js index 4d0c9c61a..5684ae7dd 100644 --- a/tests/mocha/workspace_test.js +++ b/tests/mocha/workspace_test.js @@ -6,7 +6,8 @@ goog.module('Blockly.test.workspace'); -const {assertVariableValues, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); +const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); const {testAWorkspace} = goog.require('Blockly.test.helpers.workspace'); diff --git a/tests/mocha/xml_test.js b/tests/mocha/xml_test.js index 7354d6370..fc686bcb1 100644 --- a/tests/mocha/xml_test.js +++ b/tests/mocha/xml_test.js @@ -6,7 +6,8 @@ goog.module('Blockly.test.xml'); -const {addBlockTypeToCleanup, assertVariableValues, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {addBlockTypeToCleanup, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); suite('XML', function() {