Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Improve stability of linking test #53854

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading