diff --git a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx index af57dbfa37d7..cda98dcec932 100644 --- a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx +++ b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx @@ -156,8 +156,9 @@ function TransactionPreviewContent({ currentUserEmail, currentUserAccountID, originalTransaction, + convertToDisplayString, }), - [transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction], + [transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction, convertToDisplayString], ); const getTranslatedText = (item: TranslationPathOrText) => (item.translationPath ? translate(item.translationPath) : (item.text ?? '')); diff --git a/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx b/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx index 639fb50539d7..79fc9bd20ee5 100644 --- a/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx @@ -14,6 +14,7 @@ import type {SearchGroupBy} from '@components/Search/types'; import type {ListItem} from '@components/SelectionList/types'; import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs'; import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -94,6 +95,7 @@ function TransactionGroupListItem({ const {isLargeScreenWidth} = useResponsiveLayout(); const currentUserDetails = useCurrentUserPersonalDetails(); const isScreenFocused = useIsFocused(); + const {convertToDisplayString} = useCurrencyListActions(); const oneTransactionItem = groupItem.isOneTransactionReport ? groupItem.transactions.at(0) : undefined; const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`); @@ -141,6 +143,7 @@ function TransactionGroupListItem({ allReportMetadata, cardFeeds, conciergeReportID, + convertToDisplayString, }) as [TransactionListItemType[], number, boolean]; transactions = sectionData.map((transactionItem) => ({ ...transactionItem, diff --git a/src/components/Search/SearchStaticList.tsx b/src/components/Search/SearchStaticList.tsx index 76bde43edb59..31f55779d711 100644 --- a/src/components/Search/SearchStaticList.tsx +++ b/src/components/Search/SearchStaticList.tsx @@ -22,6 +22,7 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import StatusBadge from '@components/StatusBadge'; import TransactionItemRow from '@components/TransactionItemRow'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useLocalize from '@hooks/useLocalize'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; @@ -69,6 +70,7 @@ function SearchStaticList({ const theme = useTheme(); const StyleUtils = useStyleUtils(); const {translate, localeCompare, formatPhoneNumber} = useLocalize(); + const {convertToDisplayString} = useCurrencyListActions(); const session = useSession(); const accountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID; const email = session?.email; @@ -96,6 +98,7 @@ function SearchStaticList({ bankAccountList: undefined, allReportMetadata: undefined, conciergeReportID: undefined, + convertToDisplayString, }); return getSortedSections(type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index fda2ec413e7a..14dee3c1f1a6 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -12,6 +12,7 @@ import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; import {useWideRHPActions} from '@components/WideRHPContextProvider'; import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs'; import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useMultipleSnapshots from '@hooks/useMultipleSnapshots'; @@ -352,6 +353,8 @@ function Search({ selector: savedSearchSelector, }); + const {convertToDisplayString} = useCurrencyListActions(); + const validGroupBy = getValidGroupBy(groupBy); const prevValidGroupBy = usePrevious(validGroupBy); const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults, validGroupBy); @@ -544,6 +547,7 @@ function Search({ conciergeReportID, onyxPersonalDetailsList, policyForMovingExpenses, + convertToDisplayString, }); return { baseFilteredData: filteredData1, @@ -576,6 +580,7 @@ function Search({ conciergeReportID, onyxPersonalDetailsList, policyForMovingExpenses, + convertToDisplayString, ]); // For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot @@ -612,6 +617,7 @@ function Search({ cardFeeds, allReportMetadata, conciergeReportID, + convertToDisplayString, }); return { ...item, @@ -635,6 +641,7 @@ function Search({ bankAccountList, allReportMetadata, conciergeReportID, + convertToDisplayString, ]); const hasLoadedAllTransactions = useMemo(() => { diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 43cc5d5d1d46..8d1dc4d426aa 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -287,7 +287,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { 'Workflows', ]); - const {getCurrencyDecimals} = useCurrencyListActions(); + const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions(); const selectedTransactionReportIDs = useMemo( () => [ @@ -315,7 +315,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { [selectedTransactions], ); const selectedBulkCurrency = selectedReports.at(0)?.currency ?? Object.values(selectedTransactions).at(0)?.currency; - const totalFormattedAmount = getTotalFormattedAmount(selectedReports, selectedTransactions, selectedBulkCurrency); + const totalFormattedAmount = getTotalFormattedAmount(convertToDisplayString, selectedReports, selectedTransactions, selectedBulkCurrency); const onlyShowPayElsewhere = useMemo(() => { const firstPolicyID = selectedPolicyIDs.at(0); diff --git a/src/hooks/useSearchSections.ts b/src/hooks/useSearchSections.ts index b7fa54da3460..a6003dd890a4 100644 --- a/src/hooks/useSearchSections.ts +++ b/src/hooks/useSearchSections.ts @@ -7,6 +7,7 @@ import type {Report} from '@src/types/onyx'; import type LastSearchParams from '@src/types/onyx/ReportNavigation'; import useActionLoadingReportIDs from './useActionLoadingReportIDs'; import useArchivedReportsIdSet from './useArchivedReportsIdSet'; +import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; @@ -39,6 +40,7 @@ function useSearchSections(): UseSearchSectionsResult { const currentUserDetails = useCurrentUserPersonalDetails(); const {localeCompare, formatPhoneNumber, translate} = useLocalize(); const isActionLoadingSet = useActionLoadingReportIDs(); + const {convertToDisplayString} = useCurrencyListActions(); const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { selector: selectFilteredReportActions, @@ -76,6 +78,7 @@ function useSearchSections(): UseSearchSectionsResult { cardFeeds, allReportMetadata, conciergeReportID, + convertToDisplayString, }); results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID); } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index bdf78a8ef060..9b917fd07957 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -99,7 +99,7 @@ import type {CardFeedForDisplay} from './CardFeedUtils'; import {getCardFeedsForDisplay} from './CardFeedUtils'; import {getCardDescriptionForSearchTable, getFeedNameForDisplay} from './CardUtils'; import {getDecodedCategoryName} from './CategoryUtils'; -import {convertToDisplayString, convertToDisplayStringWithoutCurrency} from './CurrencyUtils'; +import {convertToDisplayStringWithoutCurrency} from './CurrencyUtils'; import DateUtils from './DateUtils'; import interceptAnonymousUser from './interceptAnonymousUser'; import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute'; @@ -239,6 +239,7 @@ type GetReportSectionsParams = { currentUserEmail: string; translate: LocalizedTranslate; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString']; isActionLoadingSet: ReadonlySet | undefined; isOffline: boolean | undefined; allTransactionViolations: OnyxCollection; @@ -570,6 +571,7 @@ type GetSectionsParams = { translate: LocalizedTranslate; formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; bankAccountList: OnyxEntry; + convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString']; groupBy?: SearchGroupBy; reportActions?: Record; currentSearch?: SearchKey; @@ -1565,7 +1567,12 @@ function shouldShowYear( * @private * Generates a display name for IOU reports considering the personal details of the payer and the transaction details. */ -function getIOUReportName(translate: LocalizedTranslate, data: OnyxTypes.SearchResults['data'], reportItem: TransactionReportGroupListItemType) { +function getIOUReportName( + translate: LocalizedTranslate, + convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'], + data: OnyxTypes.SearchResults['data'], + reportItem: TransactionReportGroupListItemType, +) { const payerPersonalDetails = reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails; // For cases where the data personal detail for manager ID do not exist in search data.personalDetailsList // we fallback to the display name of the personal detail data from onyx. @@ -2606,6 +2613,7 @@ function getReportSections({ allReportMetadata, queryJSON, onyxPersonalDetailsList, + convertToDisplayString, }: GetReportSectionsParams): [TransactionGroupListItemType[], number, boolean] { const { transactionKeys, @@ -2740,7 +2748,7 @@ function getReportSections({ }; if (isIOUReport) { - reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, data, reportIDToTransactions[reportKey]); + reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, convertToDisplayString, data, reportIDToTransactions[reportKey]); } } } else if (isTransactionEntry(key)) { @@ -3391,6 +3399,7 @@ function getSections({ conciergeReportID, onyxPersonalDetailsList, policyForMovingExpenses, + convertToDisplayString, }: GetSectionsParams): GetSectionsResult { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { return [...getReportActionsSections(data, visibleReportActionsData), false]; @@ -3416,6 +3425,7 @@ function getSections({ allReportMetadata, queryJSON, onyxPersonalDetailsList, + convertToDisplayString, }); } diff --git a/src/libs/TransactionPreviewUtils.ts b/src/libs/TransactionPreviewUtils.ts index 2f8da3aa0ebb..4a1a6b217639 100644 --- a/src/libs/TransactionPreviewUtils.ts +++ b/src/libs/TransactionPreviewUtils.ts @@ -1,5 +1,6 @@ import truncate from 'lodash/truncate'; import type {OnyxEntry} from 'react-native-onyx'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; @@ -7,7 +8,6 @@ import type * as OnyxTypes from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {setReviewDuplicatesKey} from './actions/Transaction'; import {isCategoryMissing} from './CategoryUtils'; -import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; import {hasDynamicExternalWorkflow} from './PolicyUtils'; import {getMostRecentActiveDEWSubmitFailedAction, getOriginalMessage, isDynamicExternalWorkflowSubmitFailedAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils'; @@ -211,6 +211,7 @@ function getTransactionPreviewTextAndTranslationPaths({ currentUserEmail, currentUserAccountID, originalTransaction, + convertToDisplayString, }: { iouReport: OnyxEntry; policy: OnyxEntry; @@ -225,6 +226,7 @@ function getTransactionPreviewTextAndTranslationPaths({ currentUserEmail: string; currentUserAccountID: number; originalTransaction?: OnyxEntry; + convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString']; }) { const isFetchingWaypoints = isFetchingWaypointsFromServer(transaction); const isTransactionOnHold = isOnHold(transaction); diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 6bddb52fa82a..6997a0463281 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -8,6 +8,7 @@ import type {LocalizedTranslate} from '@components/LocaleContextProvider'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/Search/SearchList/ListItem/types'; import type {BankAccountMenuItem, BulkPaySelectionData, PaymentData, SearchQueryJSON, SelectedReports, SelectedTransactionInfo, SelectedTransactions} from '@components/Search/types'; +import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; import * as API from '@libs/API'; import {waitForWrites} from '@libs/API'; import type { @@ -20,7 +21,6 @@ import type { } from '@libs/API/parameters'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import {getCommandURL} from '@libs/ApiUtils'; -import {convertToDisplayString} from '@libs/CurrencyUtils'; import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils'; import fileDownload from '@libs/fileDownload'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; @@ -1458,7 +1458,12 @@ function getPayMoneyOnSearchInvoiceParams(policyID: string | undefined, payAsBus /** * Return the total amount of selected transactions/reports. */ -function getTotalFormattedAmount(selectedReports: SelectedReports[], selectedTransactions: SelectedTransactions, currency?: string): string { +function getTotalFormattedAmount( + convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'], + selectedReports: SelectedReports[], + selectedTransactions: SelectedTransactions, + currency?: string, +): string { const transactionKeys = Object.keys(selectedTransactions ?? {}); const totalAmount = selectedReports.length > 0 diff --git a/src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts b/src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts index f4ecf14fec96..3c733fc87327 100644 --- a/src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts +++ b/src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts @@ -3,6 +3,7 @@ import {useEffect, useEffectEvent} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {GroupedItem, SearchQueryJSON} from '@components/Search/types'; +import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; @@ -52,6 +53,7 @@ function useSpendOverTimeData() { const {groupBy, view} = queryJSON ?? {}; const {translate, localeCompare, formatPhoneNumber} = useLocalize(); + const {convertToDisplayString} = useCurrencyListActions(); const {accountID, login} = useCurrentUserPersonalDetails(); const [searchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSON?.hash}`); const isSearchLoading = !!searchResults?.search?.isLoading; @@ -98,6 +100,7 @@ function useSpendOverTimeData() { bankAccountList: undefined, allReportMetadata: undefined, conciergeReportID: undefined, + convertToDisplayString, })[0], localeCompare, translate, diff --git a/tests/ui/MoneyRequestReportPreview.test.tsx b/tests/ui/MoneyRequestReportPreview.test.tsx index 90ea067d3af3..fefef5aca7f2 100644 --- a/tests/ui/MoneyRequestReportPreview.test.tsx +++ b/tests/ui/MoneyRequestReportPreview.test.tsx @@ -4,6 +4,7 @@ import {act, fireEvent, render, screen} from '@testing-library/react-native'; import type {OnyxCollection, OnyxEntry, OnyxMergeInput} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import ComposeProviders from '@components/ComposeProviders'; +import {CurrencyListContextProvider} from '@components/CurrencyListContextProvider'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; import OnyxListItemProvider from '@components/OnyxListItemProvider'; import OptionsListContextProvider from '@components/OptionListContextProvider'; @@ -81,7 +82,7 @@ const hasViolations = ( const renderPage = ({isWhisper = false, isHovered = false, contextMenuAnchor = null}: Partial) => { return render( - + diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 33f7ae43d3d2..39ca0186075c 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -24,6 +24,7 @@ import type { TransactionYearGroupListItemType, } from '@components/Search/SearchList/ListItem/types'; import type {SelectedTransactionInfo} from '@components/Search/types'; +import {convertToDisplayString} from '@libs/CurrencyUtils'; import Navigation from '@navigation/Navigation'; import type * as ReportUserActions from '@userActions/Report'; import {createTransactionThreadReport} from '@userActions/Report'; @@ -2499,6 +2500,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }); expect(filteredReportActions).toStrictEqual(reportActionListItems); expect(allReportActionsLength).toBe(6); @@ -2516,6 +2518,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toEqual(transactionsListItems); }); @@ -2544,6 +2547,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0] as TransactionListItemType[]; const distanceTransaction = result.find((item) => item.transactionID === distanceTransactionID); @@ -2579,6 +2583,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0] as TransactionGroupListItemType[]; const reportGroup = result.find((group) => group.transactions?.some((transaction) => transaction.transactionID === distanceTransactionID)); @@ -2608,6 +2613,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionReportGroupListItems); }); @@ -2634,6 +2640,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0] as TransactionReportGroupListItemType[]; expect(result.find((item) => item.reportID === reportID2)?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); @@ -2671,6 +2678,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; expect(resultWithoutOnyx.at(0)?.primaryAvatar?.source).not.toBe(customAvatarUrl); @@ -2687,6 +2695,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, onyxPersonalDetailsList, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; expect(resultWithOnyx.at(0)?.primaryAvatar?.source).toBe(customAvatarUrl); @@ -2727,6 +2736,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, onyxPersonalDetailsList, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; expect(result?.at(0)?.primaryAvatar?.source).toBe(apiAvatarUrl); @@ -2769,6 +2779,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; const reportWithoutOnyx = resultWithoutOnyx.find((item) => item.reportID === reportID2); @@ -2785,6 +2796,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, onyxPersonalDetailsList, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; const reportWithOnyx = resultWithOnyx.find((item) => item.reportID === reportID2); @@ -2818,6 +2830,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; const reportGroupWithoutOnyx = resultWithoutOnyx.find((item) => item.reportID === reportID); @@ -2835,6 +2848,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, onyxPersonalDetailsList, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; const reportGroupWithOnyx = resultWithOnyx.find((item) => item.reportID === reportID); @@ -2876,6 +2890,7 @@ describe('SearchUIUtils', () => { conciergeReportID: undefined, allReportMetadata: {}, onyxPersonalDetailsList, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; const reportGroup = result.find((item) => item.reportID === reportID); @@ -2922,6 +2937,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0]; const resultReportFirst = SearchUIUtils.getSections({ type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT, @@ -2933,6 +2949,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0]; expect(resultTransactionFirst).toBeDefined(); @@ -2958,6 +2975,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.FROM, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionMemberGroupListItems); }); @@ -2986,6 +3004,7 @@ describe('SearchUIUtils', () => { cardFeeds: mockCardFeeds, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionCardGroupListItems); }); @@ -3003,6 +3022,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionWithdrawalIDGroupListItems); }); @@ -3029,6 +3049,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionWithdrawalIDGroupListItemType[], number, boolean]; expect(result).toHaveLength(0); @@ -3047,6 +3068,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionCategoryGroupListItems); }); @@ -3079,6 +3101,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3144,6 +3167,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MONTH, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionMonthGroupListItems); }); @@ -3178,6 +3202,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MONTH, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMonthGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3197,6 +3222,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MONTH, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMonthGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3278,6 +3304,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.YEAR, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionYearGroupListItems); }); @@ -3310,6 +3337,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.YEAR, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionYearGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3329,6 +3357,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.YEAR, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionYearGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3710,6 +3739,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.QUARTER, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionQuarterGroupListItems); }); @@ -3744,6 +3774,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.QUARTER, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionQuarterGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3763,6 +3794,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.QUARTER, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionQuarterGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3825,6 +3857,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.WEEK, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionWeekGroupListItems); }); @@ -3857,6 +3890,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.WEEK, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionWeekGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -3913,6 +3947,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; // Each category section should have a transactionsQueryJSON with a hash @@ -3957,6 +3992,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; expect(result).toHaveLength(3); @@ -3999,6 +4035,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; expect(result).toHaveLength(3); @@ -4030,6 +4067,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4066,6 +4104,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.CATEGORY, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionCategoryGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -4091,6 +4130,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MERCHANT, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionMerchantGroupListItems); }); @@ -4124,6 +4164,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MERCHANT, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -4171,6 +4212,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4220,6 +4262,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4269,6 +4312,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4318,6 +4362,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4388,6 +4433,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; // Each merchant section should have a transactionsQueryJSON with a hash @@ -4433,6 +4479,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MERCHANT, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(3); @@ -4476,6 +4523,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.MERCHANT, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionMerchantGroupListItemType[], number, boolean]; expect(result).toHaveLength(3); @@ -4498,6 +4546,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.TAG, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0], ).toStrictEqual(transactionTagGroupListItems); }); @@ -4526,6 +4575,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.TAG, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionTagGroupListItemType[], number, boolean]; // formattedTag should have unescaped colons for display @@ -4562,6 +4612,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.TAG, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionTagGroupListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -4591,6 +4642,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.TAG, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionTagGroupListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4658,6 +4710,7 @@ describe('SearchUIUtils', () => { }, }, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionTagGroupListItemType[], number, boolean]; // Each tag section should have a transactionsQueryJSON with a hash @@ -4715,6 +4768,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: '999', + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4741,6 +4795,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: '999', + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; expect(result).toHaveLength(0); @@ -4808,6 +4863,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: '999', + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; expect(result).toHaveLength(2); @@ -4862,6 +4918,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: '999', + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -4915,6 +4972,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: '999', + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; // Only the task report should be included @@ -4970,6 +5028,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TaskListItemType[], number, boolean]; expect(result).toHaveLength(1); @@ -5019,6 +5078,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0] as TransactionReportGroupListItemType[]; const item = sections.find((s) => s.keyForList === testReportID); @@ -5133,6 +5193,7 @@ describe('SearchUIUtils', () => { bankAccountList: {}, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, })[0] as TransactionReportGroupListItemType[]; const item = sections.find((s) => s.keyForList === avatarTestReportID); @@ -5259,6 +5320,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, ...options, + convertToDisplayString, }) as [TransactionListItemType[], number, boolean]; } @@ -5517,6 +5579,7 @@ describe('SearchUIUtils', () => { allReportMetadata: {}, conciergeReportID: undefined, ...options, + convertToDisplayString, }) as [TransactionReportGroupListItemType[], number, boolean]; } @@ -6177,6 +6240,7 @@ describe('SearchUIUtils', () => { groupBy: CONST.SEARCH.GROUP_BY.TAG, allReportMetadata: {}, conciergeReportID: undefined, + convertToDisplayString, }) as [TransactionTagGroupListItemType[], number, boolean]; // Then sort the sections diff --git a/tests/unit/TransactionPreviewUtils.test.ts b/tests/unit/TransactionPreviewUtils.test.ts index 77e436dd5057..6e1d0f224c02 100644 --- a/tests/unit/TransactionPreviewUtils.test.ts +++ b/tests/unit/TransactionPreviewUtils.test.ts @@ -1,5 +1,5 @@ import Onyx from 'react-native-onyx'; -import {convertAmountToDisplayString} from '@libs/CurrencyUtils'; +import {convertAmountToDisplayString, convertToDisplayString} from '@libs/CurrencyUtils'; import {buildOptimisticIOUReport, buildOptimisticIOUReportAction} from '@libs/ReportUtils'; import { createTransactionPreviewConditionals, @@ -49,6 +49,7 @@ const basicProps = { currentUserEmail: '', currentUserAccountID: CONST.DEFAULT_NUMBER_ID, reportViolations: undefined, + convertToDisplayString, }; describe('TransactionPreviewUtils', () => {