From 46106c18278c9f13beec8be45e1b92fe1eb0b14a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 10 Dec 2025 15:57:26 +0700 Subject: [PATCH 1/6] remove canDelete --- src/components/Search/index.tsx | 4 -- src/components/Search/types.ts | 3 -- src/libs/SearchUIUtils.ts | 1 - src/pages/Search/SearchPage.tsx | 47 +++++++++++++++---- src/types/onyx/SearchResults.ts | 3 -- tests/unit/MoneyRequestReportUtilsTest.ts | 1 - tests/unit/Search/SearchUIUtilsTest.ts | 12 ----- .../Search/handleActionButtonPressTest.ts | 2 - tests/unit/TransactionGroupListItemTest.tsx | 1 - 9 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 3861ac4074e6c..cd91ebae394e7 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -103,7 +103,6 @@ function mapTransactionItemToSelectedEntry( item.keyForList, { isSelected: true, - canDelete: item.canDelete, canHold: canHoldRequest, isHeld: isOnHold(item), canUnhold: canUnholdRequest, @@ -193,7 +192,6 @@ function prepareTransactionsList( ...selectedTransactions, [item.keyForList]: { isSelected: true, - canDelete: item.canDelete, canHold: canHoldRequest, isHeld: isOnHold(item), canUnhold: canUnholdRequest, @@ -535,7 +533,6 @@ function Search({ ), // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing isSelected: areAllMatchingItemsSelected || selectedTransactions[transactionItem.transactionID]?.isSelected || isExpenseReportType, - canDelete: transactionItem.canDelete, reportID: transactionItem.reportID, policyID: transactionItem.report?.policyID, amount: transactionItem.modifiedAmount ?? transactionItem.amount, @@ -585,7 +582,6 @@ function Search({ ), // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing isSelected: areAllMatchingItemsSelected || selectedTransactions[transactionItem.transactionID].isSelected, - canDelete: transactionItem.canDelete, reportID: transactionItem.reportID, policyID: transactionItem.report?.policyID, amount: transactionItem.modifiedAmount ?? transactionItem.amount, diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index d72c6ad631faf..fa312e1039c06 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -11,9 +11,6 @@ type SelectedTransactionInfo = { /** Whether the transaction is selected */ isSelected: boolean; - /** If the transaction can be deleted */ - canDelete: boolean; - /** If the transaction can be put on hold */ canHold: boolean; diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 06278f12c7247..91056352d4f6e 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2686,7 +2686,6 @@ function getTransactionFromTransactionListItem(item: TransactionListItemType): O isTaxAmountColumnWide, violations, hash, - canDelete, accountID, policyID, ...transaction diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index f181a797c4002..d557a72c37d6b 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -60,7 +60,9 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types'; import {getActiveAdminWorkspaces, hasDynamicExternalWorkflow, hasOnlyPersonalPolicies as hasOnlyPersonalPoliciesUtil, hasVBBA, isPaidGroupPolicy} from '@libs/PolicyUtils'; +import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils'; import { + canDeleteMoneyRequestReport, generateReportID, getPolicyExpenseChat, getReportOrDraftReport, @@ -102,6 +104,7 @@ function SearchPage({route}: SearchPageProps) { const isMobileSelectionModeEnabled = useMobileSelectionMode(); const allTransactions = useAllTransactions(); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); + const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: false}); const [lastPaymentMethods] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true}); const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const newReportID = generateReportID(); @@ -654,7 +657,24 @@ function SearchPage({route}: SearchPageProps) { }); } - const shouldShowDeleteOption = !isOffline && selectedTransactionsKeys.every((id) => selectedTransactions[id].canDelete); + const shouldShowDeleteOption = + !isOffline && + selectedTransactionsKeys.every((id) => { + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]; + if (!transaction) { + return false; + } + const parentReportID = transaction.reportID; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; + if (!parentReport) { + return false; + } + const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]; + const parentReportAction = Object.values(reportActions ?? {}).find( + (action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === selectedTransactions[id].transactionID, + ); + return canDeleteMoneyRequestReport(parentReport, [transaction], parentReportAction ? [parentReportAction] : []); + }); if (shouldShowDeleteOption) { options.push({ @@ -701,15 +721,27 @@ function SearchPage({route}: SearchPageProps) { status, hash, selectedTransactions, + expensifyIcons.Export, + expensifyIcons.ArrowRight, + expensifyIcons.Table, + expensifyIcons.ThumbsUp, + expensifyIcons.Workflows, + expensifyIcons.Send, + expensifyIcons.MoneyBag, + expensifyIcons.Stopwatch, + expensifyIcons.DocumentMerge, + expensifyIcons.ArrowSplit, + expensifyIcons.Trashcan, + expensifyIcons.Exclamation, translate, areAllMatchingItemsSelected, isOffline, selectedReports, - selectedTransactionReportIDs, + queryJSON, lastPaymentMethods, selectedReportIDs, allTransactions, - queryJSON, + selectedTransactionReportIDs, selectedPolicyIDs, policies, integrationsExportTemplates, @@ -718,16 +750,15 @@ function SearchPage({route}: SearchPageProps) { beginExportWithTemplate, bulkPayButtonOptions, onBulkPaySelected, + areAllTransactionsFromSubmitter, + dismissedHoldUseExplanation, + dismissedRejectUseExplanation, allReports, + allReportActions, theme.icon, styles.colorMuted, styles.fontWeightNormal, styles.textWrap, - expensifyIcons, - dismissedHoldUseExplanation, - dismissedRejectUseExplanation, - areAllTransactionsFromSubmitter, - currentUserPersonalDetails?.login, ]); const handleDeleteExpenses = () => { diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 08b66a5086afc..8b90d653cbbb7 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -86,9 +86,6 @@ type SearchTransaction = { /** The transaction amount */ amount: number; - /** If the transaction can be deleted */ - canDelete: boolean; - /** The edited transaction amount */ modifiedAmount: number; diff --git a/tests/unit/MoneyRequestReportUtilsTest.ts b/tests/unit/MoneyRequestReportUtilsTest.ts index 7bfdb21051833..9cae1e021d328 100644 --- a/tests/unit/MoneyRequestReportUtilsTest.ts +++ b/tests/unit/MoneyRequestReportUtilsTest.ts @@ -55,7 +55,6 @@ const transactionItemBaseMock: TransactionListItemType = { policy: policyBaseMock, reportAction: reportActionBaseMock, holdReportAction: undefined, - canDelete: true, cardID: undefined, cardName: undefined, category: '', diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index b0f03998d63ab..c348418376cd5 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -386,7 +386,6 @@ const searchResults: OnyxTypes.SearchResults = { [`report_${reportID5}`]: report5, [`transactions_${transactionID}`]: { amount: -5000, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -416,7 +415,6 @@ const searchResults: OnyxTypes.SearchResults = { }, [`transactions_${transactionID2}`]: { amount: -5000, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -447,7 +445,6 @@ const searchResults: OnyxTypes.SearchResults = { ...allViolations, [`transactions_${transactionID3}`]: { amount: 1200, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -477,7 +474,6 @@ const searchResults: OnyxTypes.SearchResults = { }, [`transactions_${transactionID4}`]: { amount: 3200, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -763,7 +759,6 @@ const transactionsListItems = [ policy, reportAction: reportAction1, holdReportAction: undefined, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -815,7 +810,6 @@ const transactionsListItems = [ policy, reportAction: reportAction2, holdReportAction: undefined, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -877,7 +871,6 @@ const transactionsListItems = [ policy, reportAction: reportAction3, holdReportAction: undefined, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -934,7 +927,6 @@ const transactionsListItems = [ policy, reportAction: reportAction4, holdReportAction: undefined, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -1028,7 +1020,6 @@ const transactionReportGroupListItems = [ reportAction: reportAction1, holdReportAction: undefined, amount: -5000, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -1123,7 +1114,6 @@ const transactionReportGroupListItems = [ reportAction: reportAction2, holdReportAction: undefined, amount: -5000, - canDelete: true, cardID: undefined, cardName: undefined, category: '', @@ -2331,7 +2321,6 @@ describe('SearchUIUtils', () => { // eslint-disable-next-line @typescript-eslint/naming-convention transactions_1805965960759424086: { amount: 0, - canDelete: false, category: 'Employee Meals Remote (Fringe Benefit)', comment: { comment: '', @@ -2454,7 +2443,6 @@ describe('SearchUIUtils', () => { // eslint-disable-next-line @typescript-eslint/naming-convention transactions_1805965960759424086: { amount: 0, - canDelete: false, cardID: undefined, cardName: undefined, category: 'Employee Meals Remote (Fringe Benefit)', diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index 4deb193a807c0..5bb137e4228eb 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -92,7 +92,6 @@ const mockReportItemWithHold = { action: 'view', allActions: ['view'], amount: -1200, - canDelete: true, category: '', comment: { comment: '', @@ -181,7 +180,6 @@ const mockReportItemWithHold = { action: 'view', allActions: ['view'], amount: -12300, - canDelete: true, category: '', comment: { comment: '', diff --git a/tests/unit/TransactionGroupListItemTest.tsx b/tests/unit/TransactionGroupListItemTest.tsx index 6e360fdafeb79..05cc0ab57376b 100644 --- a/tests/unit/TransactionGroupListItemTest.tsx +++ b/tests/unit/TransactionGroupListItemTest.tsx @@ -26,7 +26,6 @@ jest.mock('@libs/SearchUIUtils', () => ({ const mockTransaction: TransactionListItemType = { accountID: 1, amount: 0, - canDelete: true, category: '', groupAmount: 1284, groupCurrency: 'USD', From 8b34909a8cc1465e2206e18dbd2e26b338321475 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 10 Dec 2025 16:21:07 +0700 Subject: [PATCH 2/6] fix UTs --- src/pages/Search/SearchPage.tsx | 15 ++------------- tests/unit/Search/SearchContextTest.tsx | 1 - tests/unit/Search/SearchUIUtilsTest.ts | 4 ++-- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index d557a72c37d6b..bab5ec23ba890 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -671,7 +671,7 @@ function SearchPage({route}: SearchPageProps) { } const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]; const parentReportAction = Object.values(reportActions ?? {}).find( - (action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === selectedTransactions[id].transactionID, + (action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === transaction.transactionID, ); return canDeleteMoneyRequestReport(parentReport, [transaction], parentReportAction ? [parentReportAction] : []); }); @@ -721,18 +721,7 @@ function SearchPage({route}: SearchPageProps) { status, hash, selectedTransactions, - expensifyIcons.Export, - expensifyIcons.ArrowRight, - expensifyIcons.Table, - expensifyIcons.ThumbsUp, - expensifyIcons.Workflows, - expensifyIcons.Send, - expensifyIcons.MoneyBag, - expensifyIcons.Stopwatch, - expensifyIcons.DocumentMerge, - expensifyIcons.ArrowSplit, - expensifyIcons.Trashcan, - expensifyIcons.Exclamation, + expensifyIcons, translate, areAllMatchingItemsSelected, isOffline, diff --git a/tests/unit/Search/SearchContextTest.tsx b/tests/unit/Search/SearchContextTest.tsx index 2d973768314d4..0c1cc7f2f0eb0 100644 --- a/tests/unit/Search/SearchContextTest.tsx +++ b/tests/unit/Search/SearchContextTest.tsx @@ -13,7 +13,6 @@ const mockSelectedTransaction: SelectedTransactionInfo = { canUnhold: false, canChangeReport: true, isSelected: true, - canDelete: true, policyID: '06F34677820A4D07', reportID: '515146912679679', amount: 0, diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index c348418376cd5..1474fbd03c3cc 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1696,7 +1696,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 46; + const expectedPropertyCount = 45; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); }); @@ -1729,7 +1729,7 @@ describe('SearchUIUtils', () => { expect(distanceTransaction).toBeDefined(); expect(distanceTransaction?.iouRequestType).toBe(CONST.IOU.REQUEST_TYPE.DISTANCE); - const expectedPropertyCount = 46; + const expectedPropertyCount = 45; expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount); }); From e3066a679b1df6b7ad5274c4ad549d76c300f601 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 11 Dec 2025 16:47:23 +0700 Subject: [PATCH 3/6] Using snapshot data --- src/pages/Search/SearchPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index bab5ec23ba890..0b1d1b75eb8d1 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -660,16 +660,16 @@ function SearchPage({route}: SearchPageProps) { const shouldShowDeleteOption = !isOffline && selectedTransactionsKeys.every((id) => { - const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]; + const transaction = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]; if (!transaction) { return false; } const parentReportID = transaction.reportID; - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; + const parentReport = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`]; if (!parentReport) { return false; } - const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]; + const reportActions = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]; const parentReportAction = Object.values(reportActions ?? {}).find( (action) => (isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined) === transaction.transactionID, ); From 39670fa5181c8a0ea481d7be6fbcdfa1c8ff3397 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 11 Dec 2025 23:45:14 +0700 Subject: [PATCH 4/6] remove redundant --- src/pages/Search/SearchPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 52bbc6962ee48..bb6fc1e91b850 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -107,7 +107,6 @@ function SearchPage({route}: SearchPageProps) { const isMobileSelectionModeEnabled = useMobileSelectionMode(); const allTransactions = useAllTransactions(); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); - const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: false}); const [lastPaymentMethods] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true}); const [currentDate] = useOnyx(ONYXKEYS.CURRENT_DATE, {canBeMissing: true}); const newReportID = generateReportID(); From ab839b345605a64942dd93eb38635523da6a138b Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 12 Dec 2025 14:01:17 +0700 Subject: [PATCH 5/6] conflict --- tests/unit/Search/SearchContextTest.tsx | 156 ++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 tests/unit/Search/SearchContextTest.tsx diff --git a/tests/unit/Search/SearchContextTest.tsx b/tests/unit/Search/SearchContextTest.tsx new file mode 100644 index 0000000000000..d08d161f7925a --- /dev/null +++ b/tests/unit/Search/SearchContextTest.tsx @@ -0,0 +1,156 @@ +import {renderHook} from '@testing-library/react-native'; +import React, {act} from 'react'; +import {SearchContextProvider, useSearchContext} from '@components/Search/SearchContext'; +import type {SelectedTransactionInfo} from '@components/Search/types'; +import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionListWithSections/types'; + +const mockSelectedTransaction: SelectedTransactionInfo = { + action: 'approve', + canHold: true, + isHeld: false, + canSplit: false, + hasBeenSplit: false, + canUnhold: false, + canChangeReport: true, + isSelected: true, + canReject: false, + policyID: '06F34677820A4D07', + reportID: '515146912679679', + amount: 0, + groupAmount: 1284, + groupCurrency: 'USD', + currency: 'USD', + ownerAccountID: 1, +} as const; + +const mockTransaction = { + accountID: 1, + amount: 0, + category: '', + groupAmount: 1284, + groupCurrency: 'USD', + created: '2025-09-19', + currency: 'USD', + policy: { + id: '06F34677820A4D07', + type: 'team', + role: 'admin', + owner: 'test@test.com', + name: 'Policy', + outputCurrency: 'USD', + isPolicyExpenseChatEnabled: true, + }, + reportAction: { + reportActionID: '2454187434077044186', + actionName: 'IOU', + created: '2025-09-19', + }, + holdReportAction: undefined, + merchant: '(none)', + modifiedAmount: -1284, + modifiedCreated: '2025-09-07', + modifiedCurrency: 'USD', + modifiedMerchant: 'The Home Depot', + policyID: '06F34677820A4D07', + reportID: '515146912679679', + tag: '', + transactionID: '1', + action: 'approve', + allActions: ['approve'], + formattedFrom: 'Main Applause QA', + formattedTo: 'Main Applause QA', + formattedTotal: -1284, + formattedMerchant: 'The Home Depot', + date: '2025-09-07', + shouldShowMerchant: true, + shouldShowYear: true, + keyForList: '1', + isAmountColumnWide: false, + isTaxAmountColumnWide: false, + shouldAnimateInHighlight: false, + report: { + reportID: '515146912679679', + }, + from: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', + displayName: 'Main Applause QA', + }, + to: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', + displayName: 'Main Applause QA', + }, +} as TransactionListItemType; + +const mockReport = { + accountID: 1, + chatReportID: '4735435600700077', + chatType: undefined, + created: '2025-09-19 20:00:47', + currency: 'USD', + isOneTransactionReport: true, + isOwnPolicyExpenseChat: false, + isWaitingOnBankAccount: false, + managerID: 1, + nonReimbursableTotal: 0, + oldPolicyName: '', + ownerAccountID: 1, + parentReportActionID: '2454187434077044186', + parentReportID: '4735435600700077', + policyID: '06F34677820A4D07', + reportID: '515146912679679', + reportName: 'Expense Report #515146912679679', + stateNum: 1, + statusNum: 1, + total: -1284, + type: 'expense', + unheldTotal: -1284, + from: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', + displayName: 'Main Applause QA', + }, + to: { + accountID: 1, + avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', + displayName: 'Main Applause QA', + }, + shouldShowYear: false, + action: 'view', + transactions: [mockTransaction], + groupedBy: 'expense-report', + keyForList: '515146912679679', +} as TransactionReportGroupListItemType; + +mockTransaction.report = mockReport; + +const wrapper = ({children}: {children: React.ReactNode}) => {children}; + +describe('SearchContext', () => { + it('returns selectedReports for TransactionReportGroupListItem', () => { + const {result} = renderHook(() => useSearchContext(), {wrapper}); + act(() => { + result.current.setSelectedTransactions({[mockTransaction.keyForList]: mockSelectedTransaction}, [mockReport]); + }); + const selectedReport = result.current.selectedReports.at(0); + + expect(selectedReport?.managerID).toEqual(1); + expect(selectedReport?.ownerAccountID).toBe(1); + expect(selectedReport?.parentReportActionID).toBe('2454187434077044186'); + expect(selectedReport?.parentReportID).toBe('4735435600700077'); + }); + + it('returns selectedReports for TransactionListItemType', () => { + const {result} = renderHook(() => useSearchContext(), {wrapper}); + act(() => { + result.current.setSelectedTransactions({[mockTransaction.keyForList]: mockSelectedTransaction}, [mockTransaction]); + }); + const selectedReport = result.current.selectedReports.at(0); + + expect(selectedReport?.managerID).toEqual(1); + expect(selectedReport?.ownerAccountID).toBe(1); + expect(selectedReport?.parentReportActionID).toBe('2454187434077044186'); + expect(selectedReport?.parentReportID).toBe('4735435600700077'); + }); +}); From 4259be4839fe952ebf20eb63118797f890863b56 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 12 Dec 2025 14:04:31 +0700 Subject: [PATCH 6/6] conflict --- tests/unit/Search/SearchContextTest.tsx | 156 ------------------------ 1 file changed, 156 deletions(-) delete mode 100644 tests/unit/Search/SearchContextTest.tsx diff --git a/tests/unit/Search/SearchContextTest.tsx b/tests/unit/Search/SearchContextTest.tsx deleted file mode 100644 index d08d161f7925a..0000000000000 --- a/tests/unit/Search/SearchContextTest.tsx +++ /dev/null @@ -1,156 +0,0 @@ -import {renderHook} from '@testing-library/react-native'; -import React, {act} from 'react'; -import {SearchContextProvider, useSearchContext} from '@components/Search/SearchContext'; -import type {SelectedTransactionInfo} from '@components/Search/types'; -import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/SelectionListWithSections/types'; - -const mockSelectedTransaction: SelectedTransactionInfo = { - action: 'approve', - canHold: true, - isHeld: false, - canSplit: false, - hasBeenSplit: false, - canUnhold: false, - canChangeReport: true, - isSelected: true, - canReject: false, - policyID: '06F34677820A4D07', - reportID: '515146912679679', - amount: 0, - groupAmount: 1284, - groupCurrency: 'USD', - currency: 'USD', - ownerAccountID: 1, -} as const; - -const mockTransaction = { - accountID: 1, - amount: 0, - category: '', - groupAmount: 1284, - groupCurrency: 'USD', - created: '2025-09-19', - currency: 'USD', - policy: { - id: '06F34677820A4D07', - type: 'team', - role: 'admin', - owner: 'test@test.com', - name: 'Policy', - outputCurrency: 'USD', - isPolicyExpenseChatEnabled: true, - }, - reportAction: { - reportActionID: '2454187434077044186', - actionName: 'IOU', - created: '2025-09-19', - }, - holdReportAction: undefined, - merchant: '(none)', - modifiedAmount: -1284, - modifiedCreated: '2025-09-07', - modifiedCurrency: 'USD', - modifiedMerchant: 'The Home Depot', - policyID: '06F34677820A4D07', - reportID: '515146912679679', - tag: '', - transactionID: '1', - action: 'approve', - allActions: ['approve'], - formattedFrom: 'Main Applause QA', - formattedTo: 'Main Applause QA', - formattedTotal: -1284, - formattedMerchant: 'The Home Depot', - date: '2025-09-07', - shouldShowMerchant: true, - shouldShowYear: true, - keyForList: '1', - isAmountColumnWide: false, - isTaxAmountColumnWide: false, - shouldAnimateInHighlight: false, - report: { - reportID: '515146912679679', - }, - from: { - accountID: 1, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', - displayName: 'Main Applause QA', - }, - to: { - accountID: 1, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', - displayName: 'Main Applause QA', - }, -} as TransactionListItemType; - -const mockReport = { - accountID: 1, - chatReportID: '4735435600700077', - chatType: undefined, - created: '2025-09-19 20:00:47', - currency: 'USD', - isOneTransactionReport: true, - isOwnPolicyExpenseChat: false, - isWaitingOnBankAccount: false, - managerID: 1, - nonReimbursableTotal: 0, - oldPolicyName: '', - ownerAccountID: 1, - parentReportActionID: '2454187434077044186', - parentReportID: '4735435600700077', - policyID: '06F34677820A4D07', - reportID: '515146912679679', - reportName: 'Expense Report #515146912679679', - stateNum: 1, - statusNum: 1, - total: -1284, - type: 'expense', - unheldTotal: -1284, - from: { - accountID: 1, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', - displayName: 'Main Applause QA', - }, - to: { - accountID: 1, - avatar: 'https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_15.png', - displayName: 'Main Applause QA', - }, - shouldShowYear: false, - action: 'view', - transactions: [mockTransaction], - groupedBy: 'expense-report', - keyForList: '515146912679679', -} as TransactionReportGroupListItemType; - -mockTransaction.report = mockReport; - -const wrapper = ({children}: {children: React.ReactNode}) => {children}; - -describe('SearchContext', () => { - it('returns selectedReports for TransactionReportGroupListItem', () => { - const {result} = renderHook(() => useSearchContext(), {wrapper}); - act(() => { - result.current.setSelectedTransactions({[mockTransaction.keyForList]: mockSelectedTransaction}, [mockReport]); - }); - const selectedReport = result.current.selectedReports.at(0); - - expect(selectedReport?.managerID).toEqual(1); - expect(selectedReport?.ownerAccountID).toBe(1); - expect(selectedReport?.parentReportActionID).toBe('2454187434077044186'); - expect(selectedReport?.parentReportID).toBe('4735435600700077'); - }); - - it('returns selectedReports for TransactionListItemType', () => { - const {result} = renderHook(() => useSearchContext(), {wrapper}); - act(() => { - result.current.setSelectedTransactions({[mockTransaction.keyForList]: mockSelectedTransaction}, [mockTransaction]); - }); - const selectedReport = result.current.selectedReports.at(0); - - expect(selectedReport?.managerID).toEqual(1); - expect(selectedReport?.ownerAccountID).toBe(1); - expect(selectedReport?.parentReportActionID).toBe('2454187434077044186'); - expect(selectedReport?.parentReportID).toBe('4735435600700077'); - }); -});