From e276745b6b5225ff3f5b0a78b8088efab6eb3a6f Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 28 Feb 2022 22:49:30 +0000 Subject: [PATCH] fix: change tests to use local helpers --- tests/deps.mocha.js | 30 ++++++++++---------- tests/mocha/.eslintrc.json | 1 - tests/mocha/field_angle_test.js | 21 +++++++------- tests/mocha/field_checkbox_test.js | 15 +++++----- tests/mocha/field_colour_test.js | 19 +++++++------ tests/mocha/field_dropdown_test.js | 17 +++++------ tests/mocha/field_image_test.js | 15 +++++----- tests/mocha/field_label_serializable_test.js | 17 +++++------ tests/mocha/field_label_test.js | 17 +++++------ tests/mocha/field_multilineinput_test.js | 20 +++++++------ tests/mocha/field_number_test.js | 26 +++++++++-------- tests/mocha/field_textinput_test.js | 21 +++++++------- tests/mocha/field_variable_test.js | 17 +++++------ tests/mocha/index.html | 2 +- tests/mocha/logic_ternary_test.js | 5 ++-- tests/mocha/procedures_test.js | 5 ++-- tests/mocha/serializer_test.js | 9 +++--- tests/mocha/test_helpers/test_helpers.js | 3 +- 18 files changed, 138 insertions(+), 122 deletions(-) diff --git a/tests/deps.mocha.js b/tests/deps.mocha.js index 3c46f7dfc..39f0fdb53 100644 --- a/tests/deps.mocha.js +++ b/tests/deps.mocha.js @@ -13,19 +13,19 @@ goog.addDependency('../../tests/mocha/cursor_test.js', ['Blockly.test.cursor'], 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'], {'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'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_checkbox_test.js', ['Blockly.test.fieldCheckbox'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_colour_test.js', ['Blockly.test.fieldColour'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_dropdown_test.js', ['Blockly.test.fieldDropdown'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_image_test.js', ['Blockly.test.fieldImage'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_label_serializable_test.js', ['Blockly.test.fieldLabelSerialization'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_label_test.js', ['Blockly.test.fieldLabel'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_multilineinput_test.js', ['Blockly.test.fieldMultiline'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_number_test.js', ['Blockly.test.fieldNumber'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_angle_test.js', ['Blockly.test.fieldAngle'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_checkbox_test.js', ['Blockly.test.fieldCheckbox'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_colour_test.js', ['Blockly.test.fieldColour'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_dropdown_test.js', ['Blockly.test.fieldDropdown'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_image_test.js', ['Blockly.test.fieldImage'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_label_serializable_test.js', ['Blockly.test.fieldLabelSerialization'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_label_test.js', ['Blockly.test.fieldLabel'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_multilineinput_test.js', ['Blockly.test.fieldMultiline'], ['Blockly.test.blockHelpers', 'Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_number_test.js', ['Blockly.test.fieldNumber'], ['Blockly.test.commonHelpers', 'Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/field_registry_test.js', ['Blockly.test.fieldRegistry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/field_test.js', ['Blockly.test.fieldTest'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_textinput_test.js', ['Blockly.test.fieldTextInput'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/field_variable_test.js', ['Blockly.test.fieldVariable'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_textinput_test.js', ['Blockly.test.fieldTextInput'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/field_variable_test.js', ['Blockly.test.fieldVariable'], ['Blockly.test.fieldHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/flyout_test.js', ['Blockly.test.flyout'], ['Blockly.test.helpers', 'Blockly.test.toolboxHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/generator_test.js', ['Blockly.test.generator'], ['Blockly.Dart', 'Blockly.JavaScript', 'Blockly.Lua', 'Blockly.PHP', 'Blockly.Python', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/gesture_test.js', ['Blockly.test.gesture'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); @@ -35,20 +35,20 @@ goog.addDependency('../../tests/mocha/jso_deserialization_test.js', ['Blockly.te goog.addDependency('../../tests/mocha/jso_serialization_test.js', ['Blockly.test.jsoSerialization'], ['Blockly.test.helpers'], {'lang': 'es8', 'module': 'goog'}); goog.addDependency('../../tests/mocha/json_test.js', ['Blockly.test.json'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/keydown_test.js', ['Blockly.test.keydown'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/logic_ternary_test.js', ['Blockly.test.logicTernary'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/logic_ternary_test.js', ['Blockly.test.logicTernary'], ['Blockly.Events.utils', 'Blockly.test.blockHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/metrics_test.js', ['Blockly.test.metrics'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/mutator_test.js', ['Blockly.test.mutator'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/names_test.js', ['Blockly.test.names'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/procedures_test.js', ['Blockly.test.procedures'], ['Blockly', 'Blockly.Msg', 'Blockly.test.helpers', 'Blockly.test.procedureHelpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/procedures_test.js', ['Blockly.test.procedures'], ['Blockly', 'Blockly.Msg', 'Blockly.test.blockHelpers', 'Blockly.test.helpers', 'Blockly.test.procedureHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/registry_test.js', ['Blockly.test.registry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/run_mocha_tests_in_browser.js', [], [], {'lang': 'es8'}); -goog.addDependency('../../tests/mocha/serializer_test.js', ['Blockly.test.serialization'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/serializer_test.js', ['Blockly.test.serialization'], ['Blockly.test.commonHelpers', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/shortcut_registry_test.js', ['Blockly.test.shortcutRegistry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/block_test_helpers.mocha.js', ['Blockly.test.blockHelpers'], ['Blockly.test.commonHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/common_test_helpers.mocha.js', ['Blockly.test.commonHelpers'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/field_test_helpers.mocha.js', ['Blockly.test.fieldHelpers'], ['Blockly.test.commonHelpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/procedures_test_helpers.js', ['Blockly.test.procedureHelpers'], ['Blockly.ConnectionType'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/test_helpers/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.commonHelpers', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/test_helpers/toolbox_helper.js', ['Blockly.test.toolboxHelpers'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/toolbox_test.js', ['Blockly.test.toolbox'], ['Blockly.test.helpers', 'Blockly.test.toolboxHelpers'], {'lang': 'es6', 'module': 'goog'}); diff --git a/tests/mocha/.eslintrc.json b/tests/mocha/.eslintrc.json index c42c50c20..156a4d1ff 100644 --- a/tests/mocha/.eslintrc.json +++ b/tests/mocha/.eslintrc.json @@ -6,7 +6,6 @@ "globals": { "chai": false, "sinon": false, - "testHelpers": true }, "rules": { "no-unused-vars": ["off"], diff --git a/tests/mocha/field_angle_test.js b/tests/mocha/field_angle_test.js index 2d3736e67..186f2228f 100644 --- a/tests/mocha/field_angle_test.js +++ b/tests/mocha/field_angle_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldAngle'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -60,7 +61,7 @@ suite('Angle Fields', function() { * @param {FieldTemplate} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue); + assertFieldValue(field, defaultFieldValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -68,14 +69,14 @@ suite('Angle Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldAngle, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldAngle, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -84,12 +85,12 @@ suite('Angle Fields', function() { setup(function() { this.field = new Blockly.FieldAngle(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue(2.5); - testHelpers.assertFieldValue(this.field, 2.5); + assertFieldValue(this.field, 2.5); }); }); suite('Value -> New Value', function() { @@ -97,12 +98,12 @@ suite('Angle Fields', function() { setup(function() { this.field = new Blockly.FieldAngle(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue(2.5); - testHelpers.assertFieldValue(this.field, 2.5); + assertFieldValue(this.field, 2.5); }); }); }); @@ -142,12 +143,12 @@ suite('Angle Fields', function() { this.field.isBeingEdited_ = true; this.field.htmlInput_.value = String(suiteInfo.value); this.field.onHtmlInputChange_(null); - testHelpers.assertFieldValue( + assertFieldValue( this.field, suiteInfo.expectedValue, String(suiteInfo.value)); }); test('When Not Editing', function() { this.field.setValue(suiteInfo.value); - testHelpers.assertFieldValue(this.field, suiteInfo.expectedValue); + assertFieldValue(this.field, suiteInfo.expectedValue); }); }); }); diff --git a/tests/mocha/field_checkbox_test.js b/tests/mocha/field_checkbox_test.js index 2c6b8eeb2..ff5dffc8d 100644 --- a/tests/mocha/field_checkbox_test.js +++ b/tests/mocha/field_checkbox_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldCheckbox'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -61,7 +62,7 @@ suite('Checkbox Fields', function() { * @param {!Blockly.FieldCheckbox} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue( + assertFieldValue( field, defaultFieldValue, defaultFieldValue.toLowerCase()); }; /** @@ -70,15 +71,15 @@ suite('Checkbox Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue( + assertFieldValue( field, testCase.expectedValue, testCase.expectedValue.toLowerCase()); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldCheckbox, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldCheckbox, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -87,14 +88,14 @@ suite('Checkbox Fields', function() { setup(function() { this.field = new Blockly.FieldCheckbox('TRUE'); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, 'TRUE', 'true'); }); suite('False -> New Value', function() { setup(function() { this.field = new Blockly.FieldCheckbox('FALSE'); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, 'FALSE', 'false'); }); }); @@ -131,7 +132,7 @@ suite('Checkbox Fields', function() { }); test('New Value', function() { this.field.setValue(suiteInfo.value); - testHelpers.assertFieldValue( + assertFieldValue( this.field, suiteInfo.expectedValue, String(suiteInfo.expectedValue).toLowerCase()); }); diff --git a/tests/mocha/field_colour_test.js b/tests/mocha/field_colour_test.js index 97fd27c96..86a161c92 100644 --- a/tests/mocha/field_colour_test.js +++ b/tests/mocha/field_colour_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldColour'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -87,7 +88,7 @@ suite('Colour Fields', function() { * @param {FieldTemplate} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue, defaultTextValue); + assertFieldValue(field, defaultFieldValue, defaultTextValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -95,15 +96,15 @@ suite('Colour Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue( + assertFieldValue( field, testCase.expectedValue, testCase.expectedText); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldColour, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldColour, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -112,25 +113,25 @@ suite('Colour Fields', function() { setup(function() { this.field = new Blockly.FieldColour(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue, defaultTextValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('#bcbcbc'); - testHelpers.assertFieldValue(this.field, '#bcbcbc', '#bcbcbc'); + assertFieldValue(this.field, '#bcbcbc', '#bcbcbc'); }); }); suite('Value -> New Value', function() { setup(function() { this.field = new Blockly.FieldColour('#aaaaaa'); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, '#aaaaaa', '#aaa'); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('#bcbcbc'); - testHelpers.assertFieldValue(this.field, '#bcbcbc', '#bcbcbc'); + assertFieldValue(this.field, '#bcbcbc', '#bcbcbc'); }); }); }); @@ -161,7 +162,7 @@ suite('Colour Fields', function() { }); test('New Value', function() { this.field.setValue(suiteInfo.value); - testHelpers.assertFieldValue( + assertFieldValue( this.field, suiteInfo.expectedValue, suiteInfo.expectedText); }); }); diff --git a/tests/mocha/field_dropdown_test.js b/tests/mocha/field_dropdown_test.js index 11b517b6e..3429d9e68 100644 --- a/tests/mocha/field_dropdown_test.js +++ b/tests/mocha/field_dropdown_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldDropdown'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -74,14 +75,14 @@ suite('Dropdown Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText); + assertFieldValue(field, testCase.expectedValue, testCase.expectedText); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldDropdown, validValueCreationTestCases, invalidValueCreationTestCases, validTestCaseAssertField); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldDropdown, validValueCreationTestCases, invalidValueCreationTestCases, validTestCaseAssertField); @@ -107,12 +108,12 @@ suite('Dropdown Fields', function() { this.field = new Blockly.FieldDropdown( [['a', 'A'], ['b', 'B'], ['c', 'C']]); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueSetValueTestCases, invalidValueSetValueTestCases, 'A', 'a'); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('B'); - testHelpers.assertFieldValue(this.field, 'B', 'b'); + assertFieldValue(this.field, 'B', 'b'); }); }); @@ -133,7 +134,7 @@ suite('Dropdown Fields', function() { }); test('New Value', function() { this.dropdownField.setValue('1B'); - testHelpers.assertFieldValue(this.dropdownField, '1A', '1a'); + assertFieldValue(this.dropdownField, '1A', '1a'); }); }); suite('Force 1s Validator', function() { @@ -144,7 +145,7 @@ suite('Dropdown Fields', function() { }); test('New Value', function() { this.dropdownField.setValue('2B'); - testHelpers.assertFieldValue(this.dropdownField, '1B', '1b'); + assertFieldValue(this.dropdownField, '1B', '1b'); }); }); suite('Returns Undefined Validator', function() { @@ -153,7 +154,7 @@ suite('Dropdown Fields', function() { }); test('New Value', function() { this.dropdownField.setValue('1B'); - testHelpers.assertFieldValue(this.dropdownField, '1B', '1b'); + assertFieldValue(this.dropdownField, '1B', '1b'); }); }); }); diff --git a/tests/mocha/field_image_test.js b/tests/mocha/field_image_test.js index fcc68fd67..94f89b1a4 100644 --- a/tests/mocha/field_image_test.js +++ b/tests/mocha/field_image_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldImage'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -56,14 +57,14 @@ suite('Image Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText); + assertFieldValue(field, testCase.expectedValue, testCase.expectedText); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldImage, validValueCreationTestCases, invalidValueTestCases, validTestCaseAssertField); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldImage, validValueCreationTestCases, invalidValueTestCases, validTestCaseAssertField); @@ -80,7 +81,7 @@ suite('Image Fields', function() { setup(function() { this.field = new Blockly.FieldImage('src', 1, 1, 'alt'); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueSetValueTestCases, invalidValueTestCases, 'src', 'alt'); }); @@ -126,15 +127,15 @@ suite('Image Fields', function() { }); test('Null', function() { this.imageField.setAlt(null); - testHelpers.assertFieldValue(this.imageField, 'src', ''); + assertFieldValue(this.imageField, 'src', ''); }); test('Empty String', function() { this.imageField.setAlt(''); - testHelpers.assertFieldValue(this.imageField, 'src', ''); + assertFieldValue(this.imageField, 'src', ''); }); test('Good Alt', function() { this.imageField.setAlt('newAlt'); - testHelpers.assertFieldValue(this.imageField, 'src', 'newAlt'); + assertFieldValue(this.imageField, 'src', 'newAlt'); }); }); test('JS Configuration - Simple', function() { diff --git a/tests/mocha/field_label_serializable_test.js b/tests/mocha/field_label_serializable_test.js index 212173b2a..f4861c9dd 100644 --- a/tests/mocha/field_label_serializable_test.js +++ b/tests/mocha/field_label_serializable_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldLabelSerialization'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -53,7 +54,7 @@ suite('Label Serializable Fields', function() { * @param {!Blockly.FieldLabelSerializable} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue); + assertFieldValue(field, defaultFieldValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -61,14 +62,14 @@ suite('Label Serializable Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldLabelSerializable, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldLabelSerializable, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -77,12 +78,12 @@ suite('Label Serializable Fields', function() { setup(function() { this.field = new Blockly.FieldLabelSerializable(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); suite('Value -> New Value', function() { @@ -90,12 +91,12 @@ suite('Label Serializable Fields', function() { setup(function() { this.field = new Blockly.FieldLabelSerializable(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); }); diff --git a/tests/mocha/field_label_test.js b/tests/mocha/field_label_test.js index 52fedef90..cced8c7d4 100644 --- a/tests/mocha/field_label_test.js +++ b/tests/mocha/field_label_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldLabel'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -53,7 +54,7 @@ suite('Label Fields', function() { * @param {!Blockly.FieldLabel} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue); + assertFieldValue(field, defaultFieldValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -61,14 +62,14 @@ suite('Label Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldLabel, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldLabel, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -77,12 +78,12 @@ suite('Label Fields', function() { setup(function() { this.field = new Blockly.FieldLabel(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); suite('Value -> New Value', function() { @@ -90,12 +91,12 @@ suite('Label Fields', function() { setup(function() { this.field = new Blockly.FieldLabel(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); }); diff --git a/tests/mocha/field_multilineinput_test.js b/tests/mocha/field_multilineinput_test.js index 8283df431..3d65e0746 100644 --- a/tests/mocha/field_multilineinput_test.js +++ b/tests/mocha/field_multilineinput_test.js @@ -6,7 +6,9 @@ goog.module('Blockly.test.fieldMultiline'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {runCodeGenerationTestSuites} = goog.require('Blockly.test.blockHelpers'); suite('Multiline Input Fields', function() { @@ -55,7 +57,7 @@ suite('Multiline Input Fields', function() { * @param {!Blockly.FieldMultilineInput} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue); + assertFieldValue(field, defaultFieldValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -63,14 +65,14 @@ suite('Multiline Input Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldMultilineInput, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldMultilineInput, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -79,12 +81,12 @@ suite('Multiline Input Fields', function() { setup(function() { this.field = new Blockly.FieldMultilineInput(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); suite('Value -> New Value', function() { @@ -92,12 +94,12 @@ suite('Multiline Input Fields', function() { setup(function() { this.field = new Blockly.FieldMultilineInput(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); }); @@ -156,7 +158,7 @@ suite('Multiline Input Fields', function() { createBlock: createBlockFn('bark bark\n bark bark bark\n bark bar bark bark\n')}, ]}, ]; - testHelpers.runCodeGenerationTestSuites(testSuites); + runCodeGenerationTestSuites(testSuites); }); suite('Serialization', function() { diff --git a/tests/mocha/field_number_test.js b/tests/mocha/field_number_test.js index 379bb5b83..4f52fff4f 100644 --- a/tests/mocha/field_number_test.js +++ b/tests/mocha/field_number_test.js @@ -6,7 +6,9 @@ goog.module('Blockly.test.fieldNumber'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); +const {runTestCases} = goog.require('Blockly.test.commonHelpers'); suite('Number Fields', function() { @@ -64,7 +66,7 @@ suite('Number Fields', function() { */ function assertNumberField(field, expectedMin, expectedMax, expectedPrecision, expectedValue) { - testHelpers.assertFieldValue(field, expectedValue); + assertFieldValue(field, expectedValue); chai.assert.equal(field.getMin(), expectedMin, 'Min'); chai.assert.equal(field.getMax(), expectedMax, 'Max'); chai.assert.equal( @@ -88,11 +90,11 @@ suite('Number Fields', function() { testCase.expectedValue, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldNumber, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldNumber, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -101,7 +103,7 @@ suite('Number Fields', function() { setup(function() { this.field = new Blockly.FieldNumber(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); }); suite('Value -> New Value', function() { @@ -109,7 +111,7 @@ suite('Number Fields', function() { setup(function() { this.field = new Blockly.FieldNumber(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); }); suite('Constraints', function() { @@ -127,11 +129,11 @@ suite('Number Fields', function() { expectedValue: 123}, ]; suite('Precision', function() { - testHelpers.runTestCases(testCases, function(testCase) { + runTestCases(testCases, function(testCase) { return function() { const field = Blockly.FieldNumber.fromJson(testCase.json); field.setValue(testCase.value); - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; }); test('Null', function() { @@ -144,7 +146,7 @@ suite('Number Fields', function() { const field = Blockly.FieldNumber.fromJson(testCase.json); testCase.values.forEach(function(value, i) { field.setValue(value); - testHelpers.assertFieldValue( + assertFieldValue( field, testCase.expectedValues[i]); }); }; @@ -158,7 +160,7 @@ suite('Number Fields', function() { {title: '+10', json: {min: 10}, values: [-20, 0, 20], expectedValues: [10, 10, 20]}, ]; - testHelpers.runTestCases(testCases, setValueBoundsTestFn); + runTestCases(testCases, setValueBoundsTestFn); test('Null', function() { const field = Blockly.FieldNumber.fromJson({min: null}); chai.assert.equal(field.getMin(), -Infinity); @@ -173,7 +175,7 @@ suite('Number Fields', function() { {title: '+10', json: {max: 10}, values: [-20, 0, 20], expectedValues: [-20, 0, 10]}, ]; - testHelpers.runTestCases(testCases, setValueBoundsTestFn); + runTestCases(testCases, setValueBoundsTestFn); test('Null', function() { const field = Blockly.FieldNumber.fromJson({max: null}); chai.assert.equal(field.getMax(), Infinity); @@ -217,12 +219,12 @@ suite('Number Fields', function() { this.field.isBeingEdited_ = true; this.field.htmlInput_.value = String(suiteInfo.value); this.field.onHtmlInputChange_(null); - testHelpers.assertFieldValue( + assertFieldValue( this.field, suiteInfo.expectedValue, String(suiteInfo.value)); }); test('When Not Editing', function() { this.field.setValue(suiteInfo.value); - testHelpers.assertFieldValue(this.field, suiteInfo.expectedValue); + assertFieldValue(this.field, suiteInfo.expectedValue); }); }); }); diff --git a/tests/mocha/field_textinput_test.js b/tests/mocha/field_textinput_test.js index d95e31204..a8043938d 100644 --- a/tests/mocha/field_textinput_test.js +++ b/tests/mocha/field_textinput_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldTextInput'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -53,7 +54,7 @@ suite('Text Input Fields', function() { * @param {!Blockly.FieldTextInput} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, defaultFieldValue); + assertFieldValue(field, defaultFieldValue); }; /** * Asserts that the field properties are correct based on the test case. @@ -61,14 +62,14 @@ suite('Text Input Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, testCase.expectedValue); + assertFieldValue(field, testCase.expectedValue); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldTextInput, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldTextInput, validValueTestCases, invalidValueTestCases, validTestCaseAssertField, assertFieldDefault); @@ -77,12 +78,12 @@ suite('Text Input Fields', function() { setup(function() { this.field = new Blockly.FieldTextInput(); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, defaultFieldValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); suite('Value -> New Value', function() { @@ -90,12 +91,12 @@ suite('Text Input Fields', function() { setup(function() { this.field = new Blockly.FieldTextInput(initialValue); }); - testHelpers.runSetValueTests( + runSetValueTests( validValueTestCases, invalidValueTestCases, initialValue); test('With source block', function() { this.field.setSourceBlock(createTestBlock()); this.field.setValue('value'); - testHelpers.assertFieldValue(this.field, 'value'); + assertFieldValue(this.field, 'value'); }); }); }); @@ -136,12 +137,12 @@ suite('Text Input Fields', function() { this.field.isBeingEdited_ = true; this.field.htmlInput_.value = suiteInfo.value; this.field.onHtmlInputChange_(null); - testHelpers.assertFieldValue( + assertFieldValue( this.field, suiteInfo.expectedValue, suiteInfo.value); }); test('When Not Editing', function() { this.field.setValue(suiteInfo.value); - testHelpers.assertFieldValue(this.field, suiteInfo.expectedValue); + assertFieldValue(this.field, suiteInfo.expectedValue); }); }); }); diff --git a/tests/mocha/field_variable_test.js b/tests/mocha/field_variable_test.js index 4a93ccf41..760283416 100644 --- a/tests/mocha/field_variable_test.js +++ b/tests/mocha/field_variable_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.fieldVariable'); +const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.fieldHelpers'); const {createGenUidStubWithReturns, createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -83,7 +84,7 @@ suite('Variable Fields', function() { * @param {!Blockly.FieldVariable} field The field to check. */ const assertFieldDefault = function(field) { - testHelpers.assertFieldValue(field, FAKE_ID, defaultFieldName); + assertFieldValue(field, FAKE_ID, defaultFieldName); }; /** * Asserts that the field properties are correct based on the test case. @@ -91,15 +92,15 @@ suite('Variable Fields', function() { * @param {!FieldValueTestCase} testCase The test case. */ const validTestCaseAssertField = function(field, testCase) { - testHelpers.assertFieldValue(field, FAKE_ID, testCase.expectedText); + assertFieldValue(field, FAKE_ID, testCase.expectedText); }; - testHelpers.runConstructorSuiteTests( + runConstructorSuiteTests( Blockly.FieldVariable, validValueCreationTestCases, invalidValueCreationTestCases, validTestCaseAssertField, assertFieldDefault, customCreateWithJs); - testHelpers.runFromJsonSuiteTests( + runFromJsonSuiteTests( Blockly.FieldVariable, validValueCreationTestCases, invalidValueCreationTestCases, validTestCaseAssertField, assertFieldDefault, customCreateWithJson); @@ -149,7 +150,7 @@ suite('Variable Fields', function() { teardown(function() { console.warn = this.nativeConsoleWarn; }); - testHelpers.runSetValueTests(validValueTestCases, invalidValueTestCases, + runSetValueTests(validValueTestCases, invalidValueTestCases, FAKE_ID, defaultFieldName); }); @@ -215,7 +216,7 @@ suite('Variable Fields', function() { }); test('New Value', function() { this.variableField.setValue('id2'); - testHelpers.assertFieldValue(this.variableField, 'id1', 'name1'); + assertFieldValue(this.variableField, 'id1', 'name1'); }); }); suite('Force \'id\' ID Validator', function() { @@ -228,7 +229,7 @@ suite('Variable Fields', function() { // Must create the var so that the field doesn't throw an error. this.workspace.createVariable('thing2', null, 'other2'); this.variableField.setValue('other2'); - testHelpers.assertFieldValue(this.variableField, 'id2', 'name2'); + assertFieldValue(this.variableField, 'id2', 'name2'); }); }); suite('Returns Undefined Validator', function() { @@ -237,7 +238,7 @@ suite('Variable Fields', function() { }); test('New Value', function() { this.variableField.setValue('id2'); - testHelpers.assertFieldValue(this.variableField, 'id2', 'name2'); + assertFieldValue(this.variableField, 'id2', 'name2'); }); }); }); diff --git a/tests/mocha/index.html b/tests/mocha/index.html index 7d734de53..6eb47e3d9 100644 --- a/tests/mocha/index.html +++ b/tests/mocha/index.html @@ -24,7 +24,7 @@ - +