From b0dd8e2dff4c350fb79814d79dc325b7d85dbb9a Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 20 Feb 2024 12:57:13 -0500 Subject: [PATCH] test: `selectBlockByType` allows computed offset Allowing composing offsets based upon the block dimensions, making it easier to target, e.g., the top-left corner. --- .../__device-tests__/pages/editor-page.js | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/react-native-editor/__device-tests__/pages/editor-page.js b/packages/react-native-editor/__device-tests__/pages/editor-page.js index d8c5c91f38de7..65672337e2a2a 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -208,20 +208,36 @@ class EditorPage { /** * Selects a block by its type. * - * @param {string} blockType The type of the block to select. - * @param {Object} options Additional options. - * @param {number} options.index The index of the block to select (default: 1). - * @param {number} options.x The x-coordinate offset from the center of the element (default: 0). - * @param {number} options.y The y-coordinate offset from the center of the element (default: 0). + * @param {string} blockType The type of the block to select. + * @param {Object} options Additional options. + * @param {number} options.index The index of the block to select (default: 1). + * @param {Object} options.offset The offset of the block to select (default: { x: 0, y: 0 }). * * @return {import('webdriverio').ChainablePromiseArray} The selected block element. */ - async selectBlockByType( blockType, { index = 1, x = 0, y = 0 } = {} ) { + async selectBlockByType( + blockType, + { index = 1, offset = { x: 0, y: 0 } } = {} + ) { const locator = isAndroid() ? `//android.widget.Button[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockType } Block. Row ${ index }")]` : `-ios predicate string:label == '${ blockType } Block. Row ${ index }'`; const block = await this.driver.$$( locator )[ 0 ]; - await block.click( { x, y } ); + + const size = await block.getSize(); + + let offsetX = offset.x; + if ( typeof offset.x === 'function' ) { + offsetX = offset.x( size.width ); + } + + let offsetY = offset.y; + if ( typeof offset.y === 'function' ) { + offsetY = offset.y( size.height ); + } + + await block.click( { x: offsetX, y: offsetY } ); + return block; }