From 8887c9989817064001e916113d35c9c7fbeec1f6 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Fri, 29 Mar 2024 11:26:56 +0100 Subject: [PATCH 1/2] feat: chat TTI --- src/CONST.ts | 1 + .../LHNOptionsList/OptionRowLHN.tsx | 3 + src/libs/E2E/tests/chatOpeningTest.e2e.ts | 63 +++++++++++++++---- src/pages/home/report/ReportActionsView.tsx | 1 + 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index c57ac575f7e6..6281ad586b8f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -849,6 +849,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 5065d1cc7c13..573c7eb6e824 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -21,6 +21,7 @@ import DateUtils from '@libs/DateUtils'; import DomUtils from '@libs/DomUtils'; import {getGroupChatName} from '@libs/GroupChatUtils'; 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..f06a9d857839 100644 --- a/src/libs/E2E/tests/chatOpeningTest.e2e.ts +++ b/src/libs/E2E/tests/chatOpeningTest.e2e.ts @@ -1,3 +1,4 @@ +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'; @@ -8,6 +9,16 @@ import Performance from '@libs/Performance'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; +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]; +} + const test = (config: NativeConfig) => { // check for login (if already logged in the action will simply resolve) console.debug('[E2E] Logging in for chat opening'); @@ -23,29 +34,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/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 1d66e9d99c22..ae936567af3c 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -346,6 +346,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; From 4b8e5f35990aa079aeac87363801b486a787282e Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 2 Apr 2024 17:41:54 +0200 Subject: [PATCH 2/2] refactor: move utility to separate file --- src/libs/E2E/tests/chatOpeningTest.e2e.ts | 11 +---------- src/libs/E2E/utils/getPromiseWithResolve.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 src/libs/E2E/utils/getPromiseWithResolve.ts diff --git a/src/libs/E2E/tests/chatOpeningTest.e2e.ts b/src/libs/E2E/tests/chatOpeningTest.e2e.ts index f06a9d857839..8e43c4ece564 100644 --- a/src/libs/E2E/tests/chatOpeningTest.e2e.ts +++ b/src/libs/E2E/tests/chatOpeningTest.e2e.ts @@ -4,21 +4,12 @@ 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'; import ROUTES from '@src/ROUTES'; -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]; -} - const test = (config: NativeConfig) => { // check for login (if already logged in the action will simply resolve) console.debug('[E2E] Logging in for chat opening'); 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]; +}