From 010f9bbd428ce59d6ff24cac598b03ae98c692c4 Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Mon, 6 Nov 2023 13:49:46 +0100 Subject: [PATCH 01/10] chore: add perf tests for SidebarUtils --- tests/perf-test/SidebarUtils.perf-test.ts | 84 +++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/perf-test/SidebarUtils.perf-test.ts diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts new file mode 100644 index 000000000000..9ea29bd24af7 --- /dev/null +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -0,0 +1,84 @@ +import Onyx from 'react-native-onyx'; +import {measureFunction} from 'reassure'; +import _ from 'underscore'; +import SidebarUtils from '@libs/SidebarUtils'; +import Policy from '@src/types/onyx/Policy'; +import Report from '@src/types/onyx/Report'; +import ReportAction from '@src/types/onyx/ReportAction'; +import CONST from '../../src/CONST'; +import ONYXKEYS from '../../src/ONYXKEYS'; +import * as LHNTestUtils from '../utils/LHNTestUtils'; +import * as ReportTestUtils from '../utils/ReportTestUtils'; +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; + +jest.setTimeout(60000); + +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 getMockedReportsMap = (length = 100) => { + const mockReports = Array.from({length}, (__, i) => { + const reportID = i + 1; + const participants = [1, 2]; + const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; + const report = LHNTestUtils.getFakeReportWithPolicy(participants, 1, true); + + return {[reportKey]: report}; + }); + + return _.assign({}, ...mockReports); +}; + +const getMockedPoliciesMap = (length = 100) => { + const mockPolicies = Array.from({length}, (__, i) => { + const policyID = i + 1; + const policyKey = `${ONYXKEYS.COLLECTION.POLICY}${policyID}`; + const policy = LHNTestUtils.getFakePolicy(); + + return {[policyKey]: policy}; + }); + + return _.assign({}, ...mockPolicies); +}; + +const mockedResponseMap = getMockedReportsMap(1000); + +test('getOptionData on 1k reports', async () => { + const report = LHNTestUtils.getFakeReportWithPolicy([1, 2], 1, true) as Report; + const reportActions = ReportTestUtils.getMockedReportsMap(); + const personalDetails = LHNTestUtils.fakePersonalDetails; + const preferredLocale = 'en'; + const policy = LHNTestUtils.getFakePolicy() as Policy; + const reportAction = ReportTestUtils.getFakeReportAction(1, 'ADDCOMMENT') as unknown as ReportAction; + + Onyx.multiSet({ + ...mockedResponseMap, + }); + + await waitForBatchedUpdates(); + await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, reportAction), {runs: 20}); +}); + +test('getOrderedReportIDs on 1k reports', async () => { + const currentReportId = '1'; + const allReports = getMockedReportsMap(); + const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; + const policies = getMockedPoliciesMap(); + const reportActions = ReportTestUtils.getMockedReportsMap(); + + Onyx.multiSet({ + ...mockedResponseMap, + }); + + await waitForBatchedUpdates(); + await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, reportActions), {runs: 20}); +}); From 3358947dd2be233b2fd794b0e63f97493340d1e4 Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Mon, 6 Nov 2023 15:00:32 +0100 Subject: [PATCH 02/10] fix lint errors --- tests/perf-test/SidebarUtils.perf-test.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 9ea29bd24af7..93c25e690a15 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,12 +1,11 @@ import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; -import _ from 'underscore'; import SidebarUtils from '@libs/SidebarUtils'; import Policy from '@src/types/onyx/Policy'; import Report from '@src/types/onyx/Report'; import ReportAction from '@src/types/onyx/ReportAction'; -import CONST from '../../src/CONST'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as ReportTestUtils from '../utils/ReportTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -26,7 +25,7 @@ afterEach(() => { }); const getMockedReportsMap = (length = 100) => { - const mockReports = Array.from({length}, (__, i) => { + const mockReports = Array.from({length}, (v, i) => { const reportID = i + 1; const participants = [1, 2]; const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; @@ -35,11 +34,11 @@ const getMockedReportsMap = (length = 100) => { return {[reportKey]: report}; }); - return _.assign({}, ...mockReports); + return Object.assign({}, ...mockReports) as Record; }; const getMockedPoliciesMap = (length = 100) => { - const mockPolicies = Array.from({length}, (__, i) => { + const mockPolicies = Array.from({length}, (v, i) => { const policyID = i + 1; const policyKey = `${ONYXKEYS.COLLECTION.POLICY}${policyID}`; const policy = LHNTestUtils.getFakePolicy(); @@ -47,7 +46,7 @@ const getMockedPoliciesMap = (length = 100) => { return {[policyKey]: policy}; }); - return _.assign({}, ...mockPolicies); + return Object.assign({}, ...mockPolicies) as Record; }; const mockedResponseMap = getMockedReportsMap(1000); From bed054d9acd5b33720f8169113bb513d141a8bed Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Mon, 6 Nov 2023 18:33:00 +0100 Subject: [PATCH 03/10] ts fix --- tests/perf-test/SidebarUtils.perf-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 93c25e690a15..c261e76b6952 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,11 +1,11 @@ import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; import SidebarUtils from '@libs/SidebarUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import Policy from '@src/types/onyx/Policy'; import Report from '@src/types/onyx/Report'; import ReportAction from '@src/types/onyx/ReportAction'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as ReportTestUtils from '../utils/ReportTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -34,7 +34,7 @@ const getMockedReportsMap = (length = 100) => { return {[reportKey]: report}; }); - return Object.assign({}, ...mockReports) as Record; + return Object.assign({}, ...mockReports) as Partial; }; const getMockedPoliciesMap = (length = 100) => { @@ -69,7 +69,7 @@ test('getOptionData on 1k reports', async () => { test('getOrderedReportIDs on 1k reports', async () => { const currentReportId = '1'; - const allReports = getMockedReportsMap(); + const allReports = getMockedReportsMap() as Record; const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; const policies = getMockedPoliciesMap(); const reportActions = ReportTestUtils.getMockedReportsMap(); From 5eca7042d019aa4cbb5f5b321de7e499e7b8d73f Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Tue, 7 Nov 2023 12:45:40 +0100 Subject: [PATCH 04/10] fixes after CR --- tests/perf-test/SidebarUtils.perf-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index c261e76b6952..323f48fd7709 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -53,7 +53,7 @@ const mockedResponseMap = getMockedReportsMap(1000); test('getOptionData on 1k reports', async () => { const report = LHNTestUtils.getFakeReportWithPolicy([1, 2], 1, true) as Report; - const reportActions = ReportTestUtils.getMockedReportsMap(); + const reportActions = ReportTestUtils.getMockedReportActionsMap(); const personalDetails = LHNTestUtils.fakePersonalDetails; const preferredLocale = 'en'; const policy = LHNTestUtils.getFakePolicy() as Policy; @@ -72,7 +72,7 @@ test('getOrderedReportIDs on 1k reports', async () => { const allReports = getMockedReportsMap() as Record; const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; const policies = getMockedPoliciesMap(); - const reportActions = ReportTestUtils.getMockedReportsMap(); + const reportActions = ReportTestUtils.getMockedReportActionsMap(); Onyx.multiSet({ ...mockedResponseMap, From aa106f4668e49329c33a4dbf24ed0a31c4a2c71a Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Wed, 8 Nov 2023 16:45:48 +0100 Subject: [PATCH 05/10] increase the number of the reports --- tests/perf-test/SidebarUtils.perf-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 323f48fd7709..909169181ad8 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -10,7 +10,7 @@ import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as ReportTestUtils from '../utils/ReportTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -jest.setTimeout(60000); +jest.setTimeout(120000); beforeAll(() => Onyx.init({ @@ -49,9 +49,9 @@ const getMockedPoliciesMap = (length = 100) => { return Object.assign({}, ...mockPolicies) as Record; }; -const mockedResponseMap = getMockedReportsMap(1000); +const mockedResponseMap = getMockedReportsMap(10000); -test('getOptionData on 1k reports', async () => { +test('getOptionData on 10k reports', async () => { const report = LHNTestUtils.getFakeReportWithPolicy([1, 2], 1, true) as Report; const reportActions = ReportTestUtils.getMockedReportActionsMap(); const personalDetails = LHNTestUtils.fakePersonalDetails; @@ -67,7 +67,7 @@ test('getOptionData on 1k reports', async () => { await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, reportAction), {runs: 20}); }); -test('getOrderedReportIDs on 1k reports', async () => { +test('getOrderedReportIDs on 10k reports', async () => { const currentReportId = '1'; const allReports = getMockedReportsMap() as Record; const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; From f64231250b7e0b18a0d75171f3f362eb40285f90 Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Tue, 14 Nov 2023 10:18:29 +0100 Subject: [PATCH 06/10] add new mocks --- src/libs/SidebarUtils.ts | 2 +- tests/perf-test/SidebarUtils.perf-test.ts | 71 ++++++++++++----------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ff9486159947..bace29e06d28 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -232,7 +232,7 @@ type ActorDetails = { */ function getOptionData( report: Report, - reportActions: Record, + reportActions: Record, personalDetails: Record, preferredLocale: ValueOf, policy: Policy, diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 909169181ad8..642cf6830f19 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -6,8 +6,11 @@ import ONYXKEYS from '@src/ONYXKEYS'; import Policy from '@src/types/onyx/Policy'; import Report from '@src/types/onyx/Report'; import ReportAction from '@src/types/onyx/ReportAction'; +import createCollection from '../utils/collections/createCollection'; +import createRandomPolicy from '../utils/collections/policies'; +import createRandomReportAction from '../utils/collections/reportActions'; +import createRandomReport from '../utils/collections/reports'; import * as LHNTestUtils from '../utils/LHNTestUtils'; -import * as ReportTestUtils from '../utils/ReportTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; jest.setTimeout(120000); @@ -24,60 +27,60 @@ afterEach(() => { Onyx.clear(); }); -const getMockedReportsMap = (length = 100) => { - const mockReports = Array.from({length}, (v, i) => { - const reportID = i + 1; - const participants = [1, 2]; - const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; - const report = LHNTestUtils.getFakeReportWithPolicy(participants, 1, true); +const getMockedReports = (length = 500) => + createCollection( + (item) => `report_${item.reportID}`, + (index) => createRandomReport(index), + length, + ) as Partial; - return {[reportKey]: report}; - }); - - return Object.assign({}, ...mockReports) as Partial; -}; - -const getMockedPoliciesMap = (length = 100) => { - const mockPolicies = Array.from({length}, (v, i) => { - const policyID = i + 1; - const policyKey = `${ONYXKEYS.COLLECTION.POLICY}${policyID}`; - const policy = LHNTestUtils.getFakePolicy(); - - return {[policyKey]: policy}; - }); - - return Object.assign({}, ...mockPolicies) as Record; -}; +const reportActions = createCollection( + (item) => `${item.reportActionID}`, + (index) => createRandomReportAction(index), +); -const mockedResponseMap = getMockedReportsMap(10000); +const mockedResponseMap = getMockedReports(10000); test('getOptionData on 10k reports', async () => { - const report = LHNTestUtils.getFakeReportWithPolicy([1, 2], 1, true) as Report; - const reportActions = ReportTestUtils.getMockedReportActionsMap(); + const report = createRandomReport(1); const personalDetails = LHNTestUtils.fakePersonalDetails; const preferredLocale = 'en'; - const policy = LHNTestUtils.getFakePolicy() as Policy; - const reportAction = ReportTestUtils.getFakeReportAction(1, 'ADDCOMMENT') as unknown as ReportAction; + const policy = createRandomPolicy(1); + const parentReportAction = createRandomReportAction(1); Onyx.multiSet({ ...mockedResponseMap, }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, reportAction), {runs: 20}); + await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction), {runs: 20}); }); test('getOrderedReportIDs on 10k reports', async () => { const currentReportId = '1'; - const allReports = getMockedReportsMap() as Record; + const allReports = getMockedReports() as Record; const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; - const policies = getMockedPoliciesMap(); - const reportActions = ReportTestUtils.getMockedReportActionsMap(); + + const policies = createCollection( + (item) => `policy_${item.id}`, + (index) => createRandomPolicy(index), + ); + + const allReportActions = Object.values(reportActions).map((reportAction) => ({ + errors: reportAction.errors ?? [], + message: [ + { + moderationDecision: { + decision: reportAction.message?.[0]?.moderationDecision?.decision, + }, + }, + ], + })) as unknown as Record; Onyx.multiSet({ ...mockedResponseMap, }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, reportActions), {runs: 20}); + await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions), {runs: 20}); }); From e58877e54f03e9ee1e8de6ceea6b8084d33b3536 Mon Sep 17 00:00:00 2001 From: OlimpiaZurek Date: Tue, 14 Nov 2023 12:52:16 +0100 Subject: [PATCH 07/10] cr fixes --- tests/perf-test/SidebarUtils.perf-test.ts | 39 +++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 642cf6830f19..47abaaacf249 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -29,17 +29,17 @@ afterEach(() => { const getMockedReports = (length = 500) => createCollection( - (item) => `report_${item.reportID}`, + (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, (index) => createRandomReport(index), length, - ) as Partial; + ); const reportActions = createCollection( (item) => `${item.reportActionID}`, (index) => createRandomReportAction(index), ); -const mockedResponseMap = getMockedReports(10000); +const mockedResponseMap: Partial = getMockedReports(10000); test('getOptionData on 10k reports', async () => { const report = createRandomReport(1); @@ -53,34 +53,41 @@ test('getOptionData on 10k reports', async () => { }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction), {runs: 20}); + await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction)); }); test('getOrderedReportIDs on 10k reports', async () => { const currentReportId = '1'; - const allReports = getMockedReports() as Record; + const allReports = getMockedReports(); const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; const policies = createCollection( - (item) => `policy_${item.id}`, + (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, (index) => createRandomPolicy(index), ); - const allReportActions = Object.values(reportActions).map((reportAction) => ({ - errors: reportAction.errors ?? [], - message: [ - { - moderationDecision: { - decision: reportAction.message?.[0]?.moderationDecision?.decision, + 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 Record; + ], + ]), + ) as Record; Onyx.multiSet({ ...mockedResponseMap, }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions), {runs: 20}); + await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions)); }); From 7f7b82127bd9fdaef3b46d8da054579f482e774b Mon Sep 17 00:00:00 2001 From: Github Date: Wed, 22 Nov 2023 18:18:01 +0100 Subject: [PATCH 08/10] add timeout and runs changes --- tests/perf-test/SidebarUtils.perf-test.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 47abaaacf249..b9d3cf5a379c 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -13,8 +13,6 @@ import createRandomReport from '../utils/collections/reports'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -jest.setTimeout(120000); - beforeAll(() => Onyx.init({ keys: ONYXKEYS, @@ -39,9 +37,10 @@ const reportActions = createCollection( (index) => createRandomReportAction(index), ); -const mockedResponseMap: Partial = getMockedReports(10000); +const mockedResponseMap: Partial = getMockedReports(5000); +const runs = CONST.PERFORMANCE_TESTS.RUNS; -test('getOptionData on 10k reports', async () => { +test('getOptionData on 5k reports', async () => { const report = createRandomReport(1); const personalDetails = LHNTestUtils.fakePersonalDetails; const preferredLocale = 'en'; @@ -53,10 +52,10 @@ test('getOptionData on 10k reports', async () => { }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction)); + await measureFunction(() => SidebarUtils.getOptionData(report, reportActions, personalDetails, preferredLocale, policy, parentReportAction), {runs}); }); -test('getOrderedReportIDs on 10k reports', async () => { +test('getOrderedReportIDs on 5k reports', async () => { const currentReportId = '1'; const allReports = getMockedReports(); const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS]; @@ -89,5 +88,5 @@ test('getOrderedReportIDs on 10k reports', async () => { }); await waitForBatchedUpdates(); - await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions)); + await measureFunction(() => SidebarUtils.getOrderedReportIDs(currentReportId, allReports, betas, policies, CONST.PRIORITY_MODE.DEFAULT, allReportActions), {runs}); }); From 340125f5c4a772edc0db9b30464b2ec8f6416ad3 Mon Sep 17 00:00:00 2001 From: Github Date: Wed, 29 Nov 2023 12:42:33 +0100 Subject: [PATCH 09/10] post cr improvements --- tests/perf-test/SidebarUtils.perf-test.ts | 11 ++++++++--- tests/utils/collections/createCollection.ts | 2 +- tests/utils/collections/personalDetails.ts | 12 ++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/utils/collections/personalDetails.ts diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index b9d3cf5a379c..2d1dacf87657 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -3,14 +3,15 @@ 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 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 * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; beforeAll(() => @@ -37,12 +38,16 @@ const reportActions = createCollection( (index) => createRandomReportAction(index), ); -const mockedResponseMap: Partial = getMockedReports(5000); +const personalDetails = createCollection( + (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 personalDetails = LHNTestUtils.fakePersonalDetails; const preferredLocale = 'en'; const policy = createRandomPolicy(1); const parentReportAction = createRandomReportAction(1); diff --git a/tests/utils/collections/createCollection.ts b/tests/utils/collections/createCollection.ts index 565957b7649e..848ef8f81f47 100644 --- a/tests/utils/collections/createCollection.ts +++ b/tests/utils/collections/createCollection.ts @@ -1,4 +1,4 @@ -export default function createCollection(createKey: (item: T, index: number) => string, createItem: (index: number) => T, length = 500): Record { +export default function createCollection(createKey: (item: T, index: number) => string | number, createItem: (index: number) => T, length = 500): Record { const map: Record = {}; for (let i = 0; i < length; i++) { diff --git a/tests/utils/collections/personalDetails.ts b/tests/utils/collections/personalDetails.ts new file mode 100644 index 000000000000..4fa8586aa08c --- /dev/null +++ b/tests/utils/collections/personalDetails.ts @@ -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(), + }; +} From 5551ab090f04ce98e35f75f6e88d1f8f56aafa7b Mon Sep 17 00:00:00 2001 From: Github Date: Wed, 29 Nov 2023 12:55:01 +0100 Subject: [PATCH 10/10] fix ts --- tests/perf-test/SidebarUtils.perf-test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 2d1dacf87657..7f9957232cfb 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,4 +1,4 @@ -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxCollection} from 'react-native-onyx'; import {measureFunction} from 'reassure'; import SidebarUtils from '@libs/SidebarUtils'; import CONST from '@src/CONST'; @@ -6,7 +6,7 @@ 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 from '@src/types/onyx/ReportAction'; +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'; @@ -86,7 +86,7 @@ test('getOrderedReportIDs on 5k reports', async () => { }, ], ]), - ) as Record; + ) as unknown as OnyxCollection; Onyx.multiSet({ ...mockedResponseMap,