forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportActionsList.perf-test.tsx
166 lines (142 loc) · 6.28 KB
/
ReportActionsList.perf-test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import {fireEvent, screen} from '@testing-library/react-native';
import type {ComponentType} from 'react';
import Onyx from 'react-native-onyx';
import {measurePerformance} from 'reassure';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import type Navigation from '@libs/Navigation/Navigation';
import ComposeProviders from '@src/components/ComposeProviders';
import {LocaleContextProvider} from '@src/components/LocaleContextProvider';
import OnyxProvider from '@src/components/OnyxProvider';
import * as Localize from '@src/libs/Localize';
import ONYXKEYS from '@src/ONYXKEYS';
import ReportActionsList from '@src/pages/home/report/ReportActionsList';
import {ReportAttachmentsProvider} from '@src/pages/home/report/ReportAttachmentsContext';
import {ActionListContext, ReactionListContext} from '@src/pages/home/ReportScreenContext';
import variables from '@src/styles/variables';
import type {PersonalDetailsList} from '@src/types/onyx';
import createRandomReportAction from '../utils/collections/reportActions';
import * as LHNTestUtilsModule from '../utils/LHNTestUtils';
import * as ReportTestUtils from '../utils/ReportTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
type LazyLoadLHNTestUtils = {
fakePersonalDetails: PersonalDetailsList;
};
const mockedNavigate = jest.fn();
jest.mock('@components/withCurrentUserPersonalDetails', () => {
// Lazy loading of LHNTestUtils
const lazyLoadLHNTestUtils = () => require<LazyLoadLHNTestUtils>('../utils/LHNTestUtils');
return <TProps extends WithCurrentUserPersonalDetailsProps>(Component: ComponentType<TProps>) => {
function WrappedComponent(props: Omit<TProps, keyof WithCurrentUserPersonalDetailsProps>) {
const currentUserAccountID = 5;
const LHNTestUtils = lazyLoadLHNTestUtils(); // Load LHNTestUtils here
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...(props as TProps)}
currentUserPersonalDetails={LHNTestUtils.fakePersonalDetails[currentUserAccountID]}
/>
);
}
WrappedComponent.displayName = 'WrappedComponent';
return WrappedComponent;
};
});
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native');
return {
...actualNav,
useRoute: () => mockedNavigate,
useIsFocused: () => true,
};
});
jest.mock('@src/components/ConfirmedRoute.tsx');
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);
const mockOnLayout = jest.fn();
const mockOnScroll = jest.fn();
const mockLoadChats = jest.fn();
const mockRef = {current: null, flatListRef: null, scrollPosition: null, setScrollPosition: () => {}};
beforeEach(() => {
// Initialize the network key for OfflineWithFeedback
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
wrapOnyxWithWaitForBatchedUpdates(Onyx);
Onyx.clear().then(waitForBatchedUpdates);
});
function ReportActionsListWrapper() {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, ReportAttachmentsProvider]}>
<ReactionListContext.Provider value={mockRef}>
<ActionListContext.Provider value={mockRef}>
<ReportActionsList
parentReportAction={createRandomReportAction(1)}
parentReportActionForTransactionThread={undefined}
sortedReportActions={ReportTestUtils.getMockedSortedReportActions(500)}
report={LHNTestUtilsModule.getFakeReport()}
onLayout={mockOnLayout}
onScroll={mockOnScroll}
onContentSizeChange={() => {}}
listID={1}
loadOlderChats={mockLoadChats}
loadNewerChats={mockLoadChats}
transactionThreadReport={LHNTestUtilsModule.getFakeReport()}
reportActions={ReportTestUtils.getMockedSortedReportActions(500)}
/>
</ActionListContext.Provider>
</ReactionListContext.Provider>
</ComposeProviders>
);
}
test('[ReportActionsList] should render ReportActionsList with 500 reportActions stored', async () => {
const scenario = async () => {
await screen.findByTestId('report-actions-list');
};
await waitForBatchedUpdates();
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtilsModule.fakePersonalDetails,
});
await measurePerformance(<ReportActionsListWrapper />, {scenario});
});
test('[ReportActionsList] should render list items', async () => {
const scenario = async () => {
const hintText = Localize.translateLocal('accessibilityHints.chatMessage');
await screen.findAllByLabelText(hintText);
};
await waitForBatchedUpdates();
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtilsModule.fakePersonalDetails,
});
await measurePerformance(<ReportActionsListWrapper />, {scenario});
});
test('[ReportActionsList] should scroll through list of items', async () => {
const eventData = {
nativeEvent: {
contentOffset: {
y: variables.optionRowHeight * 5,
},
contentSize: {
// Dimensions of the scrollable content
height: variables.optionRowHeight * 10,
width: 100,
},
layoutMeasurement: {
// Dimensions of the device
height: variables.optionRowHeight * 5,
width: 100,
},
},
};
const scenario = async () => {
const reportActionsList = await screen.findByTestId('report-actions-list');
fireEvent.scroll(reportActionsList, eventData);
};
await waitForBatchedUpdates();
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtilsModule.fakePersonalDetails,
});
await measurePerformance(<ReportActionsListWrapper />, {scenario});
});