From 495eeb5845f2c40e38f4fb95285c53fb4380a144 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 20 Aug 2025 22:01:03 +0700 Subject: [PATCH 1/2] fix approve button is not shown when there are violations --- src/components/Search/SearchContext.tsx | 16 ++++++- src/components/Search/types.ts | 1 + src/libs/SearchUIUtils.ts | 54 ++++++++++++---------- src/pages/Search/SearchPage.tsx | 6 ++- src/types/onyx/SearchResults.ts | 10 ++++- tests/unit/Search/SearchUIUtilsTest.ts | 59 ++++++++++++++++--------- 6 files changed, 95 insertions(+), 51 deletions(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 271a2644f20f..8c9f5616c13b 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -78,11 +78,23 @@ function SearchContextProvider({children}: ChildrenProps) { if (data.length && data.every(isTransactionReportGroupListItemType)) { selectedReports = data .filter((item) => isMoneyRequestReport(item) && item.transactions.length > 0 && item.transactions.every(({keyForList}) => selectedTransactions[keyForList]?.isSelected)) - .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, total = CONST.DEFAULT_NUMBER_ID, policyID}) => ({reportID, action, total, policyID})); + .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, total = CONST.DEFAULT_NUMBER_ID, policyID, allActions = [action]}) => ({ + reportID, + action, + total, + policyID, + allActions, + })); } else if (data.length && data.every(isTransactionListItemType)) { selectedReports = data .filter(({keyForList}) => !!keyForList && selectedTransactions[keyForList]?.isSelected) - .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, amount: total = CONST.DEFAULT_NUMBER_ID, policyID}) => ({reportID, action, total, policyID})); + .map(({reportID, action = CONST.SEARCH.ACTION_TYPES.VIEW, amount: total = CONST.DEFAULT_NUMBER_ID, policyID, allActions = [action]}) => ({ + reportID, + action, + total, + policyID, + allActions, + })); } setSearchContextData((prevState) => ({ diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index 2b1f2348c941..370897cc9bc4 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -45,6 +45,7 @@ type SelectedReports = { reportID: string; policyID: string | undefined; action: ValueOf; + allActions: Array>; total: number; }; diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index d7c651300026..041c33dbac9c 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -884,8 +884,10 @@ function getTransactionsSections( const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy, formatPhoneNumber); + const allActions = getActions(data, allViolations, key, currentSearch, currentAccountID); const transactionSection: TransactionListItemType = { - action: getAction(data, allViolations, key, currentSearch, currentAccountID), + action: allActions.at(0) ?? CONST.SEARCH.ACTION_TYPES.VIEW, + allActions, report, from, to, @@ -1024,52 +1026,53 @@ function getReviewerPermissionFlags( * * Do not use directly, use only via `getSections()` facade. */ -function getAction( +function getActions( data: OnyxTypes.SearchResults['data'], allViolations: OnyxCollection, key: string, currentSearch: SearchKey, currentAccountID: number | undefined, reportActions: OnyxTypes.ReportAction[] = [], -): SearchTransactionAction { +): SearchTransactionAction[] { const isTransaction = isTransactionEntry(key); const report = getReportFromKey(data, key); if (currentSearch === CONST.SEARCH.SEARCH_KEYS.EXPORT) { - return CONST.SEARCH.ACTION_TYPES.EXPORT_TO_ACCOUNTING; + return [CONST.SEARCH.ACTION_TYPES.EXPORT_TO_ACCOUNTING]; } if (!isTransaction && !isReportEntry(key)) { - return CONST.SEARCH.ACTION_TYPES.VIEW; + return [CONST.SEARCH.ACTION_TYPES.VIEW]; } const transaction = isTransaction ? data[key] : undefined; if (isUnreportedAndHasInvalidDistanceRateTransaction(transaction)) { - return CONST.SEARCH.ACTION_TYPES.REVIEW; + return [CONST.SEARCH.ACTION_TYPES.REVIEW]; } // Tracked and unreported expenses don't have a report, so we return early. if (!report) { - return CONST.SEARCH.ACTION_TYPES.VIEW; + return [CONST.SEARCH.ACTION_TYPES.VIEW]; } const policy = getPolicyFromKey(data, report) as OnyxTypes.Policy; const isExportAvailable = isExportAction(report, policy, reportActions) && !isTransaction; if (isSettled(report) && !isExportAvailable) { - return CONST.SEARCH.ACTION_TYPES.PAID; + return [CONST.SEARCH.ACTION_TYPES.PAID]; } // We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might. We return early if there are any errors for performance reasons, so we don't need to compute any other possible actions. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (transaction?.errors || report?.errors) { - return CONST.SEARCH.ACTION_TYPES.REVIEW; + return [CONST.SEARCH.ACTION_TYPES.REVIEW]; } // We don't need to run the logic if this is not a transaction or iou/expense report, so let's shortcut the logic for performance reasons if (!isMoneyRequestReport(report) && !isInvoiceReport(report)) { - return CONST.SEARCH.ACTION_TYPES.VIEW; + return [CONST.SEARCH.ACTION_TYPES.VIEW]; } + const allActions: SearchTransactionAction[] = []; let allReportTransactions: SearchTransaction[]; if (isReportEntry(key)) { allReportTransactions = getTransactionsForReport(data, report.reportID); @@ -1088,14 +1091,15 @@ function getAction( // Only check for violations if we need to (when user has permission to review) if ((isSubmitter || isApprover || isAdmin) && hasAnyViolations(report.reportID, allViolations, allReportTransactions)) { if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, isIOUReportArchived || isChatReportArchived, policy, allReportTransactions)) { - return CONST.SEARCH.ACTION_TYPES.VIEW; + allActions.push(CONST.SEARCH.ACTION_TYPES.VIEW); + } else { + allActions.push(CONST.SEARCH.ACTION_TYPES.REVIEW); } - return CONST.SEARCH.ACTION_TYPES.REVIEW; } // Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option. // If this condition is not met, return early for performance reasons if (isTransaction && !transaction?.isFromOneTransactionReport) { - return CONST.SEARCH.ACTION_TYPES.VIEW; + return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.VIEW]; } const invoiceReceiverPolicy: SearchPolicy | undefined = @@ -1107,15 +1111,15 @@ function getAction( const canBePaid = canIOUBePaid(report, chatReport, policy, allReportTransactions, false, chatReportRNVP, invoiceReceiverPolicy); if (canBePaid && !hasOnlyHeldExpenses(report.reportID, allReportTransactions)) { - return CONST.SEARCH.ACTION_TYPES.PAY; + allActions.push(CONST.SEARCH.ACTION_TYPES.PAY); } if (isExportAvailable) { - return CONST.SEARCH.ACTION_TYPES.EXPORT_TO_ACCOUNTING; + allActions.push(CONST.SEARCH.ACTION_TYPES.EXPORT_TO_ACCOUNTING); } if (isClosedReport(report)) { - return CONST.SEARCH.ACTION_TYPES.DONE; + return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.DONE]; } const hasOnlyPendingCardOrScanningTransactions = allReportTransactions.length > 0 && allReportTransactions.every(isPendingCardOrScanningTransaction); @@ -1127,19 +1131,19 @@ function getAction( !hasOnlyPendingCardOrScanningTransactions && !hasOnlyHeldExpenses(report.reportID, allReportTransactions) ) { - return CONST.SEARCH.ACTION_TYPES.APPROVE; + allActions.push(CONST.SEARCH.ACTION_TYPES.APPROVE); } // We check for isAllowedToApproveExpenseReport because if the policy has preventSelfApprovals enabled, we disable the Submit action and in that case we want to show the View action instead if (canSubmitReport(report, policy, allReportTransactions, allViolations, isIOUReportArchived || isChatReportArchived) && isAllowedToApproveExpenseReport) { - return CONST.SEARCH.ACTION_TYPES.SUBMIT; + allActions.push(CONST.SEARCH.ACTION_TYPES.SUBMIT); } if (reportNVP?.exportFailedTime) { - return CONST.SEARCH.ACTION_TYPES.REVIEW; + return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.REVIEW]; } - return CONST.SEARCH.ACTION_TYPES.VIEW; + return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.VIEW]; } /** @@ -1320,9 +1324,11 @@ function getReportSections( if (shouldShow) { const reportPendingAction = reportItem?.pendingAction ?? reportItem?.pendingFields?.preview; const shouldShowBlankTo = !reportItem || isOpenExpenseReport(reportItem); + const allActions = getActions(data, allViolations, key, currentSearch, currentAccountID, actions); reportIDToTransactions[reportKey] = { ...reportItem, - action: getAction(data, allViolations, key, currentSearch, currentAccountID, actions), + action: allActions.at(0) ?? CONST.SEARCH.ACTION_TYPES.VIEW, + allActions, groupedBy: CONST.SEARCH.GROUP_BY.REPORTS, keyForList: reportItem.reportID, from: transactions.length > 0 ? data.personalDetailsList[data?.[reportKey as ReportKey]?.accountID ?? CONST.DEFAULT_NUMBER_ID] : emptyPersonalDetails, @@ -1349,9 +1355,11 @@ function getReportSections( const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy, formatPhoneNumber); + const allActions = getActions(data, allViolations, key, currentSearch, currentAccountID, actions); const transaction = { ...transactionItem, - action: getAction(data, allViolations, key, currentSearch, currentAccountID, actions), + action: allActions.at(0) ?? CONST.SEARCH.ACTION_TYPES.VIEW, + allActions, report, from, to, @@ -2040,7 +2048,7 @@ export { isCorrectSearchUserName, isReportActionEntry, isTaskListItemType, - getAction, + getActions, createTypeMenuSections, createBaseSavedSearchMenuItem, shouldShowEmptyState, diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index fa986e7d60e6..fa7be311fe30 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -302,7 +302,7 @@ function SearchPage({route}: SearchPageProps) { !isOffline && !isAnyTransactionOnHold && (selectedReports.length - ? selectedReports.every((report) => report.action === CONST.SEARCH.ACTION_TYPES.APPROVE) + ? selectedReports.every((report) => report.allActions.includes(CONST.SEARCH.ACTION_TYPES.APPROVE)) : selectedTransactionsKeys.every((id) => selectedTransactions[id].action === CONST.SEARCH.ACTION_TYPES.APPROVE)); if (shouldShowApproveOption) { @@ -333,7 +333,9 @@ function SearchPage({route}: SearchPageProps) { !isOffline && !isAnyTransactionOnHold && (selectedReports.length - ? selectedReports.every((report) => report.action === CONST.SEARCH.ACTION_TYPES.PAY && report.policyID && getLastPolicyPaymentMethod(report.policyID, lastPaymentMethods)) + ? selectedReports.every( + (report) => report.allActions.includes(CONST.SEARCH.ACTION_TYPES.PAY) && report.policyID && getLastPolicyPaymentMethod(report.policyID, lastPaymentMethods), + ) : selectedTransactionsKeys.every( (id) => selectedTransactions[id].action === CONST.SEARCH.ACTION_TYPES.PAY && diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 8535dfaf722a..2bcce37a35a7 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -129,9 +129,12 @@ type SearchReport = { /** The date the report was created */ created?: string; - /** The action that can be performed for the report */ + /** The main action that can be performed for the report */ action?: SearchTransactionAction; + /** The available actions that can be performed for the report */ + allActions?: SearchTransactionAction[]; + /** The type of chat if this is a chat report */ chatType?: ValueOf; @@ -403,9 +406,12 @@ type SearchTransaction = { /** The report ID of the transaction thread associated with the transaction */ transactionThreadReportID: string; - /** The action that can be performed for the transaction */ + /** The main action that can be performed for the transaction */ action: SearchTransactionAction; + /** The available actions that can be performed for the transaction */ + allActions: SearchTransactionAction[]; + /** The MCC Group associated with the transaction */ mccGroup?: ValueOf; diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 08d44333a777..76bd796730a3 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -275,6 +275,7 @@ const searchResults: OnyxTypes.SearchResults = { [`transactions_${transactionID}`]: { accountID: adminAccountID, action: 'view', + allActions: ['view'], amount: -5000, canDelete: true, canHold: true, @@ -315,6 +316,7 @@ const searchResults: OnyxTypes.SearchResults = { [`transactions_${transactionID2}`]: { accountID: adminAccountID, action: 'view', + allActions: ['view'], amount: -5000, canDelete: true, canHold: true, @@ -357,6 +359,7 @@ const searchResults: OnyxTypes.SearchResults = { accountID: adminAccountID, amount: 1200, action: 'view', + allActions: ['view'], canDelete: true, canHold: true, canUnhold: false, @@ -397,6 +400,7 @@ const searchResults: OnyxTypes.SearchResults = { accountID: adminAccountID, amount: 3200, action: 'view', + allActions: ['view'], canDelete: true, canHold: true, canUnhold: false, @@ -588,6 +592,7 @@ const transactionsListItems = [ { accountID: 18439984, action: 'submit', + allActions: ['submit'], amount: -5000, report: report1, canDelete: true, @@ -653,6 +658,7 @@ const transactionsListItems = [ { accountID: 18439984, action: 'review', + allActions: ['review', 'approve'], amount: -5000, report: report2, canDelete: true, @@ -724,6 +730,7 @@ const transactionsListItems = [ accountID: 18439984, amount: 1200, action: 'view', + allActions: ['view'], report: report3, canDelete: true, canHold: true, @@ -789,6 +796,7 @@ const transactionsListItems = [ accountID: 18439984, amount: 3200, action: 'view', + allActions: ['view'], report: report3, canDelete: true, canHold: true, @@ -857,6 +865,7 @@ const transactionReportGroupListItems = [ groupedBy: 'reports', accountID: 18439984, action: 'submit', + allActions: ['submit'], chatReportID: '1706144653204915', created: '2024-12-21 13:05:20', currency: 'USD', @@ -889,6 +898,7 @@ const transactionReportGroupListItems = [ { accountID: 18439984, action: 'submit', + allActions: ['submit'], report: report1, amount: -5000, canDelete: true, @@ -959,6 +969,7 @@ const transactionReportGroupListItems = [ groupedBy: 'reports', accountID: 18439984, action: 'review', + allActions: ['review', 'approve'], chatReportID: '1706144653204915', created: '2024-12-21 13:05:20', currency: 'USD', @@ -991,6 +1002,7 @@ const transactionReportGroupListItems = [ { accountID: 18439984, action: 'review', + allActions: ['review', 'approve'], report: report2, amount: -5000, canDelete: true, @@ -1087,6 +1099,7 @@ const transactionReportGroupListItems = [ type: 'iou', unheldTotal: 4400, action: 'pay', + allActions: ['pay'], keyForList: '99999', from: { accountID: 18439984, @@ -1106,6 +1119,7 @@ const transactionReportGroupListItems = [ groupedBy: 'reports', accountID: 18439984, action: 'view', + allActions: ['view'], chatReportID: '1706144653204915', created: '2024-12-21 13:05:20', currency: 'USD', @@ -1266,15 +1280,15 @@ describe('SearchUIUtils', () => { }); describe('Test getAction', () => { test('Should return `View` action for an invalid key', () => { - const action = SearchUIUtils.getAction(searchResults.data, {}, 'invalid_key', CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(searchResults.data, {}, 'invalid_key', CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); test('Should return `Submit` action for transaction on policy with delayed submission and no violations', () => { - let action = SearchUIUtils.getAction(searchResults.data, {}, `report_${reportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + let action = SearchUIUtils.getActions(searchResults.data, {}, `report_${reportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); - action = SearchUIUtils.getAction(searchResults.data, {}, `transactions_${transactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + action = SearchUIUtils.getActions(searchResults.data, {}, `transactions_${transactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); }); @@ -1297,10 +1311,10 @@ describe('SearchUIUtils', () => { managerID: adminAccountID, }, }; - expect(SearchUIUtils.getAction(localSearchResults, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, submitterAccountID)).toStrictEqual( + expect(SearchUIUtils.getActions(localSearchResults, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, submitterAccountID).at(0)).toStrictEqual( CONST.SEARCH.ACTION_TYPES.VIEW, ); - expect(SearchUIUtils.getAction(localSearchResults, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, submitterAccountID)).toStrictEqual( + expect(SearchUIUtils.getActions(localSearchResults, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, submitterAccountID).at(0)).toStrictEqual( CONST.SEARCH.ACTION_TYPES.VIEW, ); }); @@ -1317,15 +1331,15 @@ describe('SearchUIUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID2}`, searchResults.data[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID2}`]); - const action = SearchUIUtils.getAction(searchResults.data, duplicateViolation, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(searchResults.data, duplicateViolation, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); }); test('Should return `Review` action for transaction on policy with delayed submission and with violations', () => { - let action = SearchUIUtils.getAction(searchResults.data, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + let action = SearchUIUtils.getActions(searchResults.data, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); - action = SearchUIUtils.getAction(searchResults.data, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + action = SearchUIUtils.getActions(searchResults.data, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); }); @@ -1344,7 +1358,7 @@ describe('SearchUIUtils', () => { }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, paidReportID, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, paidReportID, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.PAID); }); @@ -1368,7 +1382,7 @@ describe('SearchUIUtils', () => { }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, paidReportID, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, paidReportID, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.PAID); }); @@ -1384,7 +1398,7 @@ describe('SearchUIUtils', () => { }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `report_${closedReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `report_${closedReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.PAY); }); @@ -1402,7 +1416,7 @@ describe('SearchUIUtils', () => { }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `report_${closedReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `report_${closedReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.DONE); }); @@ -1417,12 +1431,12 @@ describe('SearchUIUtils', () => { errors: {error: 'An error'}, }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `report_${errorReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `report_${errorReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); }); test('Should return `View` action for non-money request reports', () => { - const action = SearchUIUtils.getAction(searchResults.data, {}, `report_${reportID4}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(searchResults.data, {}, `report_${reportID4}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); @@ -1436,7 +1450,7 @@ describe('SearchUIUtils', () => { reportID: 'non_existent_report', }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `transactions_${orphanedTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `transactions_${orphanedTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); test('Should return `View` action for a transaction in a multi-transaction report', () => { @@ -1449,7 +1463,7 @@ describe('SearchUIUtils', () => { isFromOneTransactionReport: false, }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `transactions_${multiTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `transactions_${multiTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); test('Should return `Review` action if report export has failed', () => { @@ -1466,7 +1480,7 @@ describe('SearchUIUtils', () => { exportFailedTime: '2024-01-01', }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `report_${failedExportReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `report_${failedExportReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); }); test('Should return `Review` action if transaction has errors', () => { @@ -1479,14 +1493,14 @@ describe('SearchUIUtils', () => { errors: {error: 'An error'}, }, }; - const action = SearchUIUtils.getAction(localSearchResults, {}, `transactions_${errorTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(localSearchResults, {}, `transactions_${errorTransactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.REVIEW); }); test('Should return `Pay` action for an IOU report ready to be paid', async () => { Onyx.merge(ONYXKEYS.SESSION, {accountID: adminAccountID}); await waitForBatchedUpdates(); const iouReportKey = `report_${reportID3}`; - const action = SearchUIUtils.getAction(searchResults.data, {}, iouReportKey, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(searchResults.data, {}, iouReportKey, CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toEqual(CONST.SEARCH.ACTION_TYPES.PAY); }); }); @@ -1695,10 +1709,10 @@ describe('SearchUIUtils', () => { Onyx.merge(ONYXKEYS.SESSION, {accountID: overlimitApproverAccountID}); searchResults.data[`policy_${policyID}`].role = CONST.POLICY.ROLE.USER; return waitForBatchedUpdates().then(() => { - let action = SearchUIUtils.getAction(searchResults.data, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, overlimitApproverAccountID); + let action = SearchUIUtils.getActions(searchResults.data, allViolations, `report_${reportID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, overlimitApproverAccountID).at(0); expect(action).toEqual(CONST.SEARCH.ACTION_TYPES.VIEW); - action = SearchUIUtils.getAction(searchResults.data, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, overlimitApproverAccountID); + action = SearchUIUtils.getActions(searchResults.data, allViolations, `transactions_${transactionID2}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, overlimitApproverAccountID).at(0); expect(action).toEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); }); @@ -1783,6 +1797,7 @@ describe('SearchUIUtils', () => { canUnhold: false, category: 'Employee Meals Remote (Fringe Benefit)', action: 'approve', + allActions: ['approve'], comment: { comment: '', }, @@ -1825,7 +1840,7 @@ describe('SearchUIUtils', () => { }, }; return waitForBatchedUpdates().then(() => { - const action = SearchUIUtils.getAction(result.data, allViolations, 'report_6523565988285061', CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID); + const action = SearchUIUtils.getActions(result.data, allViolations, 'report_6523565988285061', CONST.SEARCH.SEARCH_KEYS.EXPENSES, adminAccountID).at(0); expect(action).toEqual(CONST.SEARCH.ACTION_TYPES.APPROVE); }); }); From a23381f14b5bb7ac81dadd2109643b09c35f462c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 21 Aug 2025 13:16:14 +0700 Subject: [PATCH 2/2] fix type --- tests/unit/Search/handleActionButtonPressTest.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index 7a9e48a280cf..b98853a8eac2 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -13,6 +13,7 @@ const mockReportItemWithHold = { shouldAnimateInHighlight: false, accountID: 1206, action: 'approve', + allActions: ['approve'], chatReportID: '2108006919825366', created: '2024-12-04 23:18:33', currency: 'USD', @@ -69,6 +70,7 @@ const mockReportItemWithHold = { }, accountID: 1206, action: 'view', + allActions: ['view'], amount: -1200, canDelete: true, canHold: false, @@ -147,6 +149,7 @@ const mockReportItemWithHold = { }, accountID: 1206, action: 'view', + allActions: ['view'], amount: -12300, canDelete: true, canHold: true,