Skip to content

Commit

Permalink
fix: flat test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 19, 2024
1 parent 5cf41fe commit 29cbff0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
17 changes: 15 additions & 2 deletions src/libs/E2E/interactions/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {DeviceEventEmitter} from 'react-native';
import * as E2EGenericPressableWrapper from '@components/Pressable/GenericPressable/index.e2e';
import Performance from '@libs/Performance';

const waitFor = (testID: string) => {
const waitForElement = (testID: string) => {
return new Promise((resolve) => {
const subscription = DeviceEventEmitter.addListener('onBecameVisible', (_testID: string) => {
if (_testID !== testID) {
Expand All @@ -14,8 +15,20 @@ const waitFor = (testID: string) => {
});
};

const waitForEvent = (eventName: string): Promise<PerformanceEntry> => {
return new Promise((resolve) => {
Performance.subscribeToMeasurements((entry) => {
if (entry.name !== eventName) {
return;
}

resolve(entry);
});
});
};

const tap = (testID: string) => {
E2EGenericPressableWrapper.getPressableProps(testID)?.onPress?.();
};

export {waitFor, tap};
export {waitForElement, tap, waitForEvent};
64 changes: 26 additions & 38 deletions src/libs/E2E/tests/moneyRequestTest.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import type {NativeConfig} from 'react-native-config';
import E2ELogin from '@libs/E2E/actions/e2eLogin';
import waitForAppLoaded from '@libs/E2E/actions/waitForAppLoaded';
import E2EClient from '@libs/E2E/client';
import {tap, waitForElement, waitForEvent} from '@libs/E2E/interactions';
import getConfigValueOrThrow from '@libs/E2E/utils/getConfigValueOrThrow';
import getPromiseWithResolve from '@libs/E2E/utils/getPromiseWithResolve';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import {tap, waitFor} from '../interactions';

const test = (config: NativeConfig) => {
// check for login (if already logged in the action will simply resolve)
Expand All @@ -26,37 +25,18 @@ const test = (config: NativeConfig) => {
);
}

const [appearSubmitExpenseScreenPromise, appearSubmitExpenseScreenResolve] = getPromiseWithResolve();
const [appearContactsScreenPromise, appearContactsScreenResolve] = getPromiseWithResolve();
const [approveScreenPromise, approveScreenResolve] = getPromiseWithResolve();

Promise.all([appearSubmitExpenseScreenPromise, appearContactsScreenPromise, approveScreenPromise])
.then(() => {
console.debug('[E2E] Test completed successfully, exiting…');
E2EClient.submitTestDone();
})
.catch((err) => {
console.debug('[E2E] Error while submitting test results:', err);
});

console.debug('[E2E] Logged in, getting money request metrics and submitting them…');

waitFor('+66 65 490 0617').then(() => {
Performance.markStart(CONST.TIMING.OPEN_SUBMIT_EXPENSE_APPROVE);
tap('+66 65 490 0617');
});

Performance.subscribeToMeasurements((entry) => {
if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
waitForEvent(CONST.TIMING.SIDEBAR_LOADED)
.then(() => {
console.debug(`[E2E] Sidebar loaded, navigating to submit expense…`);
Performance.markStart(CONST.TIMING.OPEN_SUBMIT_EXPENSE);
Navigation.navigate(
ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID()),
);
}

if (entry.name === CONST.TIMING.OPEN_SUBMIT_EXPENSE) {
appearSubmitExpenseScreenResolve();
})
.then(() => waitForEvent(CONST.TIMING.OPEN_SUBMIT_EXPENSE))
.then((entry) => {
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
name: `${name} - Open Manual Tracking`,
Expand All @@ -65,34 +45,42 @@ const test = (config: NativeConfig) => {
});
setTimeout(() => {
tap('button_2');
}, 1000);
}, 2000);
setTimeout(() => {
Performance.markStart(CONST.TIMING.OPEN_SUBMIT_EXPENSE_CONTACT);
tap('next-button');
}, 4000);
}

if (entry.name === CONST.TIMING.OPEN_SUBMIT_EXPENSE_CONTACT) {
})
.then(() => waitForEvent(CONST.TIMING.OPEN_SUBMIT_EXPENSE_CONTACT))
.then((entry) => {
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
name: `${name} - Open Contacts`,
metric: entry.duration,
unit: 'ms',
});
appearContactsScreenResolve();
console.log(111);
}

if (entry.name === CONST.TIMING.OPEN_SUBMIT_EXPENSE_APPROVE) {
})
.then(() => waitForElement('+66 65 490 0617'))
.then(() => {
Performance.markStart(CONST.TIMING.OPEN_SUBMIT_EXPENSE_APPROVE);
tap('+66 65 490 0617');
})
.then(() => waitForEvent(CONST.TIMING.OPEN_SUBMIT_EXPENSE_APPROVE))
.then((entry) => {
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
name: `${name} - Open Submit`,
metric: entry.duration,
unit: 'ms',
});
approveScreenResolve();
}
});
})
.then(() => {
console.debug('[E2E] Test completed successfully, exiting…');
E2EClient.submitTestDone();
})
.catch((err) => {
console.debug('[E2E] Error while submitting test results:', err);
});
});
};

Expand Down

0 comments on commit 29cbff0

Please sign in to comment.