Skip to content

Commit 091f69f

Browse files
committed
Merge branch 'perf/lhn-baselines' into perf/lhn-sort-cache
2 parents 7f7c8d1 + a8d5ff5 commit 091f69f

2 files changed

Lines changed: 3 additions & 282 deletions

File tree

Lines changed: 1 addition & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import type * as Navigation from '@react-navigation/native';
21
import {fireEvent, screen, waitFor} from '@testing-library/react-native';
32
import Onyx from 'react-native-onyx';
43
import {measureRenders} from 'reassure';
54
import CONST from '@src/CONST';
65
import ONYXKEYS from '@src/ONYXKEYS';
7-
import type {OnyxValues} from '@src/ONYXKEYS';
8-
import type {ReportActions} from '@src/types/onyx';
9-
import createRandomReportAction from '../utils/collections/reportActions';
10-
import {createSidebarReportsWithActions as createReportsWithActions} from '../utils/collections/sidebarReports';
116
import * as LHNTestUtils from '../utils/LHNTestUtils';
127
import * as TestHelper from '../utils/TestHelper';
138
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
14-
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
159
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
1610

1711
jest.mock('@libs/Permissions');
@@ -35,22 +29,8 @@ jest.mock('../../src/libs/Navigation/navigationRef', () => ({
3529
isReady: () => true,
3630
}));
3731
jest.mock('@components/Icon/Expensicons');
38-
jest.mock('@react-navigation/native', () => {
39-
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native');
4032

41-
return {
42-
...actualNav,
43-
useNavigationState: () => true,
44-
useRoute: jest.fn(),
45-
useFocusEffect: jest.fn(),
46-
useIsFocused: () => true,
47-
useNavigation: () => ({
48-
navigate: jest.fn(),
49-
addListener: jest.fn(),
50-
}),
51-
createNavigationContainerRef: jest.fn(),
52-
};
53-
});
33+
jest.mock('@react-navigation/native');
5434
jest.mock('@src/hooks/useLHNEstimatedListSize/index.native.ts');
5535

5636
const getMockedReportsMap = (length = 100) => {
@@ -70,8 +50,6 @@ const getMockedReportsMap = (length = 100) => {
7050

7151
const mockedResponseMap = getMockedReportsMap(500);
7252

73-
const REPORTS_COUNT = 150;
74-
7553
describe('SidebarLinks', () => {
7654
beforeAll(() => {
7755
Onyx.init({
@@ -135,187 +113,4 @@ describe('SidebarLinks', () => {
135113

136114
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
137115
});
138-
139-
test('[SidebarLinks LHN] initial render with 150 reports and actions', async () => {
140-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(REPORTS_COUNT);
141-
142-
const scenario = async () => {
143-
await screen.findByTestId('lhn-options-list');
144-
};
145-
146-
await Onyx.multiSet({
147-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
148-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
149-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
150-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
151-
...reports,
152-
...reportActions,
153-
...reportNameValuePairs,
154-
...policies,
155-
...reportMetadata,
156-
} as Partial<OnyxValues>);
157-
158-
await waitForBatchedUpdatesWithAct();
159-
160-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
161-
});
162-
163-
test('[SidebarLinks LHN] re-render when single report action changes', async () => {
164-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(REPORTS_COUNT);
165-
166-
await Onyx.multiSet({
167-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
168-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
169-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
170-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
171-
...reports,
172-
...reportActions,
173-
...reportNameValuePairs,
174-
...policies,
175-
...reportMetadata,
176-
} as Partial<OnyxValues>);
177-
178-
await waitForBatchedUpdates();
179-
180-
const scenario = async () => {
181-
await screen.findByTestId('lhn-options-list');
182-
const firstReportID = '1';
183-
const actionsCollection = reportActions ?? {};
184-
const firstReportActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`];
185-
if (firstReportActions) {
186-
const newAction = createRandomReportAction(999);
187-
const updatedActions = {
188-
...firstReportActions,
189-
[`${firstReportID}_999`]: newAction,
190-
};
191-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`, updatedActions);
192-
await waitForBatchedUpdatesWithAct();
193-
}
194-
};
195-
196-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
197-
});
198-
199-
test('[SidebarLinks LHN] re-render when multiple reports change', async () => {
200-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(REPORTS_COUNT);
201-
202-
await Onyx.multiSet({
203-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
204-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
205-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
206-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
207-
...reports,
208-
...reportActions,
209-
...reportNameValuePairs,
210-
...policies,
211-
...reportMetadata,
212-
} as Partial<OnyxValues>);
213-
214-
await waitForBatchedUpdates();
215-
216-
const scenario = async () => {
217-
await screen.findByTestId('lhn-options-list');
218-
const updates: Record<string, ReportActions> = {};
219-
const actionsCollection = reportActions ?? {};
220-
for (let i = 1; i <= 10; i++) {
221-
const reportID = String(i);
222-
const existingActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
223-
if (existingActions) {
224-
const newAction = createRandomReportAction(1000 + i);
225-
updates[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = {
226-
...existingActions,
227-
[`${reportID}_new`]: newAction,
228-
};
229-
}
230-
}
231-
await Onyx.multiSet(updates as Partial<OnyxValues>);
232-
await waitForBatchedUpdatesWithAct();
233-
};
234-
235-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
236-
});
237-
238-
test('[SidebarLinks LHN] re-render when report metadata changes', async () => {
239-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(REPORTS_COUNT);
240-
241-
await Onyx.multiSet({
242-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
243-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
244-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
245-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
246-
...reports,
247-
...reportActions,
248-
...reportNameValuePairs,
249-
...policies,
250-
...reportMetadata,
251-
} as Partial<OnyxValues>);
252-
253-
await waitForBatchedUpdates();
254-
255-
const scenario = async () => {
256-
await screen.findByTestId('lhn-options-list');
257-
const firstReportID = '1';
258-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${firstReportID}`, {
259-
lastVisitTime: new Date().toISOString(),
260-
});
261-
await waitForBatchedUpdatesWithAct();
262-
};
263-
264-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
265-
});
266-
267-
test('[SidebarLinks LHN] re-render when report archived status changes', async () => {
268-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(REPORTS_COUNT);
269-
270-
await Onyx.multiSet({
271-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
272-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
273-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
274-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
275-
...reports,
276-
...reportActions,
277-
...reportNameValuePairs,
278-
...policies,
279-
...reportMetadata,
280-
} as Partial<OnyxValues>);
281-
282-
await waitForBatchedUpdates();
283-
284-
const scenario = async () => {
285-
await screen.findByTestId('lhn-options-list');
286-
const firstReportID = '1';
287-
const nameValuePairsCollection = reportNameValuePairs ?? {};
288-
const currentArchivedStatus = nameValuePairsCollection[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`]?.private_isArchived;
289-
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`, {
290-
private_isArchived: currentArchivedStatus === 'true' ? 'false' : 'true',
291-
});
292-
await waitForBatchedUpdatesWithAct();
293-
};
294-
295-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
296-
});
297-
298-
test('[SidebarLinks LHN] scaling test – initial render with 500 reports', async () => {
299-
const {reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions(500);
300-
301-
const scenario = async () => {
302-
await screen.findByTestId('lhn-options-list');
303-
};
304-
305-
await Onyx.multiSet({
306-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails,
307-
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
308-
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
309-
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false,
310-
...reports,
311-
...reportActions,
312-
...reportNameValuePairs,
313-
...policies,
314-
...reportMetadata,
315-
} as Partial<OnyxValues>);
316-
317-
await waitForBatchedUpdatesWithAct();
318-
319-
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
320-
});
321116
});

tests/utils/collections/sidebarReports.ts

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ import type {OnyxCollection} from 'react-native-onyx';
33
import type {ReportsToDisplayInLHN} from '@hooks/useSidebarOrderedReports';
44
import CONST from '@src/CONST';
55
import ONYXKEYS from '@src/ONYXKEYS';
6-
import type {PersonalDetails, Report, ReportActions, ReportAttributesDerivedValue, ReportMetadata, ReportNameValuePairs} from '@src/types/onyx';
7-
import type Policy from '@src/types/onyx/Policy';
6+
import type {Report, ReportAttributesDerivedValue, ReportNameValuePairs} from '@src/types/onyx';
87
import createCollection from './createCollection';
9-
import createPersonalDetails from './personalDetails';
10-
import createRandomPolicy from './policies';
11-
import createRandomReportAction from './reportActions';
128
import {createRandomReport} from './reports';
139

1410
/**
@@ -134,74 +130,4 @@ function createSidebarTestData(): {
134130
};
135131
}
136132

137-
const LHN_ACTIONS_PER_REPORT = 50;
138-
139-
function createSidebarReportActions(reportID: string, count: number): ReportActions {
140-
const actions: ReportActions = {};
141-
for (let i = 0; i < count; i++) {
142-
actions[`${reportID}_${i}`] = createRandomReportAction(i);
143-
}
144-
return actions;
145-
}
146-
147-
function createSidebarReportsWithActions(count: number): {
148-
reports: OnyxCollection<Report>;
149-
reportActions: OnyxCollection<ReportActions>;
150-
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>;
151-
policies: OnyxCollection<Policy>;
152-
personalDetails: OnyxCollection<PersonalDetails>;
153-
reportMetadata: OnyxCollection<ReportMetadata>;
154-
} {
155-
const reports: OnyxCollection<Report> = {};
156-
const reportActions: OnyxCollection<ReportActions> = {};
157-
const reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = {};
158-
const policies: OnyxCollection<Policy> = {};
159-
const personalDetails: OnyxCollection<PersonalDetails> = {};
160-
const reportMetadata: OnyxCollection<ReportMetadata> = {};
161-
162-
const basePolicy = createRandomPolicy(1);
163-
policies[`${ONYXKEYS.COLLECTION.POLICY}${basePolicy.id}`] = basePolicy;
164-
165-
for (let i = 1; i <= count; i++) {
166-
const reportID = String(i);
167-
const report = createRandomReport(i, undefined);
168-
169-
const isArchived = i % 10 === 0;
170-
const reportTypeMod = i % 4;
171-
let reportType: Report['type'] = CONST.REPORT.TYPE.CHAT;
172-
if (reportTypeMod === 0) {
173-
reportType = CONST.REPORT.TYPE.IOU;
174-
} else if (reportTypeMod === 1) {
175-
reportType = CONST.REPORT.TYPE.EXPENSE;
176-
}
177-
178-
reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = {
179-
...report,
180-
type: reportType,
181-
};
182-
reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = createSidebarReportActions(reportID, LHN_ACTIONS_PER_REPORT);
183-
reportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`] = {
184-
private_isArchived: isArchived ? 'true' : 'false',
185-
};
186-
187-
const lastActorAccountID = report.lastActorAccountID ?? i;
188-
personalDetails[String(lastActorAccountID)] = createPersonalDetails(lastActorAccountID);
189-
190-
if (i % 5 === 0) {
191-
reportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`] = {
192-
lastVisitTime: new Date().toISOString(),
193-
};
194-
}
195-
}
196-
197-
return {
198-
reports,
199-
reportActions,
200-
reportNameValuePairs,
201-
policies,
202-
personalDetails,
203-
reportMetadata,
204-
};
205-
}
206-
207-
export {createSidebarReport, createSidebarReportsCollection, createSidebarTestData, createSidebarReportsWithActions};
133+
export {createSidebarReport, createSidebarReportsCollection, createSidebarTestData};

0 commit comments

Comments
 (0)