-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30909 from OlimpiaZurek/feat/SidebarUtils-reassur…
…e-tests [NoQA] chore: add perf tests for SidebarUtils
- Loading branch information
Showing
4 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Onyx, {OnyxCollection} from 'react-native-onyx'; | ||
import {measureFunction} from 'reassure'; | ||
import SidebarUtils from '@libs/SidebarUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import {PersonalDetails} from '@src/types/onyx'; | ||
import Policy from '@src/types/onyx/Policy'; | ||
import Report from '@src/types/onyx/Report'; | ||
import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction'; | ||
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 waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
||
beforeAll(() => | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
}), | ||
); | ||
|
||
// Clear out Onyx after each test so that each test starts with a clean slate | ||
afterEach(() => { | ||
Onyx.clear(); | ||
}); | ||
|
||
const getMockedReports = (length = 500) => | ||
createCollection<Report>( | ||
(item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, | ||
(index) => createRandomReport(index), | ||
length, | ||
); | ||
|
||
const reportActions = createCollection<ReportAction>( | ||
(item) => `${item.reportActionID}`, | ||
(index) => createRandomReportAction(index), | ||
); | ||
|
||
const personalDetails = createCollection<PersonalDetails>( | ||
(item) => item.accountID, | ||
(index) => createPersonalDetails(index), | ||
); | ||
|
||
const mockedResponseMap = getMockedReports(5000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>; | ||
const runs = CONST.PERFORMANCE_TESTS.RUNS; | ||
|
||
test('getOptionData on 5k reports', async () => { | ||
const report = createRandomReport(1); | ||
const preferredLocale = 'en'; | ||
const policy = createRandomPolicy(1); | ||
const parentReportAction = createRandomReportAction(1); | ||
|
||
Onyx.multiSet({ | ||
...mockedResponseMap, | ||
}); | ||
|
||
await waitForBatchedUpdates(); | ||
await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction), {runs}); | ||
}); | ||
|
||
test('getOrderedReportIDs on 5k reports', async () => { | ||
const currentReportId = '1'; | ||
const allReports = getMockedReports(); | ||
const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; | ||
|
||
const policies = createCollection<Policy>( | ||
(item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, | ||
(index) => createRandomPolicy(index), | ||
); | ||
|
||
const allReportActions = Object.fromEntries( | ||
Object.keys(reportActions).map((key) => [ | ||
key, | ||
[ | ||
{ | ||
errors: reportActions[key].errors ?? [], | ||
message: [ | ||
{ | ||
moderationDecision: { | ||
decision: reportActions[key].message?.[0]?.moderationDecision?.decision, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
]), | ||
) as unknown as OnyxCollection<ReportActions>; | ||
|
||
Onyx.multiSet({ | ||
...mockedResponseMap, | ||
}); | ||
|
||
await waitForBatchedUpdates(); | ||
await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions), {runs}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {randAvatar, randEmail, randWord} from '@ngneat/falso'; | ||
import type {PersonalDetails} from '@src/types/onyx'; | ||
|
||
export default function createPersonalDetails(index: number): PersonalDetails { | ||
return { | ||
accountID: index, | ||
avatar: randAvatar(), | ||
displayName: randWord(), | ||
lastName: randWord(), | ||
login: randEmail(), | ||
}; | ||
} |