Skip to content

Commit

Permalink
Merge pull request #53854 from margelo/@perunt/linking-test-fix
Browse files Browse the repository at this point in the history
[No QA] Improve stability of linking test
  • Loading branch information
puneetlath authored Dec 12, 2024
2 parents 1f36abb + 25967ae commit 629a083
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions src/libs/E2E/tests/linkingTest.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,80 @@ const test = (config: NativeConfig) => {
const linkedReportActionID = getConfigValueOrThrow('linkedReportActionID', config);
const name = getConfigValueOrThrow('name', config);

const startTestTime = Date.now();
console.debug('[E2E] Test started at:', startTestTime);

E2ELogin().then((neededLogin) => {
if (neededLogin) {
return waitForAppLoaded().then(() => E2EClient.submitTestDone());
}

const [appearMessagePromise, appearMessageResolve] = getPromiseWithResolve();
const [openReportPromise, openReportResolve] = getPromiseWithResolve();
let lastVisibleMessageId: string | undefined;
let verificationStarted = false;
let hasNavigatedToLinkedMessage = false;

const subscription = DeviceEventEmitter.addListener('onViewableItemsChanged', (res: ViewableItemResponse) => {
console.debug('[E2E] Viewable items event triggered at:', Date.now());

// update the last visible message
lastVisibleMessageId = res?.at(0)?.item?.reportActionID;
console.debug('[E2E] Current visible message:', lastVisibleMessageId);

if (!verificationStarted && lastVisibleMessageId === linkedReportActionID) {
console.debug('[E2E] Target message found, starting verification');
verificationStarted = true;

setTimeout(() => {
console.debug('[E2E] Verification timeout completed');
console.debug('[E2E] Last visible message ID:', lastVisibleMessageId);
console.debug('[E2E] Expected message ID:', linkedReportActionID);

subscription.remove();
if (lastVisibleMessageId === linkedReportActionID) {
console.debug('[E2E] Message position verified successfully');
appearMessageResolve();
} else {
console.debug('[E2E] Linked message not found, failing test!');
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
error: 'Linked message not found',
name: `${name} test can't find linked message`,
}).then(() => E2EClient.submitTestDone());
}
}, 3000);
}
});

Promise.all([appearMessagePromise, openReportPromise])
.then(() => {
console.debug('[E2E] Test completed successfully, exiting…');
console.debug('[E2E] Test completed successfully at:', Date.now());
console.debug('[E2E] Total test duration:', Date.now() - startTestTime, 'ms');
E2EClient.submitTestDone();
})
.catch((err) => {
console.debug('[E2E] Error while submitting test results:', err);
});

const subscription = DeviceEventEmitter.addListener('onViewableItemsChanged', (res: ViewableItemResponse) => {
console.debug('[E2E] Viewable items retrieved, verifying correct message…', res);

if (!!res && res?.at(0)?.item?.reportActionID === linkedReportActionID) {
appearMessageResolve();
subscription.remove();
} else {
console.debug(`[E2E] Provided message id '${res?.at(0)?.item?.reportActionID}' doesn't match to an expected '${linkedReportActionID}'. Waiting for a next one…`);
}
});

Performance.subscribeToMeasurements((entry) => {
console.debug(`[E2E] Performance entry captured: ${entry.name} at ${entry.startTime}, duration: ${entry.duration} ms`);

if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
console.debug('[E2E] Sidebar loaded, navigating to a report…');
console.debug('[E2E] Sidebar loaded, navigating to a report at:', Date.now());
const startNavigateTime = Date.now();
Performance.markStart(CONST.TIMING.OPEN_REPORT);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID));
console.debug('[E2E] Navigation to report took:', Date.now() - startNavigateTime, 'ms');
return;
}

if (entry.name === CONST.TIMING.OPEN_REPORT) {
console.debug('[E2E] Linking: 1');
console.debug('[E2E] Navigating to the linked report action…');
if (entry.name === CONST.TIMING.OPEN_REPORT && !hasNavigatedToLinkedMessage) {
console.debug('[E2E] Navigating to the linked report action at:', Date.now());
const startLinkedNavigateTime = Date.now();
hasNavigatedToLinkedMessage = true; // Set flag to prevent duplicate navigation
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(linkedReportID, linkedReportActionID));
console.debug('[E2E] Navigation to linked report took:', Date.now() - startLinkedNavigateTime, 'ms');

E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
Expand Down

0 comments on commit 629a083

Please sign in to comment.