-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36791 from margelo/feat/23229-linking-e2e
Comment linking e2e
- Loading branch information
Showing
8 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/components/InvertedFlatList/BaseInvertedFlatList/index.e2e.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, {forwardRef, useMemo} from 'react'; | ||
import type {FlatListProps, ScrollViewProps, ViewToken} from 'react-native'; | ||
import {FlatList} from 'react-native'; | ||
import type {ReportAction} from '@src/types/onyx'; | ||
|
||
type BaseInvertedFlatListProps = FlatListProps<ReportAction> & { | ||
shouldEnableAutoScrollToTopThreshold?: boolean; | ||
}; | ||
|
||
const AUTOSCROLL_TO_TOP_THRESHOLD = 128; | ||
|
||
let localViewableItems: ViewToken[]; | ||
const getViewableItems = () => localViewableItems; | ||
|
||
function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: React.ForwardedRef<FlatList<ReportAction>>) { | ||
const {shouldEnableAutoScrollToTopThreshold, ...rest} = props; | ||
|
||
const handleViewableItemsChanged = useMemo( | ||
() => | ||
({viewableItems}: {viewableItems: ViewToken[]}) => { | ||
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 ( | ||
<FlatList<ReportAction> | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
ref={ref} | ||
maintainVisibleContentPosition={maintainVisibleContentPosition} | ||
inverted | ||
onViewableItemsChanged={handleViewableItemsChanged} | ||
/> | ||
); | ||
} | ||
|
||
BaseInvertedFlatListE2e.displayName = 'BaseInvertedFlatListE2e'; | ||
|
||
export default forwardRef(BaseInvertedFlatListE2e); | ||
export {getViewableItems}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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 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: NativeConfig) => { | ||
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.getRoute(linkedReportID, linkedReportActionID)); | ||
return; | ||
} | ||
|
||
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…'); | ||
|
||
if (!!res && 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters