Skip to content

Commit 2fb9e46

Browse files
committed
Merge branch 'perf/lhn-baselines' into perf/lhn-sort-cache
2 parents fa24bf0 + 2a42cf5 commit 2fb9e46

3 files changed

Lines changed: 175 additions & 179 deletions

File tree

tests/perf-test/SidebarLinks.perf-test.tsx

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import type * as Navigation from '@react-navigation/native';
22
import {fireEvent, screen, waitFor} from '@testing-library/react-native';
3-
import type {OnyxCollection} from 'react-native-onyx';
43
import Onyx from 'react-native-onyx';
54
import {measureRenders} from 'reassure';
65
import CONST from '@src/CONST';
76
import ONYXKEYS from '@src/ONYXKEYS';
87
import type {OnyxValues} from '@src/ONYXKEYS';
9-
import type {PersonalDetails, Report, ReportActions, ReportMetadata, ReportNameValuePairs} from '@src/types/onyx';
10-
import type Policy from '@src/types/onyx/Policy';
11-
import createPersonalDetails from '../utils/collections/personalDetails';
12-
import createRandomPolicy from '../utils/collections/policies';
8+
import type {ReportActions} from '@src/types/onyx';
139
import createRandomReportAction from '../utils/collections/reportActions';
14-
import {createRandomReport} from '../utils/collections/reports';
10+
import {createSidebarReportsWithActions as createReportsWithActions} from '../utils/collections/sidebarReports';
1511
import * as LHNTestUtils from '../utils/LHNTestUtils';
1612
import * as TestHelper from '../utils/TestHelper';
1713
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
@@ -75,70 +71,6 @@ const getMockedReportsMap = (length = 100) => {
7571
const mockedResponseMap = getMockedReportsMap(500);
7672

7773
const REPORTS_COUNT = 150;
78-
const ACTIONS_PER_REPORT = 50;
79-
80-
const createMockReportActions = (reportID: string, count: number): ReportActions => {
81-
const actions: ReportActions = {};
82-
for (let i = 0; i < count; i++) {
83-
actions[`${reportID}_${i}`] = createRandomReportAction(i);
84-
}
85-
return actions;
86-
};
87-
88-
const createReportsWithActions = (count: number) => {
89-
const reports: OnyxCollection<Report> = {};
90-
const reportActions: OnyxCollection<ReportActions> = {};
91-
const reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = {};
92-
const policies: OnyxCollection<Policy> = {};
93-
const personalDetails: OnyxCollection<PersonalDetails> = {};
94-
const reportMetadata: OnyxCollection<ReportMetadata> = {};
95-
96-
const basePolicy = createRandomPolicy(1);
97-
policies[`${ONYXKEYS.COLLECTION.POLICY}${basePolicy.id}`] = basePolicy;
98-
99-
for (let i = 1; i <= count; i++) {
100-
const reportID = String(i);
101-
const report = createRandomReport(i, undefined);
102-
103-
const isArchived = i % 10 === 0;
104-
const reportTypeMod = i % 4;
105-
let reportType: string;
106-
if (reportTypeMod === 0) {
107-
reportType = CONST.REPORT.TYPE.IOU;
108-
} else if (reportTypeMod === 1) {
109-
reportType = CONST.REPORT.TYPE.EXPENSE;
110-
} else {
111-
reportType = CONST.REPORT.TYPE.CHAT;
112-
}
113-
114-
reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = {
115-
...report,
116-
type: reportType,
117-
};
118-
reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = createMockReportActions(reportID, ACTIONS_PER_REPORT);
119-
reportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`] = {
120-
private_isArchived: isArchived ? 'true' : 'false',
121-
};
122-
123-
const lastActorAccountID = report.lastActorAccountID ?? i;
124-
personalDetails[String(lastActorAccountID)] = createPersonalDetails(lastActorAccountID);
125-
126-
if (i % 5 === 0) {
127-
reportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`] = {
128-
lastVisitTime: new Date().toISOString(),
129-
};
130-
}
131-
}
132-
133-
return {
134-
reports,
135-
reportActions,
136-
reportNameValuePairs,
137-
policies,
138-
personalDetails,
139-
reportMetadata,
140-
};
141-
};
14274

14375
describe('SidebarLinks', () => {
14476
beforeAll(() => {
@@ -248,7 +180,8 @@ describe('SidebarLinks', () => {
248180
const scenario = async () => {
249181
await screen.findByTestId('lhn-options-list');
250182
const firstReportID = '1';
251-
const firstReportActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`];
183+
const actionsCollection = reportActions ?? {};
184+
const firstReportActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`];
252185
if (firstReportActions) {
253186
const newAction = createRandomReportAction(999);
254187
const updatedActions = {
@@ -283,9 +216,10 @@ describe('SidebarLinks', () => {
283216
const scenario = async () => {
284217
await screen.findByTestId('lhn-options-list');
285218
const updates: Record<string, ReportActions> = {};
219+
const actionsCollection = reportActions ?? {};
286220
for (let i = 1; i <= 10; i++) {
287221
const reportID = String(i);
288-
const existingActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
222+
const existingActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
289223
if (existingActions) {
290224
const newAction = createRandomReportAction(1000 + i);
291225
updates[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = {
@@ -350,7 +284,8 @@ describe('SidebarLinks', () => {
350284
const scenario = async () => {
351285
await screen.findByTestId('lhn-options-list');
352286
const firstReportID = '1';
353-
const currentArchivedStatus = reportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`]?.private_isArchived;
287+
const nameValuePairsCollection = reportNameValuePairs ?? {};
288+
const currentArchivedStatus = nameValuePairsCollection[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`]?.private_isArchived;
354289
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`, {
355290
private_isArchived: currentArchivedStatus === 'true' ? 'false' : 'true',
356291
});

0 commit comments

Comments
 (0)