diff --git a/src/CONST.ts b/src/CONST.ts index f9229d5185b4..587ca0d3e641 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -874,6 +874,7 @@ const CONST = { CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action', SEARCH_RENDER: 'search_render', CHAT_RENDER: 'chat_render', + OPEN_REPORT: 'open_report', HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render', REPORT_INITIAL_RENDER: 'report_initial_render', SWITCH_REPORT: 'switch_report', diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index fbcb7d4b373d..25cc53340dd5 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -20,6 +20,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; import DomUtils from '@libs/DomUtils'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import Performance from '@libs/Performance'; import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager'; import * as ReportUtils from '@libs/ReportUtils'; import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu'; @@ -123,6 +124,8 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti { + Performance.markStart(CONST.TIMING.OPEN_REPORT); + event?.preventDefault(); // Enable Composer to focus on clicking the same chat after opening the context menu. ReportActionComposeFocusManager.focus(); diff --git a/src/libs/E2E/tests/chatOpeningTest.e2e.ts b/src/libs/E2E/tests/chatOpeningTest.e2e.ts index 17d9dfa1cb4d..8e43c4ece564 100644 --- a/src/libs/E2E/tests/chatOpeningTest.e2e.ts +++ b/src/libs/E2E/tests/chatOpeningTest.e2e.ts @@ -1,8 +1,10 @@ +import Config from 'react-native-config'; 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 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 CONST from '@src/CONST'; @@ -23,29 +25,55 @@ const test = (config: NativeConfig) => { } console.debug('[E2E] Logged in, getting chat opening metrics and submitting them…'); + + const [renderChatPromise, renderChatResolve] = getPromiseWithResolve(); + const [chatTTIPromise, chatTTIResolve] = getPromiseWithResolve(); + + Promise.all([renderChatPromise, chatTTIPromise]).then(() => { + console.debug(`[E2E] Submitting!`); + + E2EClient.submitTestDone(); + }); + Performance.subscribeToMeasurements((entry) => { if (entry.name === CONST.TIMING.SIDEBAR_LOADED) { console.debug(`[E2E] Sidebar loaded, navigating to report…`); + Performance.markStart(CONST.TIMING.OPEN_REPORT); Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID)); return; } + console.debug(`[E2E] Entry: ${JSON.stringify(entry)}`); - if (entry.name !== CONST.TIMING.CHAT_RENDER) { - return; + + if (entry.name === CONST.TIMING.CHAT_RENDER) { + E2EClient.submitTestResults({ + branch: Config.E2E_BRANCH, + name: 'Chat opening', + duration: entry.duration, + }) + .then(() => { + console.debug('[E2E] Done with chat opening, exiting…'); + renderChatResolve(); + }) + .catch((err) => { + console.debug('[E2E] Error while submitting test results:', err); + }); } - console.debug(`[E2E] Submitting!`); - E2EClient.submitTestResults({ - name: 'Chat opening', - duration: entry.duration, - }) - .then(() => { - console.debug('[E2E] Done with chat opening, exiting…'); - E2EClient.submitTestDone(); + if (entry.name === CONST.TIMING.OPEN_REPORT) { + E2EClient.submitTestResults({ + branch: Config.E2E_BRANCH, + name: 'Chat TTI', + duration: entry.duration, }) - .catch((err) => { - console.debug('[E2E] Error while submitting test results:', err); - }); + .then(() => { + console.debug('[E2E] Done with chat TTI tracking, exiting…'); + chatTTIResolve(); + }) + .catch((err) => { + console.debug('[E2E] Error while submitting test results:', err); + }); + } }); }); }; diff --git a/src/libs/E2E/utils/getPromiseWithResolve.ts b/src/libs/E2E/utils/getPromiseWithResolve.ts new file mode 100644 index 000000000000..fd49cd82c513 --- /dev/null +++ b/src/libs/E2E/utils/getPromiseWithResolve.ts @@ -0,0 +1,9 @@ +export default function getPromiseWithResolve(): [Promise, (value?: T) => void] { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + let resolveFn = (_value?: T) => {}; + const promise = new Promise((resolve) => { + resolveFn = resolve; + }); + + return [promise, resolveFn]; +} diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 6040c1e67212..e6ae2c155d65 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -381,6 +381,7 @@ function ReportActionsView({ didLayout.current = true; // Capture the init measurement only once not per each chat switch as the value gets overwritten if (!ReportActionsView.initMeasured) { + Performance.markEnd(CONST.TIMING.OPEN_REPORT); Performance.markEnd(CONST.TIMING.REPORT_INITIAL_RENDER); Timing.end(CONST.TIMING.REPORT_INITIAL_RENDER); ReportActionsView.initMeasured = true;