From 55fceb1ad731bd95461db946f13c342f860ff233 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 12 Feb 2024 21:19:20 +0100 Subject: [PATCH 1/8] update config --- metro.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metro.config.js b/metro.config.js index 2422d29aaacf..68ed72d52ba0 100644 --- a/metro.config.js +++ b/metro.config.js @@ -7,7 +7,7 @@ require('dotenv').config(); const defaultConfig = getDefaultConfig(__dirname); const isE2ETesting = process.env.E2E_TESTING === 'true'; -const e2eSourceExts = ['e2e.js', 'e2e.ts']; +const e2eSourceExts = ['e2e.js', 'e2e.ts', 'e2e.tsx']; /** * Metro configuration From 82a1aaadb2f29a4a2a6a6386cd6ad466fad651d7 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 09:23:21 +0100 Subject: [PATCH 2/8] add onViewableItemsChanged --- .../BaseInvertedFlatList/index.e2e.tsx | 50 +++++++++++++++++++ .../index.tsx} | 1 + 2 files changed, 51 insertions(+) create mode 100644 src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx rename src/components/InvertedFlatList/{BaseInvertedFlatList.tsx => BaseInvertedFlatList/index.tsx} (96%) diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx new file mode 100644 index 000000000000..0553312eae32 --- /dev/null +++ b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx @@ -0,0 +1,50 @@ +import type {ForwardedRef} from 'react'; +import React, {forwardRef, useMemo} from 'react'; +import type {FlatListProps, ScrollViewProps} from 'react-native'; +import FlatList from '@components/FlatList'; + +type BaseInvertedFlatListProps = FlatListProps & { + shouldEnableAutoScrollToTopThreshold?: boolean; +}; + +const AUTOSCROLL_TO_TOP_THRESHOLD = 128; + +let localViewableItems: unknown; +const getViewableItems = () => localViewableItems; + +function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: ForwardedRef) { + const {shouldEnableAutoScrollToTopThreshold, ...rest} = props; + + const handleViewableItemsChanged = ({viewableItems}: { viewableItems: unknown }) => { + localViewableItems = viewableItems; + }; + + const maintainVisibleContentPosition = useMemo(() => { + const config: ScrollViewProps['maintainVisibleContentPosition'] = { + // This needs to be 1 to avoid using loading views as anchors. + minIndexForVisible: 1, + }; + + if (shouldEnableAutoScrollToTopThreshold) { + config.autoscrollToTopThreshold = AUTOSCROLL_TO_TOP_THRESHOLD; + } + + return config; + }, [shouldEnableAutoScrollToTopThreshold]); + + return ( + + ); +} + +BaseInvertedFlatListE2e.displayName = 'BaseInvertedFlatListE2e'; + +export default forwardRef(BaseInvertedFlatListE2e); +export {getViewableItems}; diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList.tsx b/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx similarity index 96% rename from src/components/InvertedFlatList/BaseInvertedFlatList.tsx rename to src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx index d83e54f74d66..c92203afdc74 100644 --- a/src/components/InvertedFlatList/BaseInvertedFlatList.tsx +++ b/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx @@ -25,6 +25,7 @@ function BaseInvertedFlatList(props: BaseInvertedFlatListProps, ref: Forwa return config; }, [shouldEnableAutoScrollToTopThreshold]); + console.debug(`[E2E] BaseInverted.NOT`); return ( Date: Tue, 13 Feb 2024 09:28:41 +0100 Subject: [PATCH 3/8] linking test --- src/ROUTES.ts | 4 ++ src/libs/E2E/reactNativeLaunchingTest.ts | 1 + src/libs/E2E/tests/linkingTest.e2e.ts | 69 ++++++++++++++++++++++ src/pages/home/report/ReportActionsView.js | 4 +- tests/e2e/config.js | 11 ++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/libs/E2E/tests/linkingTest.e2e.ts diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 5a2ab8cfc7de..996136d12e6d 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -169,6 +169,10 @@ const ROUTES = { route: 'r/:reportID/avatar', getRoute: (reportID: string) => `r/${reportID}/avatar` as const, }, + REPORT_WITH_ID_AND_ACTION_ID: { + route: 'r/:reportID?/:reportActionID?', + getRoute: (reportID: string, reportActionID: string) => `r/${reportID}/${reportActionID}` as const, + }, EDIT_REQUEST: { route: 'r/:threadReportID/edit/:field', getRoute: (threadReportID: string, field: ValueOf) => `r/${threadReportID}/edit/${field}` as const, diff --git a/src/libs/E2E/reactNativeLaunchingTest.ts b/src/libs/E2E/reactNativeLaunchingTest.ts index 79276e7a5d75..931b41524696 100644 --- a/src/libs/E2E/reactNativeLaunchingTest.ts +++ b/src/libs/E2E/reactNativeLaunchingTest.ts @@ -38,6 +38,7 @@ const tests: Tests = { [E2EConfig.TEST_NAMES.OpenSearchPage]: require('./tests/openSearchPageTest.e2e').default, [E2EConfig.TEST_NAMES.ChatOpening]: require('./tests/chatOpeningTest.e2e').default, [E2EConfig.TEST_NAMES.ReportTyping]: require('./tests/reportTypingTest.e2e').default, + [E2EConfig.TEST_NAMES.Linking]: require('./tests/linkingTest.e2e').default, }; // Once we receive the TII measurement we know that the app is initialized and ready to be used: diff --git a/src/libs/E2E/tests/linkingTest.e2e.ts b/src/libs/E2E/tests/linkingTest.e2e.ts new file mode 100644 index 000000000000..ef370aaecf17 --- /dev/null +++ b/src/libs/E2E/tests/linkingTest.e2e.ts @@ -0,0 +1,69 @@ +import Config from 'react-native-config'; +import {getViewableItems} from '@components/InvertedFlatList/BaseInvertedFlatList/index.e2e'; +import Timing from '@libs/actions/Timing'; +import E2ELogin from '@libs/E2E/actions/e2eLogin'; +import waitForAppLoaded from '@libs/E2E/actions/waitForAppLoaded'; +import E2EClient from '@libs/E2E/client'; +import type {TestConfig} from '@libs/E2E/types'; +import getConfigValueOrThrow from '@libs/E2E/utils/getConfigValueOrThrow'; +import Navigation from '@libs/Navigation/Navigation'; +import Performance from '@libs/Performance'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; + +const test = (config: TestConfig) => { + console.debug('[E2E] Logging in for comment linking'); + + const reportID = getConfigValueOrThrow('reportID', config); + const linkedReportID = getConfigValueOrThrow('linkedReportID', config); + const linkedReportActionID = getConfigValueOrThrow('linkedReportActionID', config); + + E2ELogin().then((neededLogin) => { + if (neededLogin) { + return waitForAppLoaded().then(() => E2EClient.submitTestDone()); + } + + Performance.subscribeToMeasurements((entry) => { + if (entry.name === CONST.TIMING.SIDEBAR_LOADED) { + console.debug('[E2E] Sidebar loaded, navigating to a report…'); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID)); + return; + } + + if (entry.name === CONST.TIMING.REPORT_INITIAL_RENDER) { + console.debug('[E2E] Navigating to linked report action…'); + Timing.start(CONST.TIMING.SWITCH_REPORT); + Performance.markStart(CONST.TIMING.SWITCH_REPORT); + + Navigation.navigate(ROUTES.REPORT_WITH_ID_AND_ACTION_ID.getRoute(linkedReportID, linkedReportActionID)); + return; + } + + if (entry.name === CONST.TIMING.SWITCH_REPORT) { + setTimeout(() => { + const res = getViewableItems(); + console.debug('[E2E] Viewable items retrieved, verifying correct message…'); + + if (res[0]?.item?.reportActionID === linkedReportActionID) { + E2EClient.submitTestResults({ + branch: Config.E2E_BRANCH, + name: 'Comment linking', + duration: entry.duration, + }) + .then(() => { + console.debug('[E2E] Test completed successfully, exiting…'); + E2EClient.submitTestDone(); + }) + .catch((err) => { + console.debug('[E2E] Error while submitting test results:', err); + }); + } else { + console.debug('[E2E] Message verification failed'); + } + }, 3000); + } + }); + }); +}; + +export default test; diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 56f204ef6ffb..bcec51dba4e1 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -384,15 +384,15 @@ function ReportActionsView({reportActions: allReportActions, ...props}) { } didLayout.current = true; - Timing.end(CONST.TIMING.SWITCH_REPORT, hasCachedActions ? CONST.TIMING.WARM : CONST.TIMING.COLD); - // Capture the init measurement only once not per each chat switch as the value gets overwritten if (!ReportActionsView.initMeasured) { Performance.markEnd(CONST.TIMING.REPORT_INITIAL_RENDER); + Timing.end(CONST.TIMING.REPORT_INITIAL_RENDER); ReportActionsView.initMeasured = true; } else { Performance.markEnd(CONST.TIMING.SWITCH_REPORT); } + Timing.end(CONST.TIMING.SWITCH_REPORT, hasCachedActions ? CONST.TIMING.WARM : CONST.TIMING.COLD); }, [hasCachedActions], ); diff --git a/tests/e2e/config.js b/tests/e2e/config.js index a7447a29c954..79d4c7c4bdfa 100644 --- a/tests/e2e/config.js +++ b/tests/e2e/config.js @@ -6,6 +6,7 @@ const TEST_NAMES = { OpenSearchPage: 'Open search page TTI', ReportTyping: 'Report typing', ChatOpening: 'Chat opening', + Linking: 'Linking', }; /** @@ -85,5 +86,15 @@ module.exports = { // #announce Chat with many messages reportID: '5421294415618529', }, + [TEST_NAMES.Linking]: { + name: TEST_NAMES.Linking, + reportScreen: { + autoFocus: true, + }, + // Crowded Policy (Do Not Delete) Report, has a input bar available: + reportID: '8268282951170052', + linkedReportID: '5421294415618529', + linkedReportActionID: '2845024374735019929', + }, }, }; From 72c4d87d36a1fa7d80bee71a9a6eb4f193f04c82 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 19 Feb 2024 09:44:52 +0100 Subject: [PATCH 4/8] fix typings --- .../BaseInvertedFlatList/index.e2e.tsx | 26 ++++++++++++++----- src/libs/E2E/tests/linkingTest.e2e.ts | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx index 0553312eae32..e255554e9436 100644 --- a/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx +++ b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx @@ -9,15 +9,27 @@ type BaseInvertedFlatListProps = FlatListProps & { const AUTOSCROLL_TO_TOP_THRESHOLD = 128; -let localViewableItems: unknown; -const getViewableItems = () => localViewableItems; +type ViewableItem = { + item: T; + index: number; + key: string; + isViewable: boolean; +}; + +let localViewableItems: Array> | undefined; -function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: ForwardedRef) { +const getViewableItems = (): Array> | undefined => localViewableItems as Array> | undefined; + +function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: ForwardedRef>) { const {shouldEnableAutoScrollToTopThreshold, ...rest} = props; - const handleViewableItemsChanged = ({viewableItems}: { viewableItems: unknown }) => { - localViewableItems = viewableItems; - }; + const handleViewableItemsChanged = useMemo( + () => + ({viewableItems}: {viewableItems: Array>}) => { + localViewableItems = viewableItems; + }, + [], + ); const maintainVisibleContentPosition = useMemo(() => { const config: ScrollViewProps['maintainVisibleContentPosition'] = { @@ -33,7 +45,7 @@ function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: Fo }, [shouldEnableAutoScrollToTopThreshold]); return ( - // eslint-disable-next-line react/jsx-props-no-spreading {...rest} ref={ref} diff --git a/src/libs/E2E/tests/linkingTest.e2e.ts b/src/libs/E2E/tests/linkingTest.e2e.ts index ef370aaecf17..33365dc5b155 100644 --- a/src/libs/E2E/tests/linkingTest.e2e.ts +++ b/src/libs/E2E/tests/linkingTest.e2e.ts @@ -44,7 +44,7 @@ const test = (config: TestConfig) => { const res = getViewableItems(); console.debug('[E2E] Viewable items retrieved, verifying correct message…'); - if (res[0]?.item?.reportActionID === linkedReportActionID) { + if (!!res && res[0]?.item?.reportActionID === linkedReportActionID) { E2EClient.submitTestResults({ branch: Config.E2E_BRANCH, name: 'Comment linking', From 9f42bc15f0b72205f685d379bb5805e8f4044f02 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 25 Mar 2024 14:05:47 +0100 Subject: [PATCH 5/8] fix lint --- src/pages/home/report/ReportActionsView.tsx | 9 ++++----- tests/e2e/config.ts | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index f284b202c0cf..1d66e9d99c22 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -344,14 +344,13 @@ 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.REPORT_INITIAL_RENDER); - Timing.end(CONST.TIMING.REPORT_INITIAL_RENDER); - ReportActionsView.initMeasured = true; + Performance.markEnd(CONST.TIMING.REPORT_INITIAL_RENDER); + Timing.end(CONST.TIMING.REPORT_INITIAL_RENDER); + ReportActionsView.initMeasured = true; } else { - Performance.markEnd(CONST.TIMING.SWITCH_REPORT); + Performance.markEnd(CONST.TIMING.SWITCH_REPORT); } Timing.end(CONST.TIMING.SWITCH_REPORT, hasCachedActionOnFirstRender ? CONST.TIMING.WARM : CONST.TIMING.COLD); }, [hasCachedActionOnFirstRender]); diff --git a/tests/e2e/config.ts b/tests/e2e/config.ts index 5747cd0f1ed3..52d284b9dd86 100644 --- a/tests/e2e/config.ts +++ b/tests/e2e/config.ts @@ -91,7 +91,7 @@ export default { [TEST_NAMES.Linking]: { name: TEST_NAMES.Linking, reportScreen: { - autoFocus: true, + autoFocus: true, }, // Crowded Policy (Do Not Delete) Report, has a input bar available: reportID: '8268282951170052', From 1c29ef05e97560d4d5e77da71d809ab5cef073a2 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 25 Mar 2024 14:38:31 +0100 Subject: [PATCH 6/8] fix type --- .../BaseInvertedFlatList/index.e2e.tsx | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx index e255554e9436..5df39ec02c89 100644 --- a/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx +++ b/src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx @@ -1,31 +1,23 @@ -import type {ForwardedRef} from 'react'; import React, {forwardRef, useMemo} from 'react'; -import type {FlatListProps, ScrollViewProps} from 'react-native'; -import FlatList from '@components/FlatList'; +import type {FlatListProps, ScrollViewProps, ViewToken} from 'react-native'; +import {FlatList} from 'react-native'; +import type {ReportAction} from '@src/types/onyx'; -type BaseInvertedFlatListProps = FlatListProps & { +type BaseInvertedFlatListProps = FlatListProps & { shouldEnableAutoScrollToTopThreshold?: boolean; }; const AUTOSCROLL_TO_TOP_THRESHOLD = 128; -type ViewableItem = { - item: T; - index: number; - key: string; - isViewable: boolean; -}; - -let localViewableItems: Array> | undefined; - -const getViewableItems = (): Array> | undefined => localViewableItems as Array> | undefined; +let localViewableItems: ViewToken[]; +const getViewableItems = () => localViewableItems; -function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: ForwardedRef>) { +function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: React.ForwardedRef>) { const {shouldEnableAutoScrollToTopThreshold, ...rest} = props; const handleViewableItemsChanged = useMemo( () => - ({viewableItems}: {viewableItems: Array>}) => { + ({viewableItems}: {viewableItems: ViewToken[]}) => { localViewableItems = viewableItems; }, [], @@ -45,7 +37,7 @@ function BaseInvertedFlatListE2e(props: Base }, [shouldEnableAutoScrollToTopThreshold]); return ( - + // eslint-disable-next-line react/jsx-props-no-spreading {...rest} ref={ref} From 884e6e2651f7c71d137432173a8d3e66f254d55e Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 25 Mar 2024 14:42:32 +0100 Subject: [PATCH 7/8] use NativeConfig type --- src/libs/E2E/tests/linkingTest.e2e.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/E2E/tests/linkingTest.e2e.ts b/src/libs/E2E/tests/linkingTest.e2e.ts index 33365dc5b155..907be14934e0 100644 --- a/src/libs/E2E/tests/linkingTest.e2e.ts +++ b/src/libs/E2E/tests/linkingTest.e2e.ts @@ -1,17 +1,17 @@ +import type {NativeConfig} from 'react-native-config'; import Config from 'react-native-config'; import {getViewableItems} from '@components/InvertedFlatList/BaseInvertedFlatList/index.e2e'; import Timing from '@libs/actions/Timing'; import E2ELogin from '@libs/E2E/actions/e2eLogin'; import waitForAppLoaded from '@libs/E2E/actions/waitForAppLoaded'; import E2EClient from '@libs/E2E/client'; -import type {TestConfig} from '@libs/E2E/types'; import getConfigValueOrThrow from '@libs/E2E/utils/getConfigValueOrThrow'; import Navigation from '@libs/Navigation/Navigation'; import Performance from '@libs/Performance'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -const test = (config: TestConfig) => { +const test = (config: NativeConfig) => { console.debug('[E2E] Logging in for comment linking'); const reportID = getConfigValueOrThrow('reportID', config); @@ -40,6 +40,7 @@ const test = (config: TestConfig) => { } if (entry.name === CONST.TIMING.SWITCH_REPORT) { + console.debug('[E2E] Linking: 1'); setTimeout(() => { const res = getViewableItems(); console.debug('[E2E] Viewable items retrieved, verifying correct message…'); From 625a59f84275d368652b5e5eda4bec4ef242b467 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Mon, 25 Mar 2024 19:41:18 +0100 Subject: [PATCH 8/8] use one get route method --- src/ROUTES.ts | 6 +----- .../InvertedFlatList/BaseInvertedFlatList/index.tsx | 1 - src/libs/E2E/tests/linkingTest.e2e.ts | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 5b0c6e1b9106..6302e0ee4683 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -179,16 +179,12 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string) => `r/${reportID}` as const, + getRoute: (reportID: string, reportActionID?: string) => (reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const)), }, REPORT_AVATAR: { route: 'r/:reportID/avatar', getRoute: (reportID: string) => `r/${reportID}/avatar` as const, }, - REPORT_WITH_ID_AND_ACTION_ID: { - route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string, reportActionID: string) => `r/${reportID}/${reportActionID}` as const, - }, EDIT_REQUEST: { route: 'r/:threadReportID/edit/:field/:tagIndex?', getRoute: (threadReportID: string, field: ValueOf, tagIndex?: number) => diff --git a/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx b/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx index a5a0b55ebfb3..9ee465369be1 100644 --- a/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx +++ b/src/components/InvertedFlatList/BaseInvertedFlatList/index.tsx @@ -25,7 +25,6 @@ function BaseInvertedFlatList(props: BaseInvertedFlatListProps, ref: Forwa return config; }, [shouldEnableAutoScrollToTopThreshold]); - console.debug(`[E2E] BaseInverted.NOT`); return ( { Timing.start(CONST.TIMING.SWITCH_REPORT); Performance.markStart(CONST.TIMING.SWITCH_REPORT); - Navigation.navigate(ROUTES.REPORT_WITH_ID_AND_ACTION_ID.getRoute(linkedReportID, linkedReportActionID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(linkedReportID, linkedReportActionID)); return; }