Fix server history with tapAndWaitFor

This commit is contained in:
Diego Mello 2023-02-16 09:46:50 -03:00
parent b2204619e8
commit 6ea3e70ad2
2 changed files with 20 additions and 18 deletions

View File

@ -180,7 +180,6 @@ async function tryTapping(theElement: Detox.IndexableNativeElement, timeout: num
} }
} catch (e) { } catch (e) {
if (timeout <= 0) { if (timeout <= 0) {
// TODO: Maths. How closely has the timeout been honoured here?
throw e; throw e;
} }
await sleep(100); 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 checkServer = async (server: string) => {
const label = `Connected to ${server}`; const label = `Connected to ${server}`;
await element(by.id('rooms-list-view-sidebar')).tap(); await element(by.id('rooms-list-view-sidebar')).tap();
@ -206,18 +222,6 @@ const checkServer = async (server: string) => {
.withTimeout(10000); .withTimeout(10000);
}; };
function runCommand(command: string) {
return new Promise<void>((resolve, reject) => {
exec(command, (error, _stdout, stderr) => {
if (error) {
reject(new Error(`exec error: ${stderr}`));
return;
}
resolve();
});
});
}
export { export {
navigateToWorkspace, navigateToWorkspace,
navigateToLogin, navigateToLogin,
@ -232,6 +236,7 @@ export {
sleep, sleep,
searchRoom, searchRoom,
tryTapping, tryTapping,
tapAndWaitFor,
checkServer, checkServer,
platformTypes platformTypes
}; };

View File

@ -1,6 +1,6 @@
import { expect } from 'detox'; 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'; import data from '../../data';
describe('Server history', () => { describe('Server history', () => {
@ -42,10 +42,7 @@ describe('Server history', () => {
await waitFor(element(by.id('new-server-view'))) await waitFor(element(by.id('new-server-view')))
.toBeVisible() .toBeVisible()
.withTimeout(2000); .withTimeout(2000);
await element(by.id('new-server-view-input')).tap(); await tapAndWaitFor(element(by.id('new-server-view-input')), element(by.id(`server-history-${data.server}`)), 2000);
await waitFor(element(by.id(`server-history-${data.server}`)))
.toBeVisible()
.withTimeout(2000);
await element(by.id(`server-history-delete-${data.server}`)).tap(); await element(by.id(`server-history-delete-${data.server}`)).tap();
await element(by.id('new-server-view-input')).tap(); await element(by.id('new-server-view-input')).tap();
await waitFor(element(by.id(`server-history-${data.server}`))) await waitFor(element(by.id(`server-history-${data.server}`)))