-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathReportScreen.perf-test.js
219 lines (186 loc) · 7.62 KB
/
ReportScreen.perf-test.js
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import {fireEvent, screen} from '@testing-library/react-native';
import React from 'react';
import Onyx from 'react-native-onyx';
import {measurePerformance} from 'reassure';
import ComposeProviders from '../../src/components/ComposeProviders';
import DragAndDropProvider from '../../src/components/DragAndDrop/Provider';
import {LocaleContextProvider} from '../../src/components/LocaleContextProvider';
import OnyxProvider from '../../src/components/OnyxProvider';
import {CurrentReportIDContextProvider} from '../../src/components/withCurrentReportID';
import {KeyboardStateProvider} from '../../src/components/withKeyboardState';
import {WindowDimensionsProvider} from '../../src/components/withWindowDimensions';
import CONST from '../../src/CONST';
import * as Localize from '../../src/libs/Localize';
import ONYXKEYS from '../../src/ONYXKEYS';
import {ReportAttachmentsProvider} from '../../src/pages/home/report/ReportAttachmentsContext';
import ReportScreen from '../../src/pages/home/ReportScreen';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import PusherHelper from '../utils/PusherHelper';
import * as ReportTestUtils from '../utils/ReportTestUtils';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
jest.mock('react-native-reanimated', () => ({
...jest.requireActual('react-native-reanimated/mock'),
useSharedValue: jest.fn,
useAnimatedStyle: jest.fn,
useAnimatedRef: jest.fn,
}));
jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
isFocused={false}
/>
);
}
WithNavigationFocus.displayName = 'WithNavigationFocus';
return WithNavigationFocus;
});
jest.mock('../../src/hooks/useEnvironment', () =>
jest.fn(() => ({
environment: 'development',
environmentURL: 'https://new.expensify.com',
isProduction: false,
isDevelopment: true,
})),
);
jest.mock('../../src/libs/Permissions', () => ({
canUseLinkPreviews: jest.fn(() => true),
}));
jest.mock('../../src/libs/Navigation/Navigation');
const mockedNavigate = jest.fn();
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
...actualNav,
useFocusEffect: jest.fn(),
useIsFocused: () => ({
navigate: mockedNavigate,
}),
useRoute: () => jest.fn(),
useNavigation: () => ({
navigate: jest.fn(),
addListener: () => jest.fn(),
}),
createNavigationContainerRef: jest.fn(),
};
});
// mock PortalStateContext
jest.mock('@gorhom/portal');
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
registerStorageEventListener: () => {},
}),
);
// Initialize the network key for OfflineWithFeedback
beforeEach(() => {
global.fetch = TestHelper.getGlobalFetchMock();
wrapOnyxWithWaitForBatchedUpdates(Onyx);
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
});
// Clear out Onyx after each test so that each test starts with a clean state
afterEach(() => {
Onyx.clear();
PusherHelper.teardown();
});
function ReportScreenWrapper(args) {
return (
<ComposeProviders
components={[
OnyxProvider,
CurrentReportIDContextProvider,
KeyboardStateProvider,
WindowDimensionsProvider,
LocaleContextProvider,
DragAndDropProvider,
ReportAttachmentsProvider,
]}
>
<ReportScreen
// eslint-disable-next-line react/jsx-props-no-spreading
{...args}
/>
</ComposeProviders>
);
}
const runs = CONST.PERFORMANCE_TESTS.RUNS;
test.skip('should render ReportScreen with composer interactions', () => {
const scenario = async () => {
// Query for the report list
await screen.findByTestId('report-actions-list');
// Query for the composer
const composer = await screen.findByTestId('composer');
// Type in the composer
fireEvent.changeText(composer, 'Test message');
const hintSendButtonText = Localize.translateLocal('common.send');
// Query for the send button
const sendButton = await screen.findByLabelText(hintSendButtonText);
// Click on the send button
fireEvent.press(sendButton);
const hintHeaderText = Localize.translateLocal('common.back');
// Query for the header
await screen.findByLabelText(hintHeaderText);
};
const policy = {
policyID: 1,
name: 'Testing Policy',
};
const report = LHNTestUtils.getFakeReport();
const reportActions = ReportTestUtils.getMockedReportsMap(1000);
const mockRoute = {params: {reportID: '1'}};
return waitForBatchedUpdates()
.then(() =>
Onyx.multiSet({
[ONYXKEYS.IS_SIDEBAR_LOADED]: true,
[`${ONYXKEYS.COLLECTION.REPORT}${mockRoute.params.reportID}`]: report,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${mockRoute.params.reportID}`]: reportActions,
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS],
[`${ONYXKEYS.COLLECTION.POLICY}${policy.policyID}`]: policy,
[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${mockRoute.params.reportID}`]: {
isLoadingReportActions: false,
},
}),
)
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario, runs}));
});
test.skip('should press of the report item', () => {
const scenario = async () => {
// Query for the report list
await screen.findByTestId('report-actions-list');
// Query for the composer
await screen.findByTestId('composer');
const hintReportPreviewText = Localize.translateLocal('iou.viewDetails');
// Query for report preview buttons
const reportPreviewButtons = await screen.findAllByLabelText(hintReportPreviewText);
// click on the report preview button
fireEvent.press(reportPreviewButtons[0]);
};
const policy = {
policyID: 123,
name: 'Testing Policy',
};
const report = LHNTestUtils.getFakeReport();
const reportActions = ReportTestUtils.getMockedReportsMap(1000);
const mockRoute = {params: {reportID: '2'}};
return waitForBatchedUpdates()
.then(() =>
Onyx.multiSet({
[ONYXKEYS.IS_SIDEBAR_LOADED]: true,
[`${ONYXKEYS.COLLECTION.REPORT}${mockRoute.params.reportID}`]: report,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${mockRoute.params.reportID}`]: reportActions,
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS],
[`${ONYXKEYS.COLLECTION.POLICY}${policy.policyID}`]: policy,
[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${mockRoute.params.reportID}`]: {
isLoadingReportActions: false,
},
}),
)
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario, runs}));
});