Skip to content

Commit

Permalink
test: selectBlockByType allows computed offset
Browse files Browse the repository at this point in the history
Allowing composing offsets based upon the block dimensions, making it
easier to target, e.g., the top-left corner.
  • Loading branch information
dcalhoun committed Feb 20, 2024
1 parent dbcd2c7 commit b0dd8e2
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/react-native-editor/__device-tests__/pages/editor-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b0dd8e2

Please sign in to comment.