-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NoQA] chore: add perf tests for SidebarUtils #30909
Merged
mountiny
merged 10 commits into
Expensify:main
from
OlimpiaZurek:feat/SidebarUtils-reassure-tests
Nov 30, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
010f9bb
chore: add perf tests for SidebarUtils
OlimpiaZurek 3358947
fix lint errors
OlimpiaZurek bed054d
ts fix
OlimpiaZurek 5eca704
fixes after CR
OlimpiaZurek aa106f4
increase the number of the reports
OlimpiaZurek f642312
add new mocks
OlimpiaZurek e58877e
cr fixes
OlimpiaZurek 7f7b821
add timeout and runs changes
OlimpiaZurek 340125f
post cr improvements
OlimpiaZurek 5551ab0
fix ts
OlimpiaZurek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(), | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been wrong til now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be
Record<string, ReportAction[]>
, ReportActions is an objects here, not an array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean
Record<string, ReportAction>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes -
Record<string, ReportAction>
😉