From 6ea3e70ad23b149dd271dfe1e8b6e2f53826ec4b Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 16 Feb 2023 09:46:50 -0300 Subject: [PATCH] Fix server history with tapAndWaitFor --- e2e/helpers/app.ts | 31 +++++++++++-------- .../onboarding/07-server-history.spec.ts | 7 ++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/e2e/helpers/app.ts b/e2e/helpers/app.ts index b0a9a58b1..59c53f6c8 100644 --- a/e2e/helpers/app.ts +++ b/e2e/helpers/app.ts @@ -180,7 +180,6 @@ async function tryTapping(theElement: Detox.IndexableNativeElement, timeout: num } } catch (e) { if (timeout <= 0) { - // TODO: Maths. How closely has the timeout been honoured here? throw e; } await sleep(100); @@ -188,6 +187,23 @@ async function tryTapping(theElement: Detox.IndexableNativeElement, timeout: num } } +async function tapAndWaitFor( + elementToTap: Detox.IndexableNativeElement, + elementToWaitFor: Detox.IndexableNativeElement, + timeout: number +) { + try { + await elementToTap.tap(); + await waitFor(elementToWaitFor).toBeVisible().withTimeout(200); + } catch (e) { + if (timeout <= 0) { + throw e; + } + await sleep(100); + await tapAndWaitFor(elementToTap, elementToWaitFor, timeout - 100); + } +} + const checkServer = async (server: string) => { const label = `Connected to ${server}`; await element(by.id('rooms-list-view-sidebar')).tap(); @@ -206,18 +222,6 @@ const checkServer = async (server: string) => { .withTimeout(10000); }; -function runCommand(command: string) { - return new Promise((resolve, reject) => { - exec(command, (error, _stdout, stderr) => { - if (error) { - reject(new Error(`exec error: ${stderr}`)); - return; - } - resolve(); - }); - }); -} - export { navigateToWorkspace, navigateToLogin, @@ -232,6 +236,7 @@ export { sleep, searchRoom, tryTapping, + tapAndWaitFor, checkServer, platformTypes }; diff --git a/e2e/tests/onboarding/07-server-history.spec.ts b/e2e/tests/onboarding/07-server-history.spec.ts index 3fd78302d..ca9652b26 100644 --- a/e2e/tests/onboarding/07-server-history.spec.ts +++ b/e2e/tests/onboarding/07-server-history.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'detox'; -import { login, navigateToLogin, logout, tapBack } from '../../helpers/app'; +import { login, navigateToLogin, logout, tapBack, tryTapping, tapAndWaitFor } from '../../helpers/app'; import data from '../../data'; describe('Server history', () => { @@ -42,10 +42,7 @@ describe('Server history', () => { await waitFor(element(by.id('new-server-view'))) .toBeVisible() .withTimeout(2000); - await element(by.id('new-server-view-input')).tap(); - await waitFor(element(by.id(`server-history-${data.server}`))) - .toBeVisible() - .withTimeout(2000); + await tapAndWaitFor(element(by.id('new-server-view-input')), element(by.id(`server-history-${data.server}`)), 2000); await element(by.id(`server-history-delete-${data.server}`)).tap(); await element(by.id('new-server-view-input')).tap(); await waitFor(element(by.id(`server-history-${data.server}`)))