From 33b1400e8145283b02947e897e180d5fa4260d37 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 13:29:47 +0300 Subject: [PATCH 01/27] wip migrate ViolationUtilsTest to ts --- tests/unit/{ViolationUtilsTest.js => ViolationUtilsTest.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit/{ViolationUtilsTest.js => ViolationUtilsTest.ts} (100%) diff --git a/tests/unit/ViolationUtilsTest.js b/tests/unit/ViolationUtilsTest.ts similarity index 100% rename from tests/unit/ViolationUtilsTest.js rename to tests/unit/ViolationUtilsTest.ts From dbe4d7c6cfd55310e55ae7faf0dde80276890e95 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 16:24:04 +0300 Subject: [PATCH 02/27] finished migrating ViolationUtilsTest to ts --- tests/unit/ViolationUtilsTest.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 15a3a4f7de07..3365d8793a5d 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -2,6 +2,7 @@ import {beforeEach} from '@jest/globals'; import Onyx from 'react-native-onyx'; import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {PolicyCategories, PolicyTagList, Transaction, TransactionViolation} from '@src/types/onyx'; const categoryOutOfPolicyViolation = { name: 'categoryOutOfPolicy', @@ -24,15 +25,15 @@ const missingTagViolation = { }; describe('getViolationsOnyxData', () => { - let transaction; - let transactionViolations; - let policyRequiresTags; - let policyTags; - let policyRequiresCategories; - let policyCategories; + let transaction: Transaction; + let transactionViolations: TransactionViolation[]; + let policyRequiresTags: boolean; + let policyTags: PolicyTagList; + let policyRequiresCategories: boolean; + let policyCategories: PolicyCategories; beforeEach(() => { - transaction = {transactionID: '123'}; + transaction = {transactionID: '123', reportID: '1234', amount: 100, comment: {}, created: '2023-07-24 13:46:20', merchant: 'United Airlines', currency: 'USD'}; transactionViolations = []; policyRequiresTags = false; policyTags = {}; @@ -62,12 +63,13 @@ describe('getViolationsOnyxData', () => { describe('policyRequiresCategories', () => { beforeEach(() => { policyRequiresCategories = true; - policyCategories = {Food: {enabled: true}}; + // eslint-disable-next-line @typescript-eslint/naming-convention + policyCategories = {Food: {name:'Food', enabled: true, areCommentsRequired: false, 'GL Code': '1234', externalID: '1234', origin: '12345'}}; transaction.category = 'Food'; }); it('should add missingCategory violation if no category is included', () => { - transaction.category = null; + transaction.category = undefined; const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policyRequiresTags, policyTags, policyRequiresCategories, policyCategories); expect(result.value).toEqual(expect.arrayContaining([missingCategoryViolation, ...transactionViolations])); }); @@ -129,8 +131,10 @@ describe('getViolationsOnyxData', () => { name: 'Meals', required: true, tags: { - Lunch: {name: 'Lunch', enabled: true}, - Dinner: {name: 'Dinner', enabled: true}, + // eslint-disable-next-line @typescript-eslint/naming-convention + Lunch: {name: 'Lunch', enabled: true, 'GL Code': ''}, + // eslint-disable-next-line @typescript-eslint/naming-convention + Dinner: {name: 'Dinner', enabled: true, 'GL Code': ''}, }, }, }; From 9d10ab7f56283a300cc9166bf959ac8da15943cd Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 16:36:51 +0300 Subject: [PATCH 03/27] migrate UserUtilsTest to ts --- tests/unit/{UserUtilsTest.js => UserUtilsTest.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/unit/{UserUtilsTest.js => UserUtilsTest.ts} (86%) diff --git a/tests/unit/UserUtilsTest.js b/tests/unit/UserUtilsTest.ts similarity index 86% rename from tests/unit/UserUtilsTest.js rename to tests/unit/UserUtilsTest.ts index f0f20fc6d4cb..f91f2a499e79 100644 --- a/tests/unit/UserUtilsTest.js +++ b/tests/unit/UserUtilsTest.ts @@ -1,4 +1,4 @@ -import * as UserUtils from '../../src/libs/UserUtils'; +import * as UserUtils from '@src/libs/UserUtils'; describe('UserUtils', () => { it('should return the default avatar from the avatar url', () => { From 0bfbaee6582d78c710dcced44db112c8fc30d754 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 16:38:12 +0300 Subject: [PATCH 04/27] migrate PhoneNumberTest to ts --- tests/unit/{PhoneNumberTest.js => PhoneNumberTest.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit/{PhoneNumberTest.js => PhoneNumberTest.ts} (100%) diff --git a/tests/unit/PhoneNumberTest.js b/tests/unit/PhoneNumberTest.ts similarity index 100% rename from tests/unit/PhoneNumberTest.js rename to tests/unit/PhoneNumberTest.ts From cb7e2615cacf0bf0cb62a20472da1e650e4a9902 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 17:46:02 +0300 Subject: [PATCH 05/27] wip migrate SearchPage.perf-test to ts --- ....perf-test.js => SearchPage.perf-test.tsx} | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) rename tests/perf-test/{SearchPage.perf-test.js => SearchPage.perf-test.tsx} (91%) diff --git a/tests/perf-test/SearchPage.perf-test.js b/tests/perf-test/SearchPage.perf-test.tsx similarity index 91% rename from tests/perf-test/SearchPage.perf-test.js rename to tests/perf-test/SearchPage.perf-test.tsx index be6b6a5d78f9..884acc243b81 100644 --- a/tests/perf-test/SearchPage.perf-test.js +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -1,14 +1,17 @@ import {fireEvent, screen, waitFor} from '@testing-library/react-native'; +import type * as NativeNavigation from '@react-navigation/native'; import React from 'react'; +import type {ComponentType} from 'react'; import Onyx from 'react-native-onyx'; import {measurePerformance} from 'reassure'; -import _ from 'underscore'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; import SearchPage from '@pages/SearchPage'; -import ComposeProviders from '../../src/components/ComposeProviders'; -import OnyxProvider from '../../src/components/OnyxProvider'; -import CONST from '../../src/CONST'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import ComposeProviders from '@src/components/ComposeProviders'; +import OnyxProvider from '@src/components/OnyxProvider'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetails, Report} from '@src/types/onyx' +import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomReport from '../utils/collections/reports'; @@ -50,11 +53,13 @@ jest.mock('@react-navigation/native', () => { addListener: () => jest.fn(), }), createNavigationContainerRef: jest.fn(), - }; + } as typeof NativeNavigation; }); -jest.mock('../../src/components/withNavigationFocus', () => (Component) => { - function WithNavigationFocus(props) { + + +jest.mock('../../src/components/withNavigationFocus', () => (Component: ComponentType) => { + function WithNavigationFocus(props: WithNavigationFocusProps) { return ( (Component) => { }); const getMockedReports = (length = 100) => - createCollection( + createCollection( (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, (index) => createRandomReport(index), length, ); const getMockedPersonalDetails = (length = 100) => - createCollection( + createCollection( (item) => item.accountID, (index) => createPersonalDetails(index), length, ); const mockedReports = getMockedReports(600); -const mockedBetas = _.values(CONST.BETAS); +const mockedBetas = Object.values(CONST.BETAS); const mockedPersonalDetails = getMockedPersonalDetails(100); beforeAll(() => From 8d354d1f2d794922390ee3bafe79523033501a0d Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 17 Feb 2024 20:00:08 +0300 Subject: [PATCH 06/27] created type SearchPageProps --- tests/perf-test/SearchPage.perf-test.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 884acc243b81..5e74a838412c 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -102,7 +102,7 @@ beforeAll(() => // Initialize the network key for OfflineWithFeedback beforeEach(() => { - global.fetch = TestHelper.getGlobalFetchMock(); + global.fetch = TestHelper.getGlobalFetchMock() as typeof fetch; wrapOnyxWithWaitForBatchedUpdates(Onyx); Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); }); @@ -113,7 +113,17 @@ afterEach(() => { PusherHelper.teardown(); }); -function SearchPageWrapper(args) { +type SearchPageProps = { + betas?: string[], + + reports?: Record, + + isSearchingForReports?: boolean, + + navigation: Record, +}; + +function SearchPageWrapper(args: SearchPageProps) { return ( Date: Sat, 17 Feb 2024 23:10:22 +0300 Subject: [PATCH 07/27] created type for createAddListenerMock() --- tests/perf-test/SearchPage.perf-test.tsx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 5e74a838412c..0231e0868454 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -2,6 +2,7 @@ import {fireEvent, screen, waitFor} from '@testing-library/react-native'; import type * as NativeNavigation from '@react-navigation/native'; import React from 'react'; import type {ComponentType} from 'react'; +import type {TextMatch} from '@testing-library/react-native/build/matches'; import Onyx from 'react-native-onyx'; import {measurePerformance} from 'reassure'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; @@ -116,7 +117,7 @@ afterEach(() => { type SearchPageProps = { betas?: string[], - reports?: Record, + reports?: Report, isSearchingForReports?: boolean, @@ -135,8 +136,13 @@ function SearchPageWrapper(args: SearchPageProps) { ); } -test('[Search Page] should interact when text input changes', async () => { - const {addListener} = TestHelper.createAddListenerMock(); +type CreateAddListenerMock = { + triggerTransitionEnd?: () => Record, + addListener?: () => Record, +}; + +test.skip('[Search Page] should interact when text input changes', async () => { + const {addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); @@ -162,15 +168,15 @@ test('[Search Page] should interact when text input changes', async () => { }); test('[Search Page] should render selection list', async () => { - const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); + const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); const smallMockedPersonalDetails = getMockedPersonalDetails(5); const scenario = async () => { await screen.findByTestId('SearchPage'); await waitFor(triggerTransitionEnd); await screen.findByTestId('selection-list'); - await screen.findByText(smallMockedPersonalDetails['1'].login); - await screen.findByText(smallMockedPersonalDetails['2'].login); + await screen.findByText(smallMockedPersonalDetails['1'].login as TextMatch); + await screen.findByText(smallMockedPersonalDetails['2'].login as TextMatch); }; const navigation = {addListener}; @@ -188,7 +194,7 @@ test('[Search Page] should render selection list', async () => { }); test('[Search Page] should search in selection list', async () => { - const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); + const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); @@ -198,7 +204,7 @@ test('[Search Page] should search in selection list', async () => { const searchValue = mockedPersonalDetails['88'].login; fireEvent.changeText(input, searchValue); - await screen.findByText(searchValue); + await screen.findByText(searchValue as TextMatch); }; const navigation = {addListener}; @@ -216,7 +222,7 @@ test('[Search Page] should search in selection list', async () => { }); test('[Search Page] should click on list item', async () => { - const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); + const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); From 6ff1321880608e64d42f5eed773ed680b33bedde Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sun, 18 Feb 2024 16:10:03 +0300 Subject: [PATCH 08/27] wip migrate OptionsSelector.perf-test to ts --- ...-test.js => OptionsSelector.perf-test.tsx} | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) rename tests/perf-test/{OptionsSelector.perf-test.js => OptionsSelector.perf-test.tsx} (69%) diff --git a/tests/perf-test/OptionsSelector.perf-test.js b/tests/perf-test/OptionsSelector.perf-test.tsx similarity index 69% rename from tests/perf-test/OptionsSelector.perf-test.js rename to tests/perf-test/OptionsSelector.perf-test.tsx index 6104ded05c6a..08d1caaf5f34 100644 --- a/tests/perf-test/OptionsSelector.perf-test.js +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -1,12 +1,15 @@ import {fireEvent} from '@testing-library/react-native'; import React from 'react'; +import type {ComponentType} from 'react'; +import type {WithLocalizeProps} from '@components/withLocalize'; +import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; +import type {RenderResult} from '@testing-library/react-native'; import {measurePerformance} from 'reassure'; -import _ from 'underscore'; import OptionsSelector from '@src/components/OptionsSelector'; import variables from '@src/styles/variables'; -jest.mock('../../src/components/withLocalize', () => (Component) => { - function WrappedComponent(props) { +jest.mock('../../src/components/withLocalize', () => (Component: ComponentType) => { + function WrappedComponent(props: WithLocalizeProps) { return ( (Component) => { return WrappedComponent; }); -jest.mock('../../src/components/withNavigationFocus', () => (Component) => { - function WithNavigationFocus(props) { +jest.mock('../../src/components/withNavigationFocus', () => (Component: ComponentType) => { + function WithNavigationFocus(props: WithNavigationFocusProps) { return ( (Component) => { return WithNavigationFocus; }); -const generateSections = (sectionConfigs) => - _.map(sectionConfigs, ({numItems, indexOffset, shouldShow = true}) => ({ +type SingleSectionConfigs = Array<{numItems: number, indexOffset: number, shouldShow?: boolean}>; +type SectionConfigs = (Props: {value: number, index: number, array: SingleSectionConfigs}) => Array>; + +const generateSections = (sectionConfigs: SingleSectionConfigs) => + Array.prototype.map(sectionConfigs as unknown as SectionConfigs, ({numItems, indexOffset, shouldShow = true}: {numItems: number, indexOffset: number, shouldShow: boolean}) => ({ + // eslint-disable-next-line @typescript-eslint/naming-convention data: Array.from({length: numItems}, (_v, i) => ({ text: `Item ${i + indexOffset}`, keyForList: `item-${i + indexOffset}`, @@ -65,7 +72,7 @@ function OptionsSelectorWrapper(args) { } test('[OptionsSelector] should render text input with interactions', () => { - const scenario = (screen) => { + const scenario = (screen: RenderResult) => { const textInput = screen.getByTestId('options-selector-input'); fireEvent.changeText(textInput, 'test'); fireEvent.changeText(textInput, 'test2'); @@ -85,7 +92,7 @@ test('[OptionsSelector] should render multiple sections', () => { }); test('[OptionsSelector] should press a list items', () => { - const scenario = (screen) => { + const scenario = (screen: RenderResult) => { fireEvent.press(screen.getByText('Item 1')); fireEvent.press(screen.getByText('Item 5')); fireEvent.press(screen.getByText('Item 10')); @@ -94,10 +101,12 @@ test('[OptionsSelector] should press a list items', () => { measurePerformance(, {scenario}); }); +// type GenerateEventData = Record; + test('[OptionsSelector] should scroll and press few items', () => { const sections = generateSections(mutlipleSectionsConfig); - const generateEventData = (numOptions, optionRowHeight) => ({ + const generateEventData = (numOptions: number, optionRowHeight: number) => ({ nativeEvent: { contentOffset: { y: optionRowHeight * numOptions, @@ -115,7 +124,7 @@ test('[OptionsSelector] should scroll and press few items', () => { const eventData = generateEventData(100, variables.optionRowHeight); const eventData2 = generateEventData(200, variables.optionRowHeight); - const scenario = async (screen) => { + const scenario = async (screen: RenderResult) => { fireEvent.press(screen.getByText('Item 10')); fireEvent.scroll(screen.getByTestId('options-list'), eventData); fireEvent.press(await screen.findByText('Item 100')); From 6cae028d0e2f50e98c2529800da97ad2208e6780 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 19 Feb 2024 00:45:49 +0300 Subject: [PATCH 09/27] used Awaited utility type to fix Promise related issue --- tests/perf-test/OptionsSelector.perf-test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index 08d1caaf5f34..6afab360d9c1 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -72,12 +72,12 @@ function OptionsSelectorWrapper(args) { } test('[OptionsSelector] should render text input with interactions', () => { - const scenario = (screen: RenderResult) => { + const scenario = ((screen: RenderResult) => { const textInput = screen.getByTestId('options-selector-input'); fireEvent.changeText(textInput, 'test'); fireEvent.changeText(textInput, 'test2'); fireEvent.changeText(textInput, 'test3'); - }; + }) as Awaited<(screen: RenderResult) => Promise>; measurePerformance(, {scenario}); }); @@ -92,11 +92,11 @@ test('[OptionsSelector] should render multiple sections', () => { }); test('[OptionsSelector] should press a list items', () => { - const scenario = (screen: RenderResult) => { + const scenario = ((screen: RenderResult) => { fireEvent.press(screen.getByText('Item 1')); fireEvent.press(screen.getByText('Item 5')); fireEvent.press(screen.getByText('Item 10')); - }; + }) as Awaited<(screen: RenderResult) => Promise>; measurePerformance(, {scenario}); }); From 7b5f8390b6e9f758f44f3cebd3ec82f00250da71 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 19 Feb 2024 15:26:39 +0300 Subject: [PATCH 10/27] code cleanup --- tests/perf-test/OptionsSelector.perf-test.tsx | 6 ++---- tests/perf-test/SearchPage.perf-test.tsx | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index 6afab360d9c1..70b6ab5fec7e 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -8,7 +8,7 @@ import {measurePerformance} from 'reassure'; import OptionsSelector from '@src/components/OptionsSelector'; import variables from '@src/styles/variables'; -jest.mock('../../src/components/withLocalize', () => (Component: ComponentType) => { +jest.mock('@src/components/withLocalize', () => (Component: ComponentType) => { function WrappedComponent(props: WithLocalizeProps) { return ( (Component: ComponentType (Component: ComponentType) => { +jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType) => { function WithNavigationFocus(props: WithNavigationFocusProps) { return ( { measurePerformance(, {scenario}); }); -// type GenerateEventData = Record; - test('[OptionsSelector] should scroll and press few items', () => { const sections = generateSections(mutlipleSectionsConfig); diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 0231e0868454..587b09f9e695 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -137,7 +137,7 @@ function SearchPageWrapper(args: SearchPageProps) { } type CreateAddListenerMock = { - triggerTransitionEnd?: () => Record, + triggerTransitionEnd?: () => void, addListener?: () => Record, }; @@ -173,7 +173,7 @@ test('[Search Page] should render selection list', async () => { const scenario = async () => { await screen.findByTestId('SearchPage'); - await waitFor(triggerTransitionEnd); + await waitFor(triggerTransitionEnd as Awaited<() => Promise>); await screen.findByTestId('selection-list'); await screen.findByText(smallMockedPersonalDetails['1'].login as TextMatch); await screen.findByText(smallMockedPersonalDetails['2'].login as TextMatch); @@ -229,7 +229,7 @@ test('[Search Page] should click on list item', async () => { const input = screen.getByTestId('selection-list-text-input'); await waitFor(triggerTransitionEnd); - const searchValue = mockedPersonalDetails['4'].login; + const searchValue = mockedPersonalDetails['4'].login as TextMatch; fireEvent.changeText(input, searchValue); const optionButton = await screen.findByText(searchValue); From 46506f0a9e23df536438cd2544ab712412890c78 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 19 Feb 2024 20:51:25 +0300 Subject: [PATCH 11/27] migrate PolicyTest to ts --- .../actions/{PolicyTest.js => PolicyTest.ts} | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) rename tests/actions/{PolicyTest.js => PolicyTest.ts} (60%) diff --git a/tests/actions/PolicyTest.js b/tests/actions/PolicyTest.ts similarity index 60% rename from tests/actions/PolicyTest.js rename to tests/actions/PolicyTest.ts index 5a994aaf600e..cd3c98594f53 100644 --- a/tests/actions/PolicyTest.js +++ b/tests/actions/PolicyTest.ts @@ -1,9 +1,10 @@ -import _ from 'lodash'; import Onyx from 'react-native-onyx'; import CONST from '@src/CONST'; -import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; -import * as Policy from '../../src/libs/actions/Policy'; -import ONYXKEYS from '../../src/ONYXKEYS'; +import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; +import * as POLICY from '@src/libs/actions/Policy'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Policy, PolicyMembers, Report, ReportActions} from '@src/types/onyx'; +import type {OnyxCollection} from 'react-native-onyx'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -20,7 +21,7 @@ describe('actions/Policy', () => { }); beforeEach(() => { - global.fetch = TestHelper.getGlobalFetchMock(); + global.fetch = TestHelper.getGlobalFetchMock() as typeof fetch; return Onyx.clear().then(waitForBatchedUpdates); }); @@ -33,12 +34,12 @@ describe('actions/Policy', () => { let adminReportID; let announceReportID; let expenseReportID; - const policyID = Policy.generatePolicyID(); + const policyID = POLICY.generatePolicyID(); - Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID); + POLICY.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID); await waitForBatchedUpdates(); - let policy = await new Promise((resolve) => { + let policy: OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, waitForCollectionCallback: true, @@ -50,15 +51,15 @@ describe('actions/Policy', () => { }); // check if policy was created with correct values - expect(policy.id).toBe(policyID); - expect(policy.name).toBe(WORKSPACE_NAME); - expect(policy.type).toBe(CONST.POLICY.TYPE.FREE); - expect(policy.role).toBe(CONST.POLICY.ROLE.ADMIN); - expect(policy.owner).toBe(ESH_EMAIL); - expect(policy.isPolicyExpenseChatEnabled).toBe(true); - expect(policy.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - - const policyMembers = await new Promise((resolve) => { + expect(policy?.id).toBe(policyID); + expect(policy?.type).toBe(CONST.POLICY.TYPE.FREE); + expect(policy?.name).toBe(WORKSPACE_NAME); + expect(policy?.role).toBe(CONST.POLICY.ROLE.ADMIN); + expect(policy?.owner).toBe(ESH_EMAIL); + expect(policy?.isPolicyExpenseChatEnabled).toBe(true); + expect(policy?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + + const policyMembers: OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, waitForCollectionCallback: true, @@ -70,9 +71,9 @@ describe('actions/Policy', () => { }); // check if the user was added as an admin to the policy - expect(policyMembers[ESH_ACCOUNT_ID].role).toBe(CONST.POLICY.ROLE.ADMIN); + expect(policyMembers?.[ESH_ACCOUNT_ID]?.role).toBe(CONST.POLICY.ROLE.ADMIN); - let allReports = await new Promise((resolve) => { + let allReports: OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, @@ -84,12 +85,12 @@ describe('actions/Policy', () => { }); // Three reports should be created: #announce, #admins and expense report - const workspaceReports = _.filter(allReports, (report) => report.policyID === policyID); - expect(_.size(workspaceReports)).toBe(3); - _.forEach(workspaceReports, (report) => { - expect(report.pendingFields.addWorkspaceRoom).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - expect(report.participantAccountIDs).toEqual([ESH_ACCOUNT_ID]); - switch (report.chatType) { + const workspaceReports = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID); + expect(workspaceReports.length).toBe(3); + workspaceReports.forEach((report) => { + expect(report?.pendingFields?.addWorkspaceRoom).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + expect(report?.participantAccountIDs).toEqual([ESH_ACCOUNT_ID]); + switch (report?.chatType) { case CONST.REPORT.CHAT_TYPE.POLICY_ADMINS: { adminReportID = report.reportID; break; @@ -107,7 +108,7 @@ describe('actions/Policy', () => { } }); - let reportActions = await new Promise((resolve) => { + let reportActions: OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, waitForCollectionCallback: true, @@ -119,14 +120,14 @@ describe('actions/Policy', () => { }); // Each of the three reports should have a a `CREATED` action. - let adminReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`]); - let announceReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`]); - let expenseReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`]); - let workspaceReportActions = _.concat(adminReportActions, announceReportActions, expenseReportActions); - _.forEach([adminReportActions, announceReportActions, expenseReportActions], (actions) => { - expect(_.size(actions)).toBe(1); + let adminReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`] ?? {}); + let announceReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`] ?? {}); + let expenseReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`] ?? {}); + let workspaceReportActions = adminReportActions.concat(announceReportActions, expenseReportActions); + [adminReportActions, announceReportActions, expenseReportActions].forEach((actions) => { + expect(actions.length).toBe(1); }); - _.forEach([...adminReportActions, ...announceReportActions, ...expenseReportActions], (reportAction) => { + [...adminReportActions, ...announceReportActions, ...expenseReportActions].forEach((reportAction) => { expect(reportAction.actionName).toBe(CONST.REPORT.ACTIONS.TYPE.CREATED); expect(reportAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); expect(reportAction.actorAccountID).toBe(ESH_ACCOUNT_ID); @@ -148,7 +149,7 @@ describe('actions/Policy', () => { }); // Check if the policy pending action was cleared - expect(policy.pendingAction).toBeFalsy(); + expect(policy?.pendingAction).toBeFalsy(); allReports = await new Promise((resolve) => { const connectionID = Onyx.connect({ @@ -162,9 +163,9 @@ describe('actions/Policy', () => { }); // Check if the report pending action and fields were cleared - _.forEach(allReports, (report) => { - expect(report.pendingAction).toBeFalsy(); - expect(report.pendingFields.addWorkspaceRoom).toBeFalsy(); + Object.values(allReports ?? {}).forEach((report) => { + expect(report?.pendingAction).toBeFalsy(); + expect(report?.pendingFields?.addWorkspaceRoom).toBeFalsy(); }); reportActions = await new Promise((resolve) => { @@ -179,11 +180,11 @@ describe('actions/Policy', () => { }); // Check if the report action pending action was cleared - adminReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`]); - announceReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`]); - expenseReportActions = _.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`]); - workspaceReportActions = _.concat(adminReportActions, announceReportActions, expenseReportActions); - _.forEach(workspaceReportActions, (reportAction) => { + adminReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`] ?? {}); + announceReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`] ?? {}); + expenseReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`] ?? {}); + workspaceReportActions = adminReportActions.concat(announceReportActions, expenseReportActions); + workspaceReportActions.forEach((reportAction) => { expect(reportAction.pendingAction).toBeFalsy(); }); }); From 2d930dc8618424210d650e38410c750ddaf764ee Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 19 Feb 2024 20:52:08 +0300 Subject: [PATCH 12/27] used Array.prototype.map correctly --- tests/perf-test/OptionsSelector.perf-test.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index 70b6ab5fec7e..496f14fe74a6 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -38,11 +38,10 @@ jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType return WithNavigationFocus; }); -type SingleSectionConfigs = Array<{numItems: number, indexOffset: number, shouldShow?: boolean}>; -type SectionConfigs = (Props: {value: number, index: number, array: SingleSectionConfigs}) => Array>; +type GenerateSectionProps = Array<{numItems: number, indexOffset: number, shouldShow?: boolean}>; -const generateSections = (sectionConfigs: SingleSectionConfigs) => - Array.prototype.map(sectionConfigs as unknown as SectionConfigs, ({numItems, indexOffset, shouldShow = true}: {numItems: number, indexOffset: number, shouldShow: boolean}) => ({ +const generateSections = (sectionConfigs: GenerateSectionProps) => + sectionConfigs.map(({numItems, indexOffset, shouldShow = true}) => ({ // eslint-disable-next-line @typescript-eslint/naming-convention data: Array.from({length: numItems}, (_v, i) => ({ text: `Item ${i + indexOffset}`, From 59071f1e2f38921133c5f25f911d64c4cc0f28ff Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 19 Feb 2024 21:10:04 +0300 Subject: [PATCH 13/27] removed unnecessary changes --- tests/actions/PolicyTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index cd3c98594f53..80829d0af9e8 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -52,8 +52,8 @@ describe('actions/Policy', () => { // check if policy was created with correct values expect(policy?.id).toBe(policyID); - expect(policy?.type).toBe(CONST.POLICY.TYPE.FREE); expect(policy?.name).toBe(WORKSPACE_NAME); + expect(policy?.type).toBe(CONST.POLICY.TYPE.FREE); expect(policy?.role).toBe(CONST.POLICY.ROLE.ADMIN); expect(policy?.owner).toBe(ESH_EMAIL); expect(policy?.isPolicyExpenseChatEnabled).toBe(true); From 3cc250cf67f2209f89fdabf30bf73da960093442 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Tue, 20 Feb 2024 14:04:55 +0300 Subject: [PATCH 14/27] run prettier --- tests/actions/PolicyTest.ts | 2 +- tests/perf-test/OptionsSelector.perf-test.tsx | 8 ++++---- tests/perf-test/SearchPage.perf-test.tsx | 20 +++++++++---------- tests/unit/ViolationUtilsTest.ts | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index 80829d0af9e8..9b23ea4ef2f4 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -1,10 +1,10 @@ import Onyx from 'react-native-onyx'; +import type {OnyxCollection} from 'react-native-onyx'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as POLICY from '@src/libs/actions/Policy'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy, PolicyMembers, Report, ReportActions} from '@src/types/onyx'; -import type {OnyxCollection} from 'react-native-onyx'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index 496f14fe74a6..0a8dcc96686d 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -1,10 +1,10 @@ import {fireEvent} from '@testing-library/react-native'; +import type {RenderResult} from '@testing-library/react-native'; import React from 'react'; import type {ComponentType} from 'react'; +import {measurePerformance} from 'reassure'; import type {WithLocalizeProps} from '@components/withLocalize'; import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; -import type {RenderResult} from '@testing-library/react-native'; -import {measurePerformance} from 'reassure'; import OptionsSelector from '@src/components/OptionsSelector'; import variables from '@src/styles/variables'; @@ -38,9 +38,9 @@ jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType return WithNavigationFocus; }); -type GenerateSectionProps = Array<{numItems: number, indexOffset: number, shouldShow?: boolean}>; +type GenerateSectionsProps = Array<{numItems: number; indexOffset: number; shouldShow?: boolean}>; -const generateSections = (sectionConfigs: GenerateSectionProps) => +const generateSections = (sectionConfigs: GenerateSectionsProps) => sectionConfigs.map(({numItems, indexOffset, shouldShow = true}) => ({ // eslint-disable-next-line @typescript-eslint/naming-convention data: Array.from({length: numItems}, (_v, i) => ({ diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 587b09f9e695..4aeb84af0c0c 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -1,18 +1,18 @@ import {fireEvent, screen, waitFor} from '@testing-library/react-native'; import type * as NativeNavigation from '@react-navigation/native'; +import type {TextMatch} from '@testing-library/react-native/build/matches'; import React from 'react'; import type {ComponentType} from 'react'; -import type {TextMatch} from '@testing-library/react-native/build/matches'; import Onyx from 'react-native-onyx'; import {measurePerformance} from 'reassure'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; +import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; import SearchPage from '@pages/SearchPage'; import ComposeProviders from '@src/components/ComposeProviders'; import OnyxProvider from '@src/components/OnyxProvider'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetails, Report} from '@src/types/onyx' -import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; +import type {PersonalDetails, Report} from '@src/types/onyx'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomReport from '../utils/collections/reports'; @@ -57,8 +57,6 @@ jest.mock('@react-navigation/native', () => { } as typeof NativeNavigation; }); - - jest.mock('../../src/components/withNavigationFocus', () => (Component: ComponentType) => { function WithNavigationFocus(props: WithNavigationFocusProps) { return ( @@ -115,13 +113,13 @@ afterEach(() => { }); type SearchPageProps = { - betas?: string[], + betas?: string[]; - reports?: Report, + reports?: Report; - isSearchingForReports?: boolean, + isSearchingForReports?: boolean; - navigation: Record, + navigation: Record; }; function SearchPageWrapper(args: SearchPageProps) { @@ -137,8 +135,8 @@ function SearchPageWrapper(args: SearchPageProps) { } type CreateAddListenerMock = { - triggerTransitionEnd?: () => void, - addListener?: () => Record, + triggerTransitionEnd?: () => void; + addListener?: () => Record; }; test.skip('[Search Page] should interact when text input changes', async () => { diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 3365d8793a5d..a6604bcc66c2 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -64,7 +64,7 @@ describe('getViolationsOnyxData', () => { beforeEach(() => { policyRequiresCategories = true; // eslint-disable-next-line @typescript-eslint/naming-convention - policyCategories = {Food: {name:'Food', enabled: true, areCommentsRequired: false, 'GL Code': '1234', externalID: '1234', origin: '12345'}}; + policyCategories = {Food: {name: 'Food', enabled: true, areCommentsRequired: false, 'GL Code': '1234', externalID: '1234', origin: '12345'}}; transaction.category = 'Food'; }); From b0a88ed2c9e98d3e56eafd5b5465ea58ef02d9dd Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 4 Mar 2024 23:08:21 +0300 Subject: [PATCH 15/27] run prettier --- tests/perf-test/SearchPage.perf-test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 4aeb84af0c0c..dd376f8922e3 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -1,5 +1,5 @@ -import {fireEvent, screen, waitFor} from '@testing-library/react-native'; import type * as NativeNavigation from '@react-navigation/native'; +import {fireEvent, screen, waitFor} from '@testing-library/react-native'; import type {TextMatch} from '@testing-library/react-native/build/matches'; import React from 'react'; import type {ComponentType} from 'react'; @@ -196,7 +196,7 @@ test('[Search Page] should search in selection list', async () => { const scenario = async () => { await screen.findByTestId('SearchPage'); - await waitFor(triggerTransitionEnd); + await waitFor(triggerTransitionEnd as Awaited<() => Promise>); const input = screen.getByTestId('selection-list-text-input'); const searchValue = mockedPersonalDetails['88'].login; @@ -225,7 +225,7 @@ test('[Search Page] should click on list item', async () => { const scenario = async () => { await screen.findByTestId('SearchPage'); const input = screen.getByTestId('selection-list-text-input'); - await waitFor(triggerTransitionEnd); + await waitFor(triggerTransitionEnd as Awaited<() => Promise>); const searchValue = mockedPersonalDetails['4'].login as TextMatch; fireEvent.changeText(input, searchValue); From dff82ff7c821e3e9af4987b2985646bce3a969f9 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 4 Mar 2024 23:43:28 +0300 Subject: [PATCH 16/27] added return type for jest mock function --- tests/perf-test/SearchPage.perf-test.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index dd376f8922e3..5ed98cacb040 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -22,22 +22,22 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; jest.mock('lodash/debounce', () => - jest.fn((fn) => { + jest.fn((fn: Record>) => { // eslint-disable-next-line no-param-reassign fn.cancel = jest.fn(); return fn; }), ); -jest.mock('../../src/libs/Log'); +jest.mock('@src/libs/Log'); -jest.mock('../../src/libs/API', () => ({ +jest.mock('@src/libs/API', () => ({ write: jest.fn(), makeRequestWithSideEffects: jest.fn(), read: jest.fn(), })); -jest.mock('../../src/libs/Navigation/Navigation'); +jest.mock('@src/libs/Navigation/Navigation'); const mockedNavigate = jest.fn(); jest.mock('@react-navigation/native', () => { @@ -57,7 +57,7 @@ jest.mock('@react-navigation/native', () => { } as typeof NativeNavigation; }); -jest.mock('../../src/components/withNavigationFocus', () => (Component: ComponentType) => { +jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType) => { function WithNavigationFocus(props: WithNavigationFocusProps) { return ( Date: Mon, 4 Mar 2024 23:49:20 +0300 Subject: [PATCH 17/27] added ts-expect-error --- tests/actions/PolicyTest.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index 9b23ea4ef2f4..4ebfa234f84f 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -21,12 +21,14 @@ describe('actions/Policy', () => { }); beforeEach(() => { - global.fetch = TestHelper.getGlobalFetchMock() as typeof fetch; + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + global.fetch = TestHelper.getGlobalFetchMock(); return Onyx.clear().then(waitForBatchedUpdates); }); describe('createWorkspace', () => { it('creates a new workspace', async () => { + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. fetch.pause(); Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID}); await waitForBatchedUpdates(); @@ -134,6 +136,7 @@ describe('actions/Policy', () => { }); // Check for success data + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. fetch.resume(); await waitForBatchedUpdates(); From 093e6749011b656f6cc033a2da70a0fd2d450061 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 4 Mar 2024 23:59:22 +0300 Subject: [PATCH 18/27] added ts-expect-error --- tests/perf-test/OptionsSelector.perf-test.tsx | 2 +- tests/perf-test/SearchPage.perf-test.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index 0a8dcc96686d..f8e5a88ed03e 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -57,7 +57,7 @@ const mutlipleSectionsConfig = [ {numItems: 1000, indexOffset: 0}, {numItems: 100, indexOffset: 70}, ]; - +// @ts-expect-error TODO: Remove this once OptionsSelector is migrated to TypeScript. function OptionsSelectorWrapper(args) { const sections = generateSections(singleSectionSConfig); return ( diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 5ed98cacb040..ebf25da0ec74 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -101,7 +101,8 @@ beforeAll(() => // Initialize the network key for OfflineWithFeedback beforeEach(() => { - global.fetch = TestHelper.getGlobalFetchMock() as typeof fetch; + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + global.fetch = TestHelper.getGlobalFetchMock(); wrapOnyxWithWaitForBatchedUpdates(Onyx); Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); }); From c79782de2842f31934077b18fd3afa9086b9fa5f Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 9 Mar 2024 11:33:19 +0300 Subject: [PATCH 19/27] fix ts issues --- tests/unit/ViolationUtilsTest.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index a6604bcc66c2..6afd2c06d46f 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -136,6 +136,7 @@ describe('getViolationsOnyxData', () => { // eslint-disable-next-line @typescript-eslint/naming-convention Dinner: {name: 'Dinner', enabled: true, 'GL Code': ''}, }, + orderWeight: 1, }, }; transaction.tag = 'Lunch'; @@ -210,9 +211,12 @@ describe('getViolationsOnyxData', () => { Accounting: { name: 'Accounting', enabled: true, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': '', }, }, required: true, + orderWeight: 1, }, Region: { name: 'Region', @@ -220,8 +224,12 @@ describe('getViolationsOnyxData', () => { Africa: { name: 'Africa', enabled: true, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': '', }, }, + required: false, + orderWeight: 1, }, Project: { name: 'Project', @@ -229,9 +237,12 @@ describe('getViolationsOnyxData', () => { Project1: { name: 'Project1', enabled: true, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': '', }, }, required: true, + orderWeight: 1, }, }; }); From 0c050cc2482af934e8dc4637e8dc2e163ca4d543 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 9 Mar 2024 11:33:57 +0300 Subject: [PATCH 20/27] remove registerStorageEventListener --- tests/perf-test/SearchPage.perf-test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index ebf25da0ec74..24a33c8ee7c6 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -95,7 +95,6 @@ beforeAll(() => Onyx.init({ keys: ONYXKEYS, safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT], - registerStorageEventListener: () => {}, }), ); From f82a45b74917d3f5977765ac6d2ceda09aaa9bd4 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 9 Mar 2024 11:40:09 +0300 Subject: [PATCH 21/27] small fix --- tests/actions/PolicyTest.ts | 10 +++++----- tests/unit/ViolationUtilsTest.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index 4ebfa234f84f..c3214bc465ac 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -2,9 +2,9 @@ import Onyx from 'react-native-onyx'; import type {OnyxCollection} from 'react-native-onyx'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; -import * as POLICY from '@src/libs/actions/Policy'; +import * as Policy from '@src/libs/actions/Policy'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, PolicyMembers, Report, ReportActions} from '@src/types/onyx'; +import type {Policy as PolicyType, PolicyMembers, Report, ReportActions} from '@src/types/onyx'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -36,12 +36,12 @@ describe('actions/Policy', () => { let adminReportID; let announceReportID; let expenseReportID; - const policyID = POLICY.generatePolicyID(); + const policyID = Policy.generatePolicyID(); - POLICY.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID); + Policy.createWorkspace(ESH_EMAIL, true, WORKSPACE_NAME, policyID); await waitForBatchedUpdates(); - let policy: OnyxCollection = await new Promise((resolve) => { + let policy: OnyxCollection = await new Promise((resolve) => { const connectionID = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, waitForCollectionCallback: true, diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 6afd2c06d46f..a4ecb3c06265 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -228,7 +228,7 @@ describe('getViolationsOnyxData', () => { 'GL Code': '', }, }, - required: false, + required: true, orderWeight: 1, }, Project: { From f5e2c6a1708edb3aecc581b21fb37abcbe017b78 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Sat, 9 Mar 2024 11:44:17 +0300 Subject: [PATCH 22/27] run prettier --- tests/actions/PolicyTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index c3214bc465ac..c5828009da96 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -4,7 +4,7 @@ import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as Policy from '@src/libs/actions/Policy'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy as PolicyType, PolicyMembers, Report, ReportActions} from '@src/types/onyx'; +import type {PolicyMembers, Policy as PolicyType, Report, ReportActions} from '@src/types/onyx'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; From 8deff4303e5dd7dfe5a2ee58c085fae453591104 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire <39636266+HezekielT@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:15:02 +0300 Subject: [PATCH 23/27] Update tests/perf-test/SearchPage.perf-test.tsx Co-authored-by: Carlos Alvarez --- tests/perf-test/SearchPage.perf-test.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 24a33c8ee7c6..c99fc97abb6a 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -114,11 +114,8 @@ afterEach(() => { type SearchPageProps = { betas?: string[]; - reports?: Report; - isSearchingForReports?: boolean; - navigation: Record; }; From b914a43b804f7a34ad4a24a3a32fe98cf9b7594a Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Fri, 15 Mar 2024 13:11:01 +0300 Subject: [PATCH 24/27] code changes based on review --- src/types/onyx/PolicyCategory.ts | 2 +- src/types/onyx/PolicyTag.ts | 2 +- tests/actions/PolicyTest.ts | 14 ++++++++----- tests/perf-test/OptionsSelector.perf-test.tsx | 21 +++++++++---------- tests/perf-test/SearchPage.perf-test.tsx | 2 +- tests/unit/ViolationUtilsTest.ts | 19 +++++------------ 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/types/onyx/PolicyCategory.ts b/src/types/onyx/PolicyCategory.ts index 5cef49afc9d4..bcbd9279041c 100644 --- a/src/types/onyx/PolicyCategory.ts +++ b/src/types/onyx/PolicyCategory.ts @@ -12,7 +12,7 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** "General Ledger code" that corresponds to this category in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': string; + 'GL Code'?: string; /** An ID for this category from an external accounting system */ externalID: string; diff --git a/src/types/onyx/PolicyTag.ts b/src/types/onyx/PolicyTag.ts index fe7b61cc8f9c..493bfc4ddd3b 100644 --- a/src/types/onyx/PolicyTag.ts +++ b/src/types/onyx/PolicyTag.ts @@ -7,7 +7,7 @@ type PolicyTag = { /** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */ // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': string; + 'GL Code'?: string; }; type PolicyTags = Record; diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index c5828009da96..c9c087ebb7ad 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -4,7 +4,7 @@ import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as Policy from '@src/libs/actions/Policy'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PolicyMembers, Policy as PolicyType, Report, ReportActions} from '@src/types/onyx'; +import type {PolicyMembers, Policy as PolicyType, Report, ReportAction, ReportActions} from '@src/types/onyx'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -122,10 +122,10 @@ describe('actions/Policy', () => { }); // Each of the three reports should have a a `CREATED` action. - let adminReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`] ?? {}); - let announceReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`] ?? {}); - let expenseReportActions = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`] ?? {}); - let workspaceReportActions = adminReportActions.concat(announceReportActions, expenseReportActions); + let adminReportActions: ReportAction[] = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminReportID}`] ?? {}); + let announceReportActions: ReportAction[] = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${announceReportID}`] ?? {}); + let expenseReportActions: ReportAction[] = Object.values(reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReportID}`] ?? {}); + let workspaceReportActions: ReportAction[] = adminReportActions.concat(announceReportActions, expenseReportActions); [adminReportActions, announceReportActions, expenseReportActions].forEach((actions) => { expect(actions.length).toBe(1); }); @@ -167,6 +167,10 @@ describe('actions/Policy', () => { // Check if the report pending action and fields were cleared Object.values(allReports ?? {}).forEach((report) => { + if (typeof report === 'undefined') { + return; + } + expect(report?.pendingAction).toBeFalsy(); expect(report?.pendingFields?.addWorkspaceRoom).toBeFalsy(); }); diff --git a/tests/perf-test/OptionsSelector.perf-test.tsx b/tests/perf-test/OptionsSelector.perf-test.tsx index f8e5a88ed03e..835e2a15673c 100644 --- a/tests/perf-test/OptionsSelector.perf-test.tsx +++ b/tests/perf-test/OptionsSelector.perf-test.tsx @@ -38,12 +38,11 @@ jest.mock('@src/components/withNavigationFocus', () => (Component: ComponentType return WithNavigationFocus; }); -type GenerateSectionsProps = Array<{numItems: number; indexOffset: number; shouldShow?: boolean}>; +type GenerateSectionsProps = Array<{numberOfItems: number; indexOffset: number; shouldShow?: boolean}>; -const generateSections = (sectionConfigs: GenerateSectionsProps) => - sectionConfigs.map(({numItems, indexOffset, shouldShow = true}) => ({ - // eslint-disable-next-line @typescript-eslint/naming-convention - data: Array.from({length: numItems}, (_v, i) => ({ +const generateSections = (sections: GenerateSectionsProps) => + sections.map(({numberOfItems, indexOffset, shouldShow = true}) => ({ + data: Array.from({length: numberOfItems}, (v, i) => ({ text: `Item ${i + indexOffset}`, keyForList: `item-${i + indexOffset}`, })), @@ -51,15 +50,15 @@ const generateSections = (sectionConfigs: GenerateSectionsProps) => shouldShow, })); -const singleSectionSConfig = [{numItems: 1000, indexOffset: 0}]; +const singleSectionsConfig = [{numberOfItems: 1000, indexOffset: 0}]; const mutlipleSectionsConfig = [ - {numItems: 1000, indexOffset: 0}, - {numItems: 100, indexOffset: 70}, + {numberOfItems: 1000, indexOffset: 0}, + {numberOfItems: 100, indexOffset: 70}, ]; // @ts-expect-error TODO: Remove this once OptionsSelector is migrated to TypeScript. function OptionsSelectorWrapper(args) { - const sections = generateSections(singleSectionSConfig); + const sections = generateSections(singleSectionsConfig); return ( { test('[OptionsSelector] should scroll and press few items', () => { const sections = generateSections(mutlipleSectionsConfig); - const generateEventData = (numOptions: number, optionRowHeight: number) => ({ + const generateEventData = (numberOfOptions: number, optionRowHeight: number) => ({ nativeEvent: { contentOffset: { - y: optionRowHeight * numOptions, + y: optionRowHeight * numberOfOptions, }, contentSize: { height: optionRowHeight * 10, diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index c99fc97abb6a..605d7fa71d92 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -136,7 +136,7 @@ type CreateAddListenerMock = { addListener?: () => Record; }; -test.skip('[Search Page] should interact when text input changes', async () => { +test('[Search Page] should interact when text input changes', async () => { const {addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); const scenario = async () => { diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index a4ecb3c06265..8c28896b0037 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -63,8 +63,7 @@ describe('getViolationsOnyxData', () => { describe('policyRequiresCategories', () => { beforeEach(() => { policyRequiresCategories = true; - // eslint-disable-next-line @typescript-eslint/naming-convention - policyCategories = {Food: {name: 'Food', enabled: true, areCommentsRequired: false, 'GL Code': '1234', externalID: '1234', origin: '12345'}}; + policyCategories = {Food: {name: 'Food', enabled: true, areCommentsRequired: false, externalID: '1234', origin: '12345'}}; transaction.category = 'Food'; }); @@ -131,10 +130,8 @@ describe('getViolationsOnyxData', () => { name: 'Meals', required: true, tags: { - // eslint-disable-next-line @typescript-eslint/naming-convention - Lunch: {name: 'Lunch', enabled: true, 'GL Code': ''}, - // eslint-disable-next-line @typescript-eslint/naming-convention - Dinner: {name: 'Dinner', enabled: true, 'GL Code': ''}, + Lunch: {name: 'Lunch', enabled: true}, + Dinner: {name: 'Dinner', enabled: true}, }, orderWeight: 1, }, @@ -211,8 +208,6 @@ describe('getViolationsOnyxData', () => { Accounting: { name: 'Accounting', enabled: true, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': '', }, }, required: true, @@ -224,12 +219,10 @@ describe('getViolationsOnyxData', () => { Africa: { name: 'Africa', enabled: true, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': '', }, }, required: true, - orderWeight: 1, + orderWeight: 2, }, Project: { name: 'Project', @@ -237,12 +230,10 @@ describe('getViolationsOnyxData', () => { Project1: { name: 'Project1', enabled: true, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': '', }, }, required: true, - orderWeight: 1, + orderWeight: 3, }, }; }); From d2c5348a9767d78cf9c2bf71a3e05297789a86cf Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Fri, 15 Mar 2024 15:14:32 +0300 Subject: [PATCH 25/27] fix ts error --- tests/perf-test/SearchPage.perf-test.tsx | 115 +++++++++++++---------- tests/unit/ViolationUtilsTest.ts | 2 +- 2 files changed, 65 insertions(+), 52 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 605d7fa71d92..593bc2ee3370 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -1,4 +1,5 @@ import type * as NativeNavigation from '@react-navigation/native'; +import type {StackScreenProps} from '@react-navigation/stack'; import {fireEvent, screen, waitFor} from '@testing-library/react-native'; import type {TextMatch} from '@testing-library/react-native/build/matches'; import React from 'react'; @@ -7,11 +8,13 @@ import Onyx from 'react-native-onyx'; import {measurePerformance} from 'reassure'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; +import type {RootStackParamList} from '@libs/Navigation/types'; import SearchPage from '@pages/SearchPage'; import ComposeProviders from '@src/components/ComposeProviders'; import OnyxProvider from '@src/components/OnyxProvider'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type SCREENS from '@src/SCREENS'; import type {PersonalDetails, Report} from '@src/types/onyx'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; @@ -112,11 +115,10 @@ afterEach(() => { PusherHelper.teardown(); }); -type SearchPageProps = { +type SearchPageProps = StackScreenProps & { betas?: string[]; reports?: Report; isSearchingForReports?: boolean; - navigation: Record; }; function SearchPageWrapper(args: SearchPageProps) { @@ -131,13 +133,9 @@ function SearchPageWrapper(args: SearchPageProps) { ); } -type CreateAddListenerMock = { - triggerTransitionEnd?: () => void; - addListener?: () => Record; -}; - test('[Search Page] should interact when text input changes', async () => { - const {addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + const {addListener} = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); @@ -150,20 +148,24 @@ test('[Search Page] should interact when text input changes', async () => { const navigation = {addListener}; - return waitForBatchedUpdates() - .then(() => - Onyx.multiSet({ - ...mockedReports, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, - [ONYXKEYS.BETAS]: mockedBetas, - [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, - }), - ) - .then(() => measurePerformance(, {scenario})); + return ( + waitForBatchedUpdates() + .then(() => + Onyx.multiSet({ + ...mockedReports, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, + [ONYXKEYS.BETAS]: mockedBetas, + [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, + }), + ) + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + .then(() => measurePerformance(, {scenario})) + ); }); test('[Search Page] should render selection list', async () => { - const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); const smallMockedPersonalDetails = getMockedPersonalDetails(5); const scenario = async () => { @@ -176,20 +178,24 @@ test('[Search Page] should render selection list', async () => { const navigation = {addListener}; - return waitForBatchedUpdates() - .then(() => - Onyx.multiSet({ - ...mockedReports, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: smallMockedPersonalDetails, - [ONYXKEYS.BETAS]: mockedBetas, - [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, - }), - ) - .then(() => measurePerformance(, {scenario})); + return ( + waitForBatchedUpdates() + .then(() => + Onyx.multiSet({ + ...mockedReports, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: smallMockedPersonalDetails, + [ONYXKEYS.BETAS]: mockedBetas, + [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, + }), + ) + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + .then(() => measurePerformance(, {scenario})) + ); }); test('[Search Page] should search in selection list', async () => { - const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); @@ -204,20 +210,24 @@ test('[Search Page] should search in selection list', async () => { const navigation = {addListener}; - return waitForBatchedUpdates() - .then(() => - Onyx.multiSet({ - ...mockedReports, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, - [ONYXKEYS.BETAS]: mockedBetas, - [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, - }), - ) - .then(() => measurePerformance(, {scenario})); + return ( + waitForBatchedUpdates() + .then(() => + Onyx.multiSet({ + ...mockedReports, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, + [ONYXKEYS.BETAS]: mockedBetas, + [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, + }), + ) + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + .then(() => measurePerformance(, {scenario})) + ); }); test('[Search Page] should click on list item', async () => { - const {triggerTransitionEnd, addListener}: CreateAddListenerMock = TestHelper.createAddListenerMock(); + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); const scenario = async () => { await screen.findByTestId('SearchPage'); @@ -232,14 +242,17 @@ test('[Search Page] should click on list item', async () => { }; const navigation = {addListener}; - return waitForBatchedUpdates() - .then(() => - Onyx.multiSet({ - ...mockedReports, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, - [ONYXKEYS.BETAS]: mockedBetas, - [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, - }), - ) - .then(() => measurePerformance(, {scenario})); + return ( + waitForBatchedUpdates() + .then(() => + Onyx.multiSet({ + ...mockedReports, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, + [ONYXKEYS.BETAS]: mockedBetas, + [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, + }), + ) + // @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript. + .then(() => measurePerformance(, {scenario})) + ); }); diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 8c28896b0037..354a90802077 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -63,7 +63,7 @@ describe('getViolationsOnyxData', () => { describe('policyRequiresCategories', () => { beforeEach(() => { policyRequiresCategories = true; - policyCategories = {Food: {name: 'Food', enabled: true, areCommentsRequired: false, externalID: '1234', origin: '12345'}}; + policyCategories = {Food: {name: 'Food', unencodedName: '', enabled: true, areCommentsRequired: false, externalID: '1234', origin: '12345'}}; transaction.category = 'Food'; }); From 599adad1df84ce46a0e1c7ca2aa85433db86c5ef Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Fri, 15 Mar 2024 18:42:46 +0300 Subject: [PATCH 26/27] updated SearchPage props --- tests/perf-test/SearchPage.perf-test.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/SearchPage.perf-test.tsx b/tests/perf-test/SearchPage.perf-test.tsx index 593bc2ee3370..3f3395092b26 100644 --- a/tests/perf-test/SearchPage.perf-test.tsx +++ b/tests/perf-test/SearchPage.perf-test.tsx @@ -5,6 +5,7 @@ import type {TextMatch} from '@testing-library/react-native/build/matches'; import React from 'react'; import type {ComponentType} from 'react'; import Onyx from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {measurePerformance} from 'reassure'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; import type {WithNavigationFocusProps} from '@components/withNavigationFocus'; @@ -15,7 +16,7 @@ import OnyxProvider from '@src/components/OnyxProvider'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; -import type {PersonalDetails, Report} from '@src/types/onyx'; +import type {Beta, PersonalDetails, Report} from '@src/types/onyx'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomReport from '../utils/collections/reports'; @@ -116,9 +117,9 @@ afterEach(() => { }); type SearchPageProps = StackScreenProps & { - betas?: string[]; - reports?: Report; - isSearchingForReports?: boolean; + betas: OnyxEntry; + reports: OnyxCollection; + isSearchingForReports: OnyxEntry; }; function SearchPageWrapper(args: SearchPageProps) { From aaad266fa2e8c9c8ada936fba3db99a38df6cd81 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire <39636266+HezekielT@users.noreply.github.com> Date: Fri, 15 Mar 2024 19:32:05 +0300 Subject: [PATCH 27/27] remove unwanted check Co-authored-by: Carlos Alvarez --- tests/actions/PolicyTest.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index c9c087ebb7ad..e59fec068d65 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -167,10 +167,6 @@ describe('actions/Policy', () => { // Check if the report pending action and fields were cleared Object.values(allReports ?? {}).forEach((report) => { - if (typeof report === 'undefined') { - return; - } - expect(report?.pendingAction).toBeFalsy(); expect(report?.pendingFields?.addWorkspaceRoom).toBeFalsy(); });