From ac1a048632c0cc7fed7cc54a71df059413b3bc52 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 14 Mar 2024 14:08:27 +0100 Subject: [PATCH 1/3] feat: add initail test setup for OptionListUtils --- src/libs/OptionsListUtils.ts | 4 + tests/perf-test/OptionsListUtils.perf-test.ts | 87 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/perf-test/OptionsListUtils.perf-test.ts diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 3de3d1622405..617427fb8d07 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1720,6 +1720,10 @@ function getOptions( ); } + // console.log('recentReportOptions: ', recentReportOptions); + console.log('userToInvite: ', userToInvite); + console.log('currentUserOption: ', currentUserOption); + return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts new file mode 100644 index 000000000000..41237c6b3538 --- /dev/null +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -0,0 +1,87 @@ +import {rand} from '@ngneat/falso'; +import type * as NativeNavigation from '@react-navigation/native'; +import Onyx from 'react-native-onyx'; +import {measureFunction} from 'reassure'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetails} from '@src/types/onyx'; +import type Policy from '@src/types/onyx/Policy'; +import type Report from '@src/types/onyx/Report'; +import type 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, {getRandomDate} from '../utils/collections/reportActions'; +import createRandomReport from '../utils/collections/reports'; +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; + +const REPORTS_COUNT = 15000; +const PERSONAL_DETAILS_LIST_COUNT = 1000; + +const allReports = createCollection( + (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, + (index) => ({ + ...createRandomReport(index), + type: rand(Object.values(CONST.REPORT.TYPE)), + lastVisibleActionCreated: getRandomDate(), + }), + REPORTS_COUNT, +); + +// const reportActions = createCollection( +// (item) => `${item.reportActionID}`, +// (index) => createRandomReportAction(index), +// ); + +const personalDetails = createCollection( + (item) => item.accountID, + (index) => createPersonalDetails(index), + PERSONAL_DETAILS_LIST_COUNT, +); + +// const policies = createCollection( +// (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, +// (index) => createRandomPolicy(index), +// ); + +const mockedBetas = Object.values(CONST.BETAS); + +jest.mock('@react-navigation/native', () => { + const actualNav = jest.requireActual('@react-navigation/native'); + return { + ...actualNav, + createNavigationContainerRef: () => ({ + getState: () => jest.fn(), + }), + } as typeof NativeNavigation; +}); + +describe('SidebarUtils', () => { + beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], + }); + + Onyx.multiSet({ + [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, + }); + }); + + afterAll(() => { + Onyx.clear(); + }); + + test.only('[OptionsListUtils] getSearchOptions with test search value', async () => { + const SEARCH_VALUE = 'testingvalue'; + await waitForBatchedUpdates(); + await measureFunction(() => OptionsListUtils.getSearchOptions(allReports, personalDetails, SEARCH_VALUE, mockedBetas), {runs: 1}); + }); + + test.only('[OptionsListUtils] getSearchOptions with empty search value', async () => { + const SEARCH_VALUE = ''; + await waitForBatchedUpdates(); + await measureFunction(() => OptionsListUtils.getSearchOptions(allReports, personalDetails, SEARCH_VALUE, mockedBetas), {runs: 1}); + }); +}); From ddd22000d3720f3194451f916394d7787d3767c2 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Fri, 15 Mar 2024 12:29:29 +0100 Subject: [PATCH 2/3] feat: add additional tests for getOption --- src/libs/OptionsListUtils.ts | 9 +-- tests/perf-test/OptionsListUtils.perf-test.ts | 59 ++++++++----------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 617427fb8d07..710221197e4c 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1720,10 +1720,6 @@ function getOptions( ); } - // console.log('recentReportOptions: ', recentReportOptions); - console.log('userToInvite: ', userToInvite); - console.log('currentUserOption: ', currentUserOption); - return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, @@ -1833,6 +1829,11 @@ function getFilteredOptions( taxRates: TaxRatesWithDefault = {} as TaxRatesWithDefault, includeSelfDM = false, ) { + // console.log('personalDetails: ', personalDetails); + // console.log('selectedOptions: ', selectedOptions); + // console.log('tags: ', tags); + // console.log('taxRates: ', taxRates); + return getOptions(reports, personalDetails, { betas, searchInputValue: searchValue.trim(), diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 41237c6b3538..5c11bd1ca027 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -1,25 +1,22 @@ import {rand} from '@ngneat/falso'; import type * as NativeNavigation from '@react-navigation/native'; -import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetails} from '@src/types/onyx'; -import type Policy from '@src/types/onyx/Policy'; import type Report from '@src/types/onyx/Report'; -import type 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, {getRandomDate} from '../utils/collections/reportActions'; +import {getRandomDate} from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -const REPORTS_COUNT = 15000; +const REPORTS_COUNT = 5000; const PERSONAL_DETAILS_LIST_COUNT = 1000; +const SEARCH_VALUE = 'TestingValue'; -const allReports = createCollection( +const reports = createCollection( (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, (index) => ({ ...createRandomReport(index), @@ -29,22 +26,12 @@ const allReports = createCollection( REPORTS_COUNT, ); -// const reportActions = createCollection( -// (item) => `${item.reportActionID}`, -// (index) => createRandomReportAction(index), -// ); - const personalDetails = createCollection( (item) => item.accountID, (index) => createPersonalDetails(index), PERSONAL_DETAILS_LIST_COUNT, ); -// const policies = createCollection( -// (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, -// (index) => createRandomPolicy(index), -// ); - const mockedBetas = Object.values(CONST.BETAS); jest.mock('@react-navigation/native', () => { @@ -57,31 +44,35 @@ jest.mock('@react-navigation/native', () => { } as typeof NativeNavigation; }); -describe('SidebarUtils', () => { - beforeAll(() => { - Onyx.init({ - keys: ONYXKEYS, - safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], - }); +/* GetOption is the private function and is never called directly, we are testing the functions which call getOption with different params */ +describe('OptionsListUtils', () => { + /* Testing getSearchOptions */ + test('[OptionsListUtils] getSearchOptions with search value', async () => { + await waitForBatchedUpdates(); + await measureFunction(() => OptionsListUtils.getSearchOptions(reports, personalDetails, SEARCH_VALUE, mockedBetas)); + }); - Onyx.multiSet({ - [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, - }); + /* Testing getShareLogOptions */ + test('[OptionsListUtils] getShareLogOptions with search value', async () => { + await waitForBatchedUpdates(); + await measureFunction(() => OptionsListUtils.getShareLogOptions(reports, personalDetails, SEARCH_VALUE, mockedBetas)); }); - afterAll(() => { - Onyx.clear(); + /* Testing getFilteredOptions */ + test('[OptionsListUtils] getFilteredOptions with test value', async () => { + await waitForBatchedUpdates(); + await measureFunction(() => OptionsListUtils.getFilteredOptions(reports, personalDetails, mockedBetas, SEARCH_VALUE)); }); - test.only('[OptionsListUtils] getSearchOptions with test search value', async () => { - const SEARCH_VALUE = 'testingvalue'; + /* Testing getShareDestinationOptions */ + test('[OptionsListUtils] getShareDestinationOptions with search value', async () => { await waitForBatchedUpdates(); - await measureFunction(() => OptionsListUtils.getSearchOptions(allReports, personalDetails, SEARCH_VALUE, mockedBetas), {runs: 1}); + await measureFunction(() => OptionsListUtils.getShareDestinationOptions(reports, personalDetails, mockedBetas, SEARCH_VALUE)); }); - test.only('[OptionsListUtils] getSearchOptions with empty search value', async () => { - const SEARCH_VALUE = ''; + /* Testing getMemberInviteOptions */ + test('[OptionsListUtils] getMemberInviteOptions with search value', async () => { await waitForBatchedUpdates(); - await measureFunction(() => OptionsListUtils.getSearchOptions(allReports, personalDetails, SEARCH_VALUE, mockedBetas), {runs: 1}); + await measureFunction(() => OptionsListUtils.getMemberInviteOptions(personalDetails, mockedBetas, SEARCH_VALUE)); }); }); From 5b88a1398190e8642eccfe3f1a30c6a32d27fc2d Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Fri, 15 Mar 2024 12:40:51 +0100 Subject: [PATCH 3/3] chore: cleanup --- src/libs/OptionsListUtils.ts | 5 ----- tests/perf-test/OptionsListUtils.perf-test.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 710221197e4c..3de3d1622405 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1829,11 +1829,6 @@ function getFilteredOptions( taxRates: TaxRatesWithDefault = {} as TaxRatesWithDefault, includeSelfDM = false, ) { - // console.log('personalDetails: ', personalDetails); - // console.log('selectedOptions: ', selectedOptions); - // console.log('tags: ', tags); - // console.log('taxRates: ', taxRates); - return getOptions(reports, personalDetails, { betas, searchInputValue: searchValue.trim(), diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 5c11bd1ca027..d81be3165919 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -59,7 +59,7 @@ describe('OptionsListUtils', () => { }); /* Testing getFilteredOptions */ - test('[OptionsListUtils] getFilteredOptions with test value', async () => { + test('[OptionsListUtils] getFilteredOptions with search value', async () => { await waitForBatchedUpdates(); await measureFunction(() => OptionsListUtils.getFilteredOptions(reports, personalDetails, mockedBetas, SEARCH_VALUE)); });