diff --git a/src/e2e/iOS/__tests__/caret.ts b/src/e2e/iOS/__tests__/caret.ts index 29e773dc8f0..87d41810ef8 100644 --- a/src/e2e/iOS/__tests__/caret.ts +++ b/src/e2e/iOS/__tests__/caret.ts @@ -251,4 +251,23 @@ describe('Caret', () => { expect(selectionTextContent).toBe('new') expect(childrenTexts).toEqual(['foo', 'bar']) }) + + it('Focus is prevented after clearing the cursor', async () => { + await newThought('Hello') + await hideKeyboardByTappingDone() + + // Use a native WebDriver click on the inner anchor to clear the cursor. + // A synthetic tap() (performActions pointer events) does not fire the real + // click event that HomeLink's fastClick onClick handler relies on, so the + // cursor would never be cleared. + await browser.$('[data-testid="home"] a').click() + + await tap(await waitForEditable('Hello'), { horizontalTapLine: 'right', x: 6, y: 60, pointerType: 'touch' }) + + // Wait for focus to be cleared and activeElement to be body + await waitUntil(() => browser.execute(() => document.activeElement === document.body)) + + const activeElementIsBody = await browser.execute(() => document.activeElement === document.body) + expect(activeElementIsBody).toBe(true) + }) }) diff --git a/src/e2e/iOS/helpers/tap.ts b/src/e2e/iOS/helpers/tap.ts index 824f792f39e..dc7033fcbec 100644 --- a/src/e2e/iOS/helpers/tap.ts +++ b/src/e2e/iOS/helpers/tap.ts @@ -5,6 +5,8 @@ import type { Element } from 'webdriverio' interface Options { // Where in the horizontal line (inside) of the target node should be tapped horizontalTapLine?: 'left' | 'right' + // Pointer type to use for the tap action. Defaults to 'mouse'. + pointerType?: 'mouse' | 'touch' // Specify specific node on editable to tap. Overrides horizontalClickLine offset?: number // Number of pixels of x offset to add to the tap coordinates @@ -21,7 +23,7 @@ interface Options { */ const tap = async ( nodeHandle: Element, - { horizontalTapLine = 'left', offset, x = 0, y = 0, releaseDelayMs = 100 }: Options = {}, + { horizontalTapLine = 'left', offset, x = 0, y = 0, pointerType = 'mouse', releaseDelayMs = 100 }: Options = {}, ) => { // Ensure element exists and has an elementId const exists = await nodeHandle.isExisting() @@ -98,7 +100,7 @@ const tap = async ( { type: 'pointer', id: 'pointer1', - parameters: { pointerType: 'mouse' }, + parameters: { pointerType }, actions: [ { type: 'pointerMove',