forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportUtils.perf-test.ts
212 lines (172 loc) · 8.66 KB
/
ReportUtils.perf-test.ts
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
import Onyx from 'react-native-onyx';
import {measureFunction} from 'reassure';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, Policy, Report, ReportAction} from '@src/types/onyx';
import createCollection from '../utils/collections/createCollection';
import createPersonalDetails from '../utils/collections/personalDetails';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';
import createRandomTransaction from '../utils/collections/transaction';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
const getMockedReports = (length = 500) =>
createCollection<Report>(
(item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`,
(index) => createRandomReport(index),
length,
);
const getMockedPolicies = (length = 500) =>
createCollection<Policy>(
(item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`,
(index) => createRandomPolicy(index),
length,
);
const personalDetails = createCollection<PersonalDetails>(
(item) => item.accountID,
(index) => createPersonalDetails(index),
1000,
);
const mockedReportsMap = getMockedReports(1000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>;
const mockedPoliciesMap = getMockedPolicies(1000) as Record<`${typeof ONYXKEYS.COLLECTION.POLICY}`, Policy>;
const participantAccountIDs = Array.from({length: 1000}, (v, i) => i + 1);
describe('ReportUtils', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});
beforeEach(async () => {
await Onyx.multiSet({
...mockedPoliciesMap,
...mockedReportsMap,
});
});
afterAll(() => {
Onyx.clear();
});
test('[ReportUtils] findLastAccessedReport on 2k reports and policies', async () => {
const ignoreDomainRooms = true;
const reports = getMockedReports(2000);
const policies = getMockedPolicies(2000);
const openOnAdminRoom = true;
await Onyx.multiSet({
[ONYXKEYS.COLLECTION.REPORT]: reports,
[ONYXKEYS.COLLECTION.POLICY]: policies,
});
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.findLastAccessedReport(ignoreDomainRooms, openOnAdminRoom));
});
test('[ReportUtils] canDeleteReportAction on 1k reports and policies', async () => {
const reportID = '1';
const reportAction = {...createRandomReportAction(1), actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT} as unknown as ReportAction;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.canDeleteReportAction(reportAction, reportID));
});
test('[ReportUtils] getReportRecipientAccountID on 1k participants', async () => {
const report = {...createRandomReport(1), participantAccountIDs};
const currentLoginAccountID = 1;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportRecipientAccountIDs(report, currentLoginAccountID));
});
test('[ReportUtils] getIconsForParticipants on 1k participants', async () => {
const participants = Array.from({length: 1000}, (v, i) => i + 1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIconsForParticipants(participants, personalDetails));
});
test('[ReportUtils] getIcons on 1k participants', async () => {
const report = {...createRandomReport(1), parentReportID: '1', parentReportActionID: '1', type: CONST.REPORT.TYPE.CHAT};
const policy = createRandomPolicy(1);
const defaultIcon = null;
const defaultName = '';
const defaultIconId = -1;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIcons(report, personalDetails, defaultIcon, defaultName, defaultIconId, policy));
});
test('[ReportUtils] getDisplayNamesWithTooltips 1k participants', async () => {
const isMultipleParticipantReport = true;
const shouldFallbackToHidden = true;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getDisplayNamesWithTooltips(personalDetails, isMultipleParticipantReport, shouldFallbackToHidden));
});
test('[ReportUtils] getReportPreviewMessage on 1k policies', async () => {
const reportAction = createRandomReportAction(1);
const report = createRandomReport(1);
const policy = createRandomPolicy(1);
const shouldConsiderReceiptBeingScanned = true;
const isPreviewMessageForParentChatReport = true;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportPreviewMessage(report, reportAction, shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy));
});
test('[ReportUtils] getReportName on 1k participants', async () => {
const report = {...createRandomReport(1), chatType: undefined, participantAccountIDs};
const policy = createRandomPolicy(1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportName(report, policy));
});
test('[ReportUtils] canShowReportRecipientLocalTime on 1k participants', async () => {
const report = {...createRandomReport(1), participantAccountIDs};
const accountID = 1;
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.canShowReportRecipientLocalTime(personalDetails, report, accountID));
});
test('[ReportUtils] shouldReportBeInOptionList on 1k participant', async () => {
const report = {...createRandomReport(1), participantAccountIDs, type: CONST.REPORT.TYPE.CHAT};
const currentReportId = '2';
const isInFocusMode = true;
const betas = [CONST.BETAS.DEFAULT_ROOMS];
const policies = getMockedPolicies();
await waitForBatchedUpdates();
await measureFunction(() =>
ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies, doesReportHaveViolations: false, excludeEmptyChats: false}),
);
});
test('[ReportUtils] getWorkspaceIcon on 1k policies', async () => {
const report = createRandomReport(1);
const policy = createRandomPolicy(1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getWorkspaceIcon(report, policy));
});
test('[ReportUtils] getMoneyRequestOptions on 1k participants', async () => {
const report = {...createRandomReport(1), type: CONST.REPORT.TYPE.CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true};
const policy = createRandomPolicy(1);
const reportParticipants = Array.from({length: 1000}, (v, i) => i + 1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipants));
});
test('[ReportUtils] getWorkspaceAvatar on 1k policies', async () => {
const report = createRandomReport(1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getWorkspaceAvatar(report));
});
test('[ReportUtils] getWorkspaceChat on 1k policies', async () => {
const policyID = '1';
const accountsID = Array.from({length: 20}, (v, i) => i + 1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getWorkspaceChats(policyID, accountsID));
});
test('[ReportUtils] getTransactionDetails on 1k reports', async () => {
const transaction = createRandomTransaction(1);
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getTransactionDetails(transaction, 'yyyy-MM-dd'));
});
test('[ReportUtils] getIOUReportActionDisplayMessage on 1k policies', async () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
originalMessage: {
IOUReportID: '1',
IOUTransactionID: '1',
amount: 100,
participantAccountID: 1,
currency: CONST.CURRENCY.USD,
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
paymentType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
},
};
await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIOUReportActionDisplayMessage(reportAction));
});
});