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

fix: comment linking e2e test #43986

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {forwardRef, useMemo} from 'react';
import type {FlatListProps, ScrollViewProps, ViewToken} from 'react-native';
import {FlatList} from 'react-native';
import {DeviceEventEmitter, FlatList} from 'react-native';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeviceEventEmitter is deprecated, but we can use NativeEventEmitter instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, currently we don't use NativeEventEmitter anywhere in the codebase, so I think now it's better to keep DeviceEventEmitter and later (when needed) we can re-work all code pieces at once.

import type {ReportAction} from '@src/types/onyx';

type BaseInvertedFlatListProps = FlatListProps<ReportAction> & {
Expand All @@ -9,16 +9,13 @@ type BaseInvertedFlatListProps = FlatListProps<ReportAction> & {

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;
DeviceEventEmitter.emit('onViewableItemsChanged', viewableItems);
},
[],
);
Expand Down Expand Up @@ -51,4 +48,3 @@ function BaseInvertedFlatListE2e(props: BaseInvertedFlatListProps, ref: React.Fo
BaseInvertedFlatListE2e.displayName = 'BaseInvertedFlatListE2e';

export default forwardRef(BaseInvertedFlatListE2e);
export {getViewableItems};
53 changes: 32 additions & 21 deletions src/libs/E2E/tests/linkingTest.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {DeviceEventEmitter} from 'react-native';
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 getPromiseWithResolve from '@libs/E2E/utils/getPromiseWithResolve';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import CONST from '@src/CONST';
Expand All @@ -23,6 +24,29 @@ const test = (config: NativeConfig) => {
return waitForAppLoaded().then(() => E2EClient.submitTestDone());
}

const [appearMessagePromise, appearMessageResolve] = getPromiseWithResolve();
const [switchReportPromise, switchReportResolve] = getPromiseWithResolve();

Promise.all([appearMessagePromise, switchReportPromise])
.then(() => {
console.debug('[E2E] Test completed successfully, exiting…');
E2EClient.submitTestDone();
})
.catch((err) => {
console.debug('[E2E] Error while submitting test results:', err);
});

const subscription = DeviceEventEmitter.addListener('onViewableItemsChanged', (res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it fire when we open the first chat? It looks like it would, so we can skip it or change the log '[E2E] Message verification failed,' as it may look like an error, but it would be expected behavior since we only want to check it for entry.name === SWITCH_REPORT

console.debug('[E2E] Viewable items retrieved, verifying correct message…', res);

if (!!res && res[0]?.item?.reportActionID === linkedReportActionID) {
appearMessageResolve();
subscription.remove();
} else {
console.debug(`[E2E] Provided message id '${res?.[0]?.item?.reportActionID}' doesn't match to an expected '${linkedReportActionID}'. Waiting for a next one…`);
}
});

Performance.subscribeToMeasurements((entry) => {
if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
console.debug('[E2E] Sidebar loaded, navigating to a report…');
Expand All @@ -41,27 +65,14 @@ const test = (config: NativeConfig) => {

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);
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
name: 'Comment linking',
duration: entry.duration,
});

switchReportResolve();
}
});
});
Expand Down
Loading