fix: split user input helpers into new file

This commit is contained in:
Beka Westberg
2022-03-01 19:40:59 +00:00
parent e084e91942
commit ccfd8882b8
8 changed files with 85 additions and 69 deletions

View File

@@ -28,13 +28,13 @@ goog.addDependency('../../tests/mocha/field_textinput_test.js', ['Blockly.test.f
goog.addDependency('../../tests/mocha/field_variable_test.js', ['Blockly.test.fieldVariable'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.fields'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/flyout_test.js', ['Blockly.test.flyout'], ['Blockly.test.helpers', 'Blockly.test.helpers.toolbox_definitions'], {'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.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/gesture_test.js', ['Blockly.test.gesture'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/input_test.js', ['Blockly.test.input'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/insertion_marker_test.js', ['Blockly.test.insertionMarker'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/jso_deserialization_test.js', ['Blockly.test.jsoDeserialization'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/jso_serialization_test.js', ['Blockly.test.jsoSerialization'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es8', 'module': 'goog'});
goog.addDependency('../../tests/mocha/json_test.js', ['Blockly.test.json'], ['Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/keydown_test.js', ['Blockly.test.keydown'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/keydown_test.js', ['Blockly.test.keydown'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/logic_ternary_test.js', ['Blockly.test.logicTernary'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.serialization'], {'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', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es6', 'module': 'goog'});
@@ -43,7 +43,7 @@ goog.addDependency('../../tests/mocha/procedures_test.js', ['Blockly.test.proced
goog.addDependency('../../tests/mocha/registry_test.js', ['Blockly.test.registry'], ['Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'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', 'Blockly.test.helpers.common'], {'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/shortcut_registry_test.js', ['Blockly.test.shortcutRegistry'], ['Blockly.test.helpers', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/test_helpers/block_definitions.js', ['Blockly.test.helpers.blockDefinitions'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/test_helpers/code_generation.js', ['Blockly.test.helpers.codeGeneration'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/test_helpers/common.js', ['Blockly.test.helpers.common'], [], {'lang': 'es6', 'module': 'goog'});
@@ -52,12 +52,13 @@ goog.addDependency('../../tests/mocha/test_helpers/procedures.js', ['Blockly.tes
goog.addDependency('../../tests/mocha/test_helpers/serialization.js', ['Blockly.test.helpers.serialization'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/test_helpers/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers.common', 'Blockly.utils.KeyCodes'], {'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/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/theme_test.js', ['Blockly.test.theme'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'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'], {'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.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_model_test.js', ['Blockly.test.variableModel'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
@@ -67,4 +68,4 @@ goog.addDependency('../../tests/mocha/workspace_comment_test.js', ['Blockly.test
goog.addDependency('../../tests/mocha/workspace_svg_test.js', ['Blockly.test.workspaceSvg'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', '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/zoom_controls_test.js', ['Blockly.test.zoomControls'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../tests/mocha/zoom_controls_test.js', ['Blockly.test.zoomControls'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'});

View File

@@ -6,8 +6,9 @@
goog.module('Blockly.test.gesture');
const {assertEventFired, assertEventNotFired, dispatchPointerEvent, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {defineBasicBlockWithField} = goog.require('Blockly.test.helpers.blockDefinitions');
const {dispatchPointerEvent} = goog.require('Blockly.test.helpers.userInput');
suite('Gesture', function() {

View File

@@ -6,8 +6,9 @@
goog.module('Blockly.test.keydown');
const {createKeyDownEvent, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {createKeyDownEvent} = goog.require('Blockly.test.helpers.userInput');
const {defineStackBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
suite('Key Down', function() {

View File

@@ -6,7 +6,8 @@
goog.module('Blockly.test.shortcutRegistry');
const {createKeyDownEvent, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {createKeyDownEvent} = goog.require('Blockly.test.helpers.userInput');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
suite('Keyboard Shortcut Registry Test', function() {

View File

@@ -419,62 +419,4 @@ function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
const eventArg = nthCall.firstArg;
assertXmlProperties_(eventArg, xmlProperties);
}
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;
/**
* Triggers pointer event on target.
* @param {!EventTarget} target The object receiving the event.
* @param {string} type The type of mouse event (eg: mousedown, mouseup,
* click).
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
function dispatchPointerEvent(target, type, properties) {
const eventInitDict = {
cancelable: true,
bubbles: true,
isPrimary: true,
pressure: 0.5,
clientX: 10,
clientY: 10,
};
if (properties) {
Object.assign(eventInitDict, properties);
}
const event = new PointerEvent(type, eventInitDict);
target.dispatchEvent(event);
}
exports.dispatchPointerEvent = dispatchPointerEvent;
/**
* Creates a key down event used for testing.
* @param {number} keyCode The keycode for the event. Use Blockly.utils.KeyCodes enum.
* @param {!Array<number>=} modifiers A list of modifiers. Use Blockly.utils.KeyCodes enum.
* @return {!KeyboardEvent} The mocked keydown event.
*/
function createKeyDownEvent(keyCode, modifiers) {
const event = {
keyCode: keyCode,
};
if (modifiers && modifiers.length > 0) {
event.altKey = modifiers.indexOf(KeyCodes.ALT) > -1;
event.ctrlKey = modifiers.indexOf(KeyCodes.CTRL) > -1;
event.metaKey = modifiers.indexOf(KeyCodes.META) > -1;
event.shiftKey = modifiers.indexOf(KeyCodes.SHIFT) > -1;
}
return new KeyboardEvent('keydown', event);
}
exports.createKeyDownEvent = createKeyDownEvent;
/**
* Simulates mouse click by triggering relevant mouse events.
* @param {!EventTarget} target The object receiving the event.
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
function simulateClick(target, properties) {
dispatchPointerEvent(target, 'pointerdown', properties);
dispatchPointerEvent(target, 'pointerup', properties);
dispatchPointerEvent(target, 'click', properties);
}
exports.simulateClick = simulateClick;
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;

View File

@@ -0,0 +1,68 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.module('Blockly.test.helpers.userInput');
const {KeyCodes} = goog.require('Blockly.utils.KeyCodes');
/**
* Triggers pointer event on target.
* @param {!EventTarget} target The object receiving the event.
* @param {string} type The type of mouse event (eg: mousedown, mouseup,
* click).
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
function dispatchPointerEvent(target, type, properties) {
const eventInitDict = {
cancelable: true,
bubbles: true,
isPrimary: true,
pressure: 0.5,
clientX: 10,
clientY: 10,
};
if (properties) {
Object.assign(eventInitDict, properties);
}
const event = new PointerEvent(type, eventInitDict);
target.dispatchEvent(event);
}
exports.dispatchPointerEvent = dispatchPointerEvent;
/**
* Creates a key down event used for testing.
* @param {number} keyCode The keycode for the event. Use Blockly.utils.KeyCodes enum.
* @param {!Array<number>=} modifiers A list of modifiers. Use Blockly.utils.KeyCodes enum.
* @return {!KeyboardEvent} The mocked keydown event.
*/
function createKeyDownEvent(keyCode, modifiers) {
const event = {
keyCode: keyCode,
};
if (modifiers && modifiers.length > 0) {
event.altKey = modifiers.indexOf(KeyCodes.ALT) > -1;
event.ctrlKey = modifiers.indexOf(KeyCodes.CTRL) > -1;
event.metaKey = modifiers.indexOf(KeyCodes.META) > -1;
event.shiftKey = modifiers.indexOf(KeyCodes.SHIFT) > -1;
}
return new KeyboardEvent('keydown', event);
}
exports.createKeyDownEvent = createKeyDownEvent;
/**
* Simulates mouse click by triggering relevant mouse events.
* @param {!EventTarget} target The object receiving the event.
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
function simulateClick(target, properties) {
dispatchPointerEvent(target, 'pointerdown', properties);
dispatchPointerEvent(target, 'pointerup', properties);
dispatchPointerEvent(target, 'click', properties);
}
exports.simulateClick = simulateClick;

View File

@@ -6,9 +6,10 @@
goog.module('Blockly.test.trashcan');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {defineBasicBlockWithField, defineMutatorBlocks, defineRowBlock, defineStackBlock, defineStatementBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
const eventUtils = goog.require('Blockly.Events.utils');
const {simulateClick} = goog.require('Blockly.test.helpers.userInput');
suite("Trashcan", function() {

View File

@@ -6,8 +6,9 @@
goog.module('Blockly.test.zoomControls');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const eventUtils = goog.require('Blockly.Events.utils');
const {assertEventFired, assertEventNotFired, sharedTestSetup, sharedTestTeardown, simulateClick} = goog.require('Blockly.test.helpers');
const {simulateClick} = goog.require('Blockly.test.helpers.userInput');
suite("Zoom Controls", function() {