From 7784eac9beac7f694060aa42a6d37cd70ff88a77 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Wed, 8 Dec 2021 18:16:13 -0800 Subject: [PATCH] chore!: Add deprecation notices to values in blockly.js (#5555) * Add deprecation warnings and reorganize blockly.js * Update usages of deprecated properties * chore: make dates consistent, remove extra function * chore: run clang-format and fix lint * chore: add more tags * chore: fix updated location of Align types * chore: fix deprecated usages in tests * chore: rebuild deps * chore: fix moved Align types in demos and tests * chore: update which properties are actually deprecated * chore: don't deprecate Blockly.selected. --- core/blockly.js | 600 ++++++++++++++----------- core/common.js | 2 +- tests/deps.mocha.js | 10 +- tests/mocha/block_json_test.js | 10 +- tests/mocha/block_test.js | 9 +- tests/mocha/connection_checker_test.js | 63 +-- tests/mocha/connection_db_test.js | 33 +- tests/mocha/procedures_test_helpers.js | 5 +- tests/mocha/toolbox_test.js | 2 +- 9 files changed, 421 insertions(+), 313 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 9c344d7e0..dd12f0f1b 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -191,253 +191,17 @@ goog.require('Blockly.Events.VarCreate'); */ exports.VERSION = 'uncompiled'; -// Add a getter and setter pair for Blockly.alert, Blockly.confirm, -// Blockly.mainWorkspace, Blockly.prompt and Blockly.selected for backwards -// compatibility. -Object.defineProperties(exports, { - /** - * Wrapper to window.alert() that app developers may override to - * provide alternatives to the modal browser window. - * @name Blockly.alert - * @type {!function(string, function()=)} - * @deprecated Use Blockly.dialog.alert / .setAlert() instead. - * (September 2021) - * @suppress {checkTypes} - */ - alert: { - set: function(newAlert) { - deprecation.warn('Blockly.alert', 'September 2021', 'September 2022'); - dialog.setAlert(newAlert); - }, - get: function() { - deprecation.warn( - 'Blockly.alert', 'September 2021', 'September 2022', - 'Blockly.dialog.alert()'); - return dialog.alert; - }, - }, - /** - * Wrapper to window.confirm() that app developers may override to - * provide alternatives to the modal browser window. - * @name Blockly.confirm - * @type {!function(string, function()=)} - * @deprecated Use Blockly.dialog.confirm / .setConfirm() instead. - * (September 2021) - * @suppress {checkTypes} - */ - confirm: { - set: function(newConfirm) { - deprecation.warn('Blockly.confirm', 'September 2021', 'September 2022'); - dialog.setConfirm(newConfirm); - }, - get: function() { - deprecation.warn( - 'Blockly.confirm', 'September 2021', 'September 2022', - 'Blockly.dialog.confirm()'); - return dialog.confirm; - }, - }, - /** - * The main workspace most recently used. - * Set by Blockly.WorkspaceSvg.prototype.markFocused - * @name Blockly.mainWorkspace - * @type {Workspace} - * @deprecated Use Blockly.common.getMainWorkspace() / - * .setMainWorkspace instead. (September 2021) - * @suppress {checkTypes} - */ - mainWorkspace: { - set: function(x) { - deprecation.warn( - 'Blockly.mainWorkspace', 'September 2021', 'September 2022'); - common.setMainWorkspace(x); - }, - get: function() { - deprecation.warn( - 'Blockly.mainWorkspace', 'September 2021', 'September 2022', - 'Blockly.getMainWorkspace()'); - return common.getMainWorkspace(); - }, - }, - /** - * Wrapper to window.prompt() that app developers may override to - * provide alternatives to the modal browser window. Built-in - * browser prompts are often used for better text input experience - * on mobile device. We strongly recommend testing mobile when - * overriding this. - * @name Blockly.prompt - * @type {!function(string, string, function()=)} - * @deprecated Use Blockly.dialog.prompt / .setPrompt() instead. - * (September 2021) - * @suppress {checkTypes} - */ - prompt: { - set: function(newPrompt) { - deprecation.warn('Blockly.prompt', 'September 2021', 'September 2022'); - dialog.setPrompt(newPrompt); - }, - get: function() { - deprecation.warn( - 'Blockly.prompt', 'September 2021', 'September 2022', - 'Blockly.dialog.prompt()'); - return dialog.prompt; - }, - }, - /** - * Currently selected block. - * @name Blockly.selected - * @type {?ICopyable} - * @deprecated Use Blockly.common.getSelected() / .setSelected - * instead. (September 2021) - * @suppress {checkTypes} - */ - selected: { - get: function() { - deprecation.warn( - 'Blockly.selected', 'September 2021', 'September 2022', - 'Blockly.common.getSelected()'); - return common.getSelected(); - }, - set: function(newSelection) { - deprecation.warn( - 'Blockly.selected', 'September 2021', 'September 2022', - 'Blockly.common.setSelected()'); - common.setSelected(newSelection); - }, - }, -}); - -/** - * Returns the dimensions of the specified SVG image. - * @param {!SVGElement} svg SVG image. - * @return {!Size} Contains width and height properties. - * @deprecated Use workspace.setCachedParentSvgSize. (2021 March 5) - * @alias Blockly.svgSize +/* + * Top-level functions and properties on the Blockly namespace. + * These are used only in external code. Do not reference these + * from internal code as importing from this file can cause circular + * dependencies. Do not add new functions here. There is probably a better + * namespace to put new functions on. */ -exports.svgSize = svgMath.svgSize; -/** - * Size the workspace when the contents change. This also updates - * scrollbars accordingly. - * @param {!WorkspaceSvg} workspace The workspace to resize. - * @deprecated - * @alias Blockly.resizeSvgContents +/* + * Aliases for input alignments used in block defintions. */ -const resizeSvgContentsLocal = function(workspace) { - deprecation.warn( - 'Blockly.resizeSvgContents', 'December 2021', 'December 2022', - 'Blockly.WorkspaceSvg.resizeSvgContents'); - resizeSvgContents(workspace); -}; -exports.resizeSvgContents = resizeSvgContentsLocal; - -/** - * Copy a block or workspace comment onto the local clipboard. - * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. - * @package - * @alias Blockly.copy - */ -exports.copy = clipboard.copy; - -/** - * Paste a block or workspace comment on to the main workspace. - * @return {boolean} True if the paste was successful, false otherwise. - * @package - * @alias Blockly.paste - */ -exports.paste = clipboard.paste; - -/** - * Duplicate this block and its children, or a workspace comment. - * @param {!ICopyable} toDuplicate Block or Workspace Comment to be - * copied. - * @package - * @alias Blockly.duplicate - */ -exports.duplicate = clipboard.duplicate; - -/** - * Close tooltips, context menus, dropdown selections, etc. - * @deprecated Use Blockly.common.getMainWorkspace().hideChaff() - * @param {boolean=} opt_onlyClosePopups Whether only popups should be closed. - * @alias Blockly.hideChaff - */ -const hideChaff = function(opt_onlyClosePopups) { - deprecation.warn( - 'Blockly.hideChaff', 'September 2021', 'September 2022', - 'workspace.hideChaff'); - common.getMainWorkspace().hideChaff(opt_onlyClosePopups); -}; -exports.hideChaff = hideChaff; - -/** - * Returns the main workspace. Returns the last used main workspace (based on - * focus). Try not to use this function, particularly if there are multiple - * Blockly instances on a page. - * @return {!Workspace} The main workspace. - * @alias Blockly.getMainWorkspace - */ -exports.getMainWorkspace = common.getMainWorkspace; - -/** - * Define blocks from an array of JSON block definitions, as might be generated - * by the Blockly Developer Tools. - * @param {!Array} jsonArray An array of JSON block definitions. - * @alias Blockly.defineBlocksWithJsonArray - */ -exports.defineBlocksWithJsonArray = common.defineBlocksWithJsonArray; - -/** - * Is the given string a number (includes negative and decimals). - * @param {string} str Input string. - * @return {boolean} True if number, false otherwise. - * @deprecated - * @alias Blockly.isNumber - */ -const isNumber = function(str) { - deprecation.warn( - 'Blockly.isNumber', 'December 2021', 'December 2022', - 'Blockly.utils.string.isNumber'); - return utils.string.isNumber(str); -}; -exports.isNumber = isNumber; - -/** - * Set the parent container. This is the container element that the WidgetDiv, - * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` - * is called. - * This method is a NOP if called after the first ``Blockly.inject``. - * @param {!Element} container The container element. - * @alias Blockly.setParentContainer - */ -exports.setParentContainer = common.setParentContainer; - -/** Aliases. */ - -/** - * @see colour.hueToHex - * @deprecated Use Blockly.utils.colour.hueToHex (September 2021). - * @alias Blockly.hueToHex - */ -exports.hueToHex = colour.hueToHex; - -/** - * @see browserEvents.bind - * @alias Blockly.bindEvent_ - */ -exports.bindEvent_ = browserEvents.bind; - -/** - * @see browserEvents.unbind - * @alias Blockly.unbindEvent_ - */ -exports.unbindEvent_ = browserEvents.unbind; - -/** - * @see browserEvents.conditionalBind - * @alias Blockly.bindEventWithChecks_ - */ -exports.bindEventWithChecks_ = browserEvents.conditionalBind; /** * @see Blockly.Input.Align.LEFT @@ -457,12 +221,7 @@ exports.ALIGN_CENTRE = Align.CENTRE; */ exports.ALIGN_RIGHT = Align.RIGHT; -/** - * @see common.svgResize - */ -exports.svgResize = common.svgResize; - -/** +/* * Aliases for constants used for connection and input types. */ @@ -524,6 +283,347 @@ exports.TOOLBOX_AT_LEFT = toolbox.Position.LEFT; */ exports.TOOLBOX_AT_RIGHT = toolbox.Position.RIGHT; +/* + * Other aliased functions. + */ + +/** + * Size the SVG image to completely fill its container. Call this when the view + * actually changes sizes (e.g. on a window resize/device orientation change). + * See workspace.resizeContents to resize the workspace when the contents + * change (e.g. when a block is added or removed). + * Record the height/width of the SVG image. + * @param {!WorkspaceSvg} workspace Any workspace in the SVG. + * @see Blockly.common.svgResize + * @alias Blockly.svgResize + */ +exports.svgResize = common.svgResize; + +/** + * Close tooltips, context menus, dropdown selections, etc. + * @param {boolean=} opt_onlyClosePopups Whether only popups should be closed. + * @see Blockly.WorkspaceSvg.hideChaff + * @alias Blockly.hideChaff + */ +const hideChaff = function(opt_onlyClosePopups) { + common.getMainWorkspace().hideChaff(opt_onlyClosePopups); +}; +exports.hideChaff = hideChaff; + +/** + * Returns the main workspace. Returns the last used main workspace (based on + * focus). Try not to use this function, particularly if there are multiple + * Blockly instances on a page. + * @return {!Workspace} The main workspace. + * @see Blockly.common.getMainWorkspace + * @alias Blockly.getMainWorkspace + */ +exports.getMainWorkspace = common.getMainWorkspace; + +/** + * Define blocks from an array of JSON block definitions, as might be generated + * by the Blockly Developer Tools. + * @param {!Array} jsonArray An array of JSON block definitions. + * @see Blockly.common.defineBlocksWithJsonArray + * @alias Blockly.defineBlocksWithJsonArray + */ +exports.defineBlocksWithJsonArray = common.defineBlocksWithJsonArray; + +/** + * Set the parent container. This is the container element that the WidgetDiv, + * DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject` + * is called. + * This method is a NOP if called after the first ``Blockly.inject``. + * @param {!Element} container The container element. + * @see Blockly.common.setParentContainer + * @alias Blockly.setParentContainer + */ +exports.setParentContainer = common.setParentContainer; + +/* + * Aliased functions and properties that used to be on the Blockly namespace. + * Everything in this section is deprecated. Both external and internal code + * should avoid using these functions and use the designated replacements. + * Anything in this section may be removed in a future version of Blockly. + */ + +// Add accessors for properties on Blockly that have now been deprecated. +Object.defineProperties(exports, { + /** + * Wrapper to window.alert() that app developers may override to + * provide alternatives to the modal browser window. + * @name Blockly.alert + * @type {!function(string, function()=)} + * @deprecated Use Blockly.dialog.alert / .setAlert() instead. + * (December 2021) + * @suppress {checkTypes} + */ + alert: { + set: function(newAlert) { + deprecation.warn('Blockly.alert', 'December 2021', 'December 2022'); + dialog.setAlert(newAlert); + }, + get: function() { + deprecation.warn( + 'Blockly.alert', 'December 2021', 'December 2022', + 'Blockly.dialog.alert()'); + return dialog.alert; + }, + }, + /** + * Wrapper to window.confirm() that app developers may override to + * provide alternatives to the modal browser window. + * @name Blockly.confirm + * @type {!function(string, function()=)} + * @deprecated Use Blockly.dialog.confirm / .setConfirm() instead. + * (December 2021) + * @suppress {checkTypes} + */ + confirm: { + set: function(newConfirm) { + deprecation.warn('Blockly.confirm', 'December 2021', 'December 2022'); + dialog.setConfirm(newConfirm); + }, + get: function() { + deprecation.warn( + 'Blockly.confirm', 'December 2021', 'December 2022', + 'Blockly.dialog.confirm()'); + return dialog.confirm; + }, + }, + /** + * The main workspace most recently used. + * Set by Blockly.WorkspaceSvg.prototype.markFocused + * @name Blockly.mainWorkspace + * @type {Workspace} + * @suppress {checkTypes} + */ + mainWorkspace: { + set: function(x) { + common.setMainWorkspace(x); + }, + get: function() { + return common.getMainWorkspace(); + }, + }, + /** + * Wrapper to window.prompt() that app developers may override to + * provide alternatives to the modal browser window. Built-in + * browser prompts are often used for better text input experience + * on mobile device. We strongly recommend testing mobile when + * overriding this. + * @name Blockly.prompt + * @type {!function(string, string, function()=)} + * @deprecated Use Blockly.dialog.prompt / .setPrompt() instead. + * (December 2021) + * @suppress {checkTypes} + */ + prompt: { + set: function(newPrompt) { + deprecation.warn('Blockly.prompt', 'December 2021', 'December 2022'); + dialog.setPrompt(newPrompt); + }, + get: function() { + deprecation.warn( + 'Blockly.prompt', 'December 2021', 'December 2022', + 'Blockly.dialog.prompt()'); + return dialog.prompt; + }, + }, + /** + * Currently selected block. + * @name Blockly.selected + * @type {?ICopyable} + * @suppress {checkTypes} + */ + selected: { + get: function() { + return common.getSelected(); + }, + set: function(newSelection) { + common.setSelected(newSelection); + }, + }, +}); + +/** + * Returns the dimensions of the specified SVG image. + * @param {!SVGElement} svg SVG image. + * @return {!Size} Contains width and height properties. + * @deprecated Use workspace.setCachedParentSvgSize. (2021 March 5) + * @see Blockly.WorkspaceSvg.setCachedParentSvgSize + * @alias Blockly.svgSize + */ +exports.svgSize = svgMath.svgSize; + +/** + * Size the workspace when the contents change. This also updates + * scrollbars accordingly. + * @param {!WorkspaceSvg} workspace The workspace to resize. + * @deprecated Use workspace.resizeContents. (2021 December) + * @see Blockly.WorkspaceSvg.resizeContents + * @alias Blockly.resizeSvgContents + */ +const resizeSvgContentsLocal = function(workspace) { + deprecation.warn( + 'Blockly.resizeSvgContents', 'December 2021', 'December 2022', + 'Blockly.WorkspaceSvg.resizeSvgContents'); + resizeSvgContents(workspace); +}; +exports.resizeSvgContents = resizeSvgContentsLocal; + +/** + * Copy a block or workspace comment onto the local clipboard. + * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. + * @deprecated Use Blockly.clipboard.copy(). (2021 December) + * @see Blockly.clipboard.copy + * @alias Blockly.copy + */ +const copy = function(toCopy) { + deprecation.warn( + 'Blockly.copy', 'December 2021', 'December 2022', + 'Blockly.clipboard.copy'); + clipboard.copy(toCopy); +}; +exports.copy = copy; + +/** + * Paste a block or workspace comment on to the main workspace. + * @return {boolean} True if the paste was successful, false otherwise. + * @deprecated Use Blockly.clipboard.paste(). (2021 December) + * @see Blockly.clipboard.paste + * @alias Blockly.paste + */ +const paste = function() { + deprecation.warn( + 'Blockly.paste', 'December 2021', 'December 2022', + 'Blockly.clipboard.paste'); + return clipboard.paste(); +}; +exports.paste = paste; + +/** + * Duplicate this block and its children, or a workspace comment. + * @param {!ICopyable} toDuplicate Block or Workspace Comment to be + * copied. + * @deprecated Use Blockly.clipboard.duplicate(). (2021 December) + * @see Blockly.clipboard.duplicate + * @alias Blockly.duplicate + */ +const duplicate = function(toDuplicate) { + deprecation.warn( + 'Blockly.duplicate', 'December 2021', 'December 2022', + 'Blockly.clipboard.duplicate'); + clipboard.duplicate(toDuplicate); +}; +exports.duplicate = duplicate; + +/** + * Is the given string a number (includes negative and decimals). + * @param {string} str Input string. + * @return {boolean} True if number, false otherwise. + * @deprecated Use Blockly.utils.string.isNumber(str). (2021 December) + * @see Blockly.utils.string.isNumber + * @alias Blockly.isNumber + */ +const isNumber = function(str) { + deprecation.warn( + 'Blockly.isNumber', 'December 2021', 'December 2022', + 'Blockly.utils.string.isNumber'); + return utils.string.isNumber(str); +}; +exports.isNumber = isNumber; + +/** + * Convert a hue (HSV model) into an RGB hex triplet. + * @param {number} hue Hue on a colour wheel (0-360). + * @return {string} RGB code, e.g. '#5ba65b'. + * @deprecated Use Blockly.utils.colour.hueToHex(). (2021 December) + * @see Blockly.utils.colour.hueToHex + * @alias Blockly.hueToHex + */ +const hueToHex = function(hue) { + deprecation.warn( + 'Blockly.hueToHex', 'December 2021', 'December 2022', + 'Blockly.utils.colour.hueToHex'); + return colour.hueToHex(hue); +}; +exports.hueToHex = hueToHex; + +/** + * Bind an event handler that should be called regardless of whether it is part + * of the active touch stream. + * Use this for events that are not part of a multi-part gesture (e.g. + * mouseover for tooltips). + * @param {!EventTarget} node Node upon which to listen. + * @param {string} name Event name to listen to (e.g. 'mousedown'). + * @param {?Object} thisObject The value of 'this' in the function. + * @param {!Function} func Function to call when event is triggered. + * @return {!browserEvents.Data} Opaque data that can be passed to + * unbindEvent_. + * @deprecated Use Blockly.browserEvents.bind(). (December 2021) + * @see Blockly.browserEvents.bind + * @alias Blockly.bindEvent_ + */ +const bindEvent_ = function(node, name, thisObject, func) { + deprecation.warn( + 'Blockly.bindEvent_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.bind'); + return browserEvents.bind(node, name, thisObject, func); +}; +exports.bindEvent_ = bindEvent_; + +/** + * Unbind one or more events event from a function call. + * @param {!browserEvents.Data} bindData Opaque data from bindEvent_. + * This list is emptied during the course of calling this function. + * @return {!Function} The function call. + * @deprecated Use Blockly.browserEvents.unbind(). (December 2021) + * @see browserEvents.unbind + * @alias Blockly.unbindEvent_ + */ +const unbindEvent_ = function(bindData) { + deprecation.warn( + 'Blockly.unbindEvent_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.unbind'); + return browserEvents.unbind(bindData); +}; +exports.unbindEvent_ = unbindEvent_; + +/** + * Bind an event handler that can be ignored if it is not part of the active + * touch stream. + * Use this for events that either start or continue a multi-part gesture (e.g. + * mousedown or mousemove, which may be part of a drag or click). + * @param {!EventTarget} node Node upon which to listen. + * @param {string} name Event name to listen to (e.g. 'mousedown'). + * @param {?Object} thisObject The value of 'this' in the function. + * @param {!Function} func Function to call when event is triggered. + * @param {boolean=} opt_noCaptureIdentifier True if triggering on this event + * should not block execution of other event handlers on this touch or + * other simultaneous touches. False by default. + * @param {boolean=} opt_noPreventDefault True if triggering on this event + * should prevent the default handler. False by default. If + * opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be + * provided. + * @return {!browserEvents.Data} Opaque data that can be passed to + * unbindEvent_. + * @deprecated Use Blockly.browserEvents.conditionalBind(). (December 2021) + * @see browserEvents.conditionalBind + * @alias Blockly.bindEventWithChecks_ + */ +const bindEventWithChecks_ = function( + node, name, thisObject, func, opt_noCaptureIdentifier, + opt_noPreventDefault) { + deprecation.warn( + 'Blockly.bindEventWithChecks_', 'December 2021', 'December 2022', + 'Blockly.browserEvents.conditionalBind'); + return browserEvents.conditionalBind( + node, name, thisObject, func, opt_noCaptureIdentifier, + opt_noPreventDefault); +}; +exports.bindEventWithChecks_ = bindEventWithChecks_; + // Aliases to allow external code to access these values for legacy reasons. exports.LINE_MODE_MULTIPLIER = internalConstants.LINE_MODE_MULTIPLIER; exports.PAGE_MODE_MULTIPLIER = internalConstants.PAGE_MODE_MULTIPLIER; diff --git a/core/common.js b/core/common.js index 429ee11f4..59052b55d 100644 --- a/core/common.js +++ b/core/common.js @@ -121,7 +121,7 @@ exports.setParentContainer = setParentContainer; /** * Size the SVG image to completely fill its container. Call this when the view * actually changes sizes (e.g. on a window resize/device orientation change). - * See Blockly.resizeSvgContents to resize the workspace when the contents + * See workspace.resizeContents to resize the workspace when the contents * change (e.g. when a block is added or removed). * Record the height/width of the SVG image. * @param {!WorkspaceSvg} workspace Any workspace in the SVG. diff --git a/tests/deps.mocha.js b/tests/deps.mocha.js index 2897bf250..4be80abef 100644 --- a/tests/deps.mocha.js +++ b/tests/deps.mocha.js @@ -2,11 +2,11 @@ goog.addDependency('../../tests/mocha/.mocharc.js', [], []); goog.addDependency('../../tests/mocha/astnode_test.js', ['Blockly.test.astNode'], ['Blockly.ASTNode', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/block_change_event_test.js', ['Blockly.test.blockChangeEvent'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/block_create_event_test.js', ['Blockly.test.blockCreateEvent'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/block_json_test.js', ['Blockly.test.blockJson'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/block_test.js', ['Blockly.test.blocks'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/block_json_test.js', ['Blockly.test.blockJson'], ['Blockly.Input'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/block_test.js', ['Blockly.test.blocks'], ['Blockly.ConnectionType', 'Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/comment_test.js', ['Blockly.test.comments'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/connection_checker_test.js', ['Blockly.test.connectionChecker'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/connection_db_test.js', ['Blockly.test.connectionDb'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/connection_checker_test.js', ['Blockly.test.connectionChecker'], ['Blockly.ConnectionType', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/connection_db_test.js', ['Blockly.test.connectionDb'], ['Blockly.ConnectionType', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/connection_test.js', ['Blockly.test.connection'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'}); 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'}); @@ -40,7 +40,7 @@ goog.addDependency('../../tests/mocha/metrics_test.js', ['Blockly.test.metrics'] 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_helpers.js', ['Blockly.test.procedureHelpers'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/procedures_test_helpers.js', ['Blockly.test.procedureHelpers'], ['Blockly.ConnectionType'], {'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'}); diff --git a/tests/mocha/block_json_test.js b/tests/mocha/block_json_test.js index 2d6a83ee1..b93045960 100644 --- a/tests/mocha/block_json_test.js +++ b/tests/mocha/block_json_test.js @@ -6,6 +6,8 @@ goog.module('Blockly.test.blockJson'); +const {Align} = goog.require('Blockly.Input'); + suite('Block JSON initialization', function() { suite('validateTokens_', function() { @@ -564,7 +566,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'LEFT', }, - 'input_dummy', undefined, Blockly.ALIGN_LEFT); + 'input_dummy', undefined, Align.LEFT); }); test('"Right" align', function() { @@ -573,7 +575,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'RIGHT', }, - 'input_dummy', undefined, Blockly.ALIGN_RIGHT); + 'input_dummy', undefined, Align.RIGHT); }); test('"Center" align', function() { @@ -582,7 +584,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'CENTER', }, - 'input_dummy', undefined, Blockly.ALIGN_CENTRE); + 'input_dummy', undefined, Align.CENTRE); }); test('"Centre" align', function() { @@ -591,7 +593,7 @@ suite('Block JSON initialization', function() { 'type': 'input_dummy', 'align': 'CENTRE', }, - 'input_dummy', undefined, Blockly.ALIGN_CENTRE); + 'input_dummy', undefined, Align.CENTRE); }); }); }); diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 91e86594a..36cc583d9 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -8,6 +8,7 @@ goog.module('Blockly.test.blocks'); const eventUtils = goog.require('Blockly.Events.utils'); const {Blocks} = goog.require('Blockly.blocks'); +const {ConnectionType} = goog.require('Blockly.ConnectionType'); const {createDeprecationWarningStub, createRenderedBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers'); @@ -397,19 +398,19 @@ suite('Blocks', function() { this.getInputs = function() { return this.workspace - .connectionDBList[Blockly.INPUT_VALUE].connections_; + .connectionDBList[ConnectionType.INPUT_VALUE].connections_; }; this.getOutputs = function() { return this.workspace - .connectionDBList[Blockly.OUTPUT_VALUE].connections_; + .connectionDBList[ConnectionType.OUTPUT_VALUE].connections_; }; this.getNext = function() { return this.workspace - .connectionDBList[Blockly.NEXT_STATEMENT].connections_; + .connectionDBList[ConnectionType.NEXT_STATEMENT].connections_; }; this.getPrevious = function() { return this.workspace - .connectionDBList[Blockly.PREVIOUS_STATEMENT].connections_; + .connectionDBList[ConnectionType.PREVIOUS_STATEMENT].connections_; }; this.assertConnectionsEmpty = function() { diff --git a/tests/mocha/connection_checker_test.js b/tests/mocha/connection_checker_test.js index b5fbf8163..53582daaf 100644 --- a/tests/mocha/connection_checker_test.js +++ b/tests/mocha/connection_checker_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.connectionChecker'); +const {ConnectionType} = goog.require('Blockly.ConnectionType'); const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -27,7 +28,7 @@ suite('Connection checker', function() { } test('Target Null', function() { - const connection = new Blockly.Connection({}, Blockly.INPUT_VALUE); + const connection = new Blockly.Connection({}, ConnectionType.INPUT_VALUE); assertReasonHelper( this.checker, connection, @@ -36,8 +37,8 @@ suite('Connection checker', function() { }); test('Target Self', function() { const block = {workspace: 1}; - const connection1 = new Blockly.Connection(block, Blockly.INPUT_VALUE); - const connection2 = new Blockly.Connection(block, Blockly.OUTPUT_VALUE); + const connection1 = new Blockly.Connection(block, ConnectionType.INPUT_VALUE); + const connection2 = new Blockly.Connection(block, ConnectionType.OUTPUT_VALUE); assertReasonHelper( this.checker, @@ -47,9 +48,9 @@ suite('Connection checker', function() { }); test('Different Workspaces', function() { const connection1 = new Blockly.Connection( - {workspace: 1}, Blockly.INPUT_VALUE); + {workspace: 1}, ConnectionType.INPUT_VALUE); const connection2 = new Blockly.Connection( - {workspace: 2}, Blockly.OUTPUT_VALUE); + {workspace: 2}, ConnectionType.OUTPUT_VALUE); assertReasonHelper( this.checker, @@ -66,13 +67,13 @@ suite('Connection checker', function() { const outBlock = {isShadow: function() {}}; const inBlock = {isShadow: function() {}}; this.previous = new Blockly.Connection( - prevBlock, Blockly.PREVIOUS_STATEMENT); + prevBlock, ConnectionType.PREVIOUS_STATEMENT); this.next = new Blockly.Connection( - nextBlock, Blockly.NEXT_STATEMENT); + nextBlock, ConnectionType.NEXT_STATEMENT); this.output = new Blockly.Connection( - outBlock, Blockly.OUTPUT_VALUE); + outBlock, ConnectionType.OUTPUT_VALUE); this.input = new Blockly.Connection( - inBlock, Blockly.INPUT_VALUE); + inBlock, ConnectionType.INPUT_VALUE); }); test('Previous, Next', function() { assertReasonHelper( @@ -163,8 +164,8 @@ suite('Connection checker', function() { test('Previous Shadow', function() { const prevBlock = {isShadow: function() {return true;}}; const nextBlock = {isShadow: function() {return false;}}; - const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT); - const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT); + const prev = new Blockly.Connection(prevBlock, ConnectionType.PREVIOUS_STATEMENT); + const next = new Blockly.Connection(nextBlock, ConnectionType.NEXT_STATEMENT); assertReasonHelper( this.checker, @@ -175,8 +176,8 @@ suite('Connection checker', function() { test('Next Shadow', function() { const prevBlock = {isShadow: function() {return false;}}; const nextBlock = {isShadow: function() {return true;}}; - const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT); - const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT); + const prev = new Blockly.Connection(prevBlock, ConnectionType.PREVIOUS_STATEMENT); + const next = new Blockly.Connection(nextBlock, ConnectionType.NEXT_STATEMENT); assertReasonHelper( this.checker, @@ -187,8 +188,8 @@ suite('Connection checker', function() { test('Prev and Next Shadow', function() { const prevBlock = {isShadow: function() {return true;}}; const nextBlock = {isShadow: function() {return true;}}; - const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT); - const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT); + const prev = new Blockly.Connection(prevBlock, ConnectionType.PREVIOUS_STATEMENT); + const next = new Blockly.Connection(nextBlock, ConnectionType.NEXT_STATEMENT); assertReasonHelper( this.checker, @@ -199,8 +200,8 @@ suite('Connection checker', function() { test('Output Shadow', function() { const outBlock = {isShadow: function() {return true;}}; const inBlock = {isShadow: function() {return false;}}; - const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE); - const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE); + const outCon = new Blockly.Connection(outBlock, ConnectionType.OUTPUT_VALUE); + const inCon = new Blockly.Connection(inBlock, ConnectionType.INPUT_VALUE); assertReasonHelper( this.checker, @@ -211,8 +212,8 @@ suite('Connection checker', function() { test('Input Shadow', function() { const outBlock = {isShadow: function() {return false;}}; const inBlock = {isShadow: function() {return true;}}; - const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE); - const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE); + const outCon = new Blockly.Connection(outBlock, ConnectionType.OUTPUT_VALUE); + const inCon = new Blockly.Connection(inBlock, ConnectionType.INPUT_VALUE); assertReasonHelper( this.checker, @@ -223,8 +224,8 @@ suite('Connection checker', function() { test('Output and Input Shadow', function() { const outBlock = {isShadow: function() {return true;}}; const inBlock = {isShadow: function() {return true;}}; - const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE); - const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE); + const outCon = new Blockly.Connection(outBlock, ConnectionType.OUTPUT_VALUE); + const inCon = new Blockly.Connection(inBlock, ConnectionType.INPUT_VALUE); assertReasonHelper( this.checker, @@ -255,17 +256,17 @@ suite('Connection checker', function() { isShadow: function() { }, }; - const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE); - const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE); + const outCon = new Blockly.Connection(outBlock, ConnectionType.OUTPUT_VALUE); + const inCon = new Blockly.Connection(inBlock, ConnectionType.INPUT_VALUE); outBlock.outputConnection = outCon; inBlock.inputConnection = inCon; connectReciprocally(inCon, outCon); - const prevCon = new Blockly.Connection(outBlock, Blockly.PREVIOUS_STATEMENT); + const prevCon = new Blockly.Connection(outBlock, ConnectionType.PREVIOUS_STATEMENT); const nextBlock = { isShadow: function() { }, }; - const nextCon = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT); + const nextCon = new Blockly.Connection(nextBlock, ConnectionType.NEXT_STATEMENT); assertReasonHelper( this.checker, @@ -282,17 +283,17 @@ suite('Connection checker', function() { isShadow: function() { }, }; - const prevCon = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT); - const nextCon = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT); + const prevCon = new Blockly.Connection(prevBlock, ConnectionType.PREVIOUS_STATEMENT); + const nextCon = new Blockly.Connection(nextBlock, ConnectionType.NEXT_STATEMENT); prevBlock.previousConnection = prevCon; nextBlock.nextConnection = nextCon; connectReciprocally(prevCon, nextCon); - const outCon = new Blockly.Connection(prevBlock, Blockly.OUTPUT_VALUE); + const outCon = new Blockly.Connection(prevBlock, ConnectionType.OUTPUT_VALUE); const inBlock = { isShadow: function() { }, }; - const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE); + const inCon = new Blockly.Connection(inBlock, ConnectionType.INPUT_VALUE); assertReasonHelper( this.checker, @@ -304,8 +305,8 @@ suite('Connection checker', function() { }); suite('Check Types', function() { setup(function() { - this.con1 = new Blockly.Connection({}, Blockly.PREVIOUS_STATEMENT); - this.con2 = new Blockly.Connection({}, Blockly.NEXT_STATEMENT); + this.con1 = new Blockly.Connection({}, ConnectionType.PREVIOUS_STATEMENT); + this.con2 = new Blockly.Connection({}, ConnectionType.NEXT_STATEMENT); }); function assertCheckTypes(checker, one, two) { chai.assert.isTrue(checker.doTypeChecks(one, two)); diff --git a/tests/mocha/connection_db_test.js b/tests/mocha/connection_db_test.js index 4936d703d..83ec64663 100644 --- a/tests/mocha/connection_db_test.js +++ b/tests/mocha/connection_db_test.js @@ -6,6 +6,7 @@ goog.module('Blockly.test.connectionDb'); +const {ConnectionType} = goog.require('Blockly.ConnectionType'); const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); @@ -34,7 +35,7 @@ suite('Connection Database', function() { }; this.createSimpleTestConnections = function() { for (let i = 0; i < 10; i++) { - const connection = this.createConnection(0, i, Blockly.PREVIOUS_STATEMENT); + const connection = this.createConnection(0, i, ConnectionType.PREVIOUS_STATEMENT); this.database.addConnection(connection, i); } }; @@ -112,14 +113,14 @@ suite('Connection Database', function() { }); suite('Get Neighbors', function() { test('Empty Database', function() { - const connection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT, + const connection = this.createConnection(0, 0, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); chai.assert.isEmpty(this.database.getNeighbours(connection), 100); }); test('Block At Top', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 0, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 4); chai.assert.sameMembers(neighbors, this.database.connections_.slice(0, 5)); @@ -127,7 +128,7 @@ suite('Connection Database', function() { test('Block In Middle', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(0, 4, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 4, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 2); chai.assert.sameMembers(neighbors, this.database.connections_.slice(2, 7)); @@ -135,7 +136,7 @@ suite('Connection Database', function() { test('Block At End', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(0, 9, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 9, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 4); chai.assert.sameMembers(neighbors, this.database.connections_.slice(5, 10)); @@ -143,7 +144,7 @@ suite('Connection Database', function() { test('Out of Range X', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(10, 9, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(10, 9, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 4); chai.assert.isEmpty(neighbors); @@ -151,7 +152,7 @@ suite('Connection Database', function() { test('Out of Range Y', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(0, 19, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 19, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 4); chai.assert.isEmpty(neighbors); @@ -159,7 +160,7 @@ suite('Connection Database', function() { test('Out of Range Diagonal', function() { this.createSimpleTestConnections(); - const checkConnection = this.createConnection(-2, -2, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(-2, -2, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); const neighbors = this.database.getNeighbours(checkConnection, 2); chai.assert.isEmpty(neighbors); @@ -168,7 +169,7 @@ suite('Connection Database', function() { suite('Ordering', function() { test('Simple', function() { for (let i = 0; i < 10; i++) { - const connection = this.createConnection(0, i, Blockly.NEXT_STATEMENT); + const connection = this.createConnection(0, i, ConnectionType.NEXT_STATEMENT); this.database.addConnection(connection, i); } this.assertOrder(); @@ -192,7 +193,7 @@ suite('Connection Database', function() { const length = xCoords.length; for (let i = 0; i < length; i++) { const connection = this.createConnection(xCoords[i], yCoords[i], - Blockly.NEXT_STATEMENT); + ConnectionType.NEXT_STATEMENT); this.database.addConnection(connection, yCoords[i]); } this.assertOrder(); @@ -214,22 +215,22 @@ suite('Connection Database', function() { }); this.createCheckConnection = function(x, y) { - const checkConnection = this.createConnection(x, y, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(x, y, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); return checkConnection; }; }); test('Empty Database', function() { - const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 0, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); chai.assert.isNull(this.database.searchForClosest( checkConnection, 100, {x: 0, y: 0}).connection); }); test('Too Far', function() { - const connection = this.createConnection(0, 100, Blockly.PREVIOUS_STATEMENT); + const connection = this.createConnection(0, 100, ConnectionType.PREVIOUS_STATEMENT); this.database.addConnection(connection, 100); - const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT, + const checkConnection = this.createConnection(0, 0, ConnectionType.NEXT_STATEMENT, new Blockly.ConnectionDB()); chai.assert.isNull(this.database.searchForClosest( checkConnection, 50, {x: 0, y: 0}).connection); @@ -255,9 +256,9 @@ suite('Connection Database', function() { chai.assert.equal(last, closest); }); test('No Y-Coord Priority', function() { - const connection1 = this.createConnection(6, 6, Blockly.PREVIOUS_STATEMENT); + const connection1 = this.createConnection(6, 6, ConnectionType.PREVIOUS_STATEMENT); this.database.addConnection(connection1, 6); - const connection2 = this.createConnection(5, 5, Blockly.PREVIOUS_STATEMENT); + const connection2 = this.createConnection(5, 5, ConnectionType.PREVIOUS_STATEMENT); this.database.addConnection(connection2, 5); const checkConnection = this.createCheckConnection(4, 6); diff --git a/tests/mocha/procedures_test_helpers.js b/tests/mocha/procedures_test_helpers.js index 1479bcf30..deb75a5ba 100644 --- a/tests/mocha/procedures_test_helpers.js +++ b/tests/mocha/procedures_test_helpers.js @@ -5,6 +5,9 @@ */ goog.module('Blockly.test.procedureHelpers'); +const {ConnectionType} = goog.require('Blockly.ConnectionType'); + + /** * Asserts that the procedure definition or call block has the expected var * models. @@ -33,7 +36,7 @@ function assertCallBlockArgsStructure(callBlock, args) { for (let i = 0; i < args.length; i++) { const expectedName = args[i]; const callInput = callBlock.inputList[i + 1]; - chai.assert.equal(callInput.type, Blockly.INPUT_VALUE); + chai.assert.equal(callInput.type, ConnectionType.INPUT_VALUE); chai.assert.equal(callInput.name, 'ARG' + i); chai.assert.equal(callInput.fieldRow[0].getValue(), expectedName, 'Call block consts did not match expected.'); diff --git a/tests/mocha/toolbox_test.js b/tests/mocha/toolbox_test.js index acaededd5..b717060d4 100644 --- a/tests/mocha/toolbox_test.js +++ b/tests/mocha/toolbox_test.js @@ -32,7 +32,7 @@ suite('Toolbox', function() { chai.assert.isDefined(this.toolbox.HtmlDiv); }); test('Init called -> HtmlDiv is inserted before parent node', function() { - const toolboxDiv = Blockly.getMainWorkspace().getInjectionDiv().childNodes[0]; + const toolboxDiv = Blockly.common.getMainWorkspace().getInjectionDiv().childNodes[0]; chai.assert.equal(toolboxDiv.className, 'blocklyToolboxDiv blocklyNonSelectable'); });