diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 5af85b9e6847d0..c44bc277155e2c 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -418,13 +418,20 @@ const selectTextFromElement = async ( driver, element ) => { } }; -// Starts from the middle of the screen or the element(if specified) -// and swipes upwards. +/** + * Starts from the middle of the screen or the element(if specified) + * and swipes upwards. + * + * @param {Object} driver WebdriverIO driver + * @param {Object} element Element to swipe from + * @param {Object} options Options + * @param {number} options.delay Delay between the swipe and the next action + * @param {number} options.endYCoefficient Multiplier for the end Y coordinate + */ const swipeUp = async ( driver, element = undefined, - delay = 3000, - endYCoefficient = 0.5 + { delay = 3000, endYCoefficient = 0.5 } = {} ) => { let size = await driver.getWindowSize(); let y = 0; @@ -465,15 +472,25 @@ const swipeFromTo = async ( .pause( delay ) .perform(); -// Starts from the middle of the screen and swipes downwards -const swipeDown = async ( driver, delay = 3000 ) => { +/** + * Starts from the middle of the screen and swipes downwards + * + * @param {Object} driver WebdriverIO driver + * @param {Object} options Options + * @param {number} options.delay Delay between the swipe and the next action + * @param {number} options.endYCoefficient Multiplier for the end Y coordinate + */ +const swipeDown = async ( + driver, + { delay = 3000, endYCoefficient = 0.5 } = {} +) => { const size = await driver.getWindowSize(); const y = 0; const startX = size.width / 2; const startY = y + size.height / 3; const endX = startX; - const endY = startY - startY * -1 * 0.5; + const endY = startY - startY * -1 * endYCoefficient; await swipeFromTo( driver, 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 fe3f410601a8dc..07b51d35f4ad9d 100644 --- a/packages/react-native-editor/__device-tests__/pages/editor-page.js +++ b/packages/react-native-editor/__device-tests__/pages/editor-page.js @@ -251,7 +251,7 @@ class EditorPage { if ( options.autoscroll ) { if ( isAndroid() ) { - await swipeDown( this.driver ); + await swipeDown( this.driver, { endYCoefficient: 2 } ); } else { await tapStatusBariOS( this.driver ); } @@ -288,7 +288,10 @@ class EditorPage { `//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityLabel }")]` ); if ( elements.length === 0 ) { - await swipeUp( this.driver, undefined, 100, 1 ); + await swipeUp( this.driver, undefined, { + delay: 100, + endYCoefficient: 1, + } ); return this.androidScrollAndReturnElement( accessibilityLabel ); } return elements[ elements.length - 1 ]; @@ -301,7 +304,10 @@ class EditorPage { const elements = await this.driver.$$( `~${ id }` ); if ( elements.length === 0 ) { - await swipeUp( this.driver, undefined, 100, 1 ); + await swipeUp( this.driver, undefined, { + delay: 100, + endYCoefficient: 1, + } ); return this.scrollAndReturnElementByAccessibilityId( id ); } return elements[ elements.length - 1 ]; @@ -668,46 +674,6 @@ class EditorPage { await moveDownButton.click(); } - // Position of the block to remove - // Block will no longer be present if this succeeds. - async removeBlockAtPosition( blockName = '', position = 1 ) { - if ( ! ( await this.hasBlockAtPosition( position, blockName ) ) ) { - throw Error( `No Block at position ${ position }` ); - } - - const buttonElementName = isAndroid() - ? '//*' - : '//XCUIElementTypeButton'; - const blockActionsMenuButtonIdentifier = `Open Block Actions Menu`; - const blockActionsMenuButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockActionsMenuButtonIdentifier }")]`; - if ( isAndroid() ) { - const block = await this.getBlockAtPosition( blockName, position ); - let checkList = await this.driver.$$( - blockActionsMenuButtonLocator - ); - while ( checkList.length === 0 ) { - await swipeUp( this.driver, block ); // Swipe up to show remove icon at the bottom. - checkList = await this.driver.$$( - blockActionsMenuButtonLocator - ); - } - } - - const blockActionsMenuButton = await waitForVisible( - this.driver, - blockActionsMenuButtonLocator - ); - await blockActionsMenuButton.click(); - const removeActionButtonIdentifier = 'Remove block'; - const removeActionButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ removeActionButtonIdentifier }")]`; - const removeActionButton = await waitForVisible( - this.driver, - removeActionButtonLocator - ); - - await removeActionButton.click(); - } - // ========================= // Formatting toolbar functions // =========================