diff --git a/src/components/MoneyRequestHeaderSecondaryActions.tsx b/src/components/MoneyRequestHeaderSecondaryActions.tsx index 376a617e5b2d..27d9ae23d1d8 100644 --- a/src/components/MoneyRequestHeaderSecondaryActions.tsx +++ b/src/components/MoneyRequestHeaderSecondaryActions.tsx @@ -47,6 +47,7 @@ import { isCurrentUserSubmitter, isDM, isExpenseReport, + isOpenReport, isSelfDM, navigateToDetailsPage, rejectMoneyRequestReason, @@ -192,7 +193,8 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money const shouldDuplicateCloseModalOnSelect = isDistanceExpenseUnsupportedForDuplicating || hasCustomUnitOutOfPolicyViolation || isPerDiemRequestOnNonDefaultWorkspace; const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); const hasMultipleSplits = useHasMultipleSplitChildren(transaction?.comment?.originalTransactionID); - const shouldShowSplitIndicator = isExpenseSplit && hasMultipleSplits; + const isReportOpen = isOpenReport(parentReport); + const shouldShowSplitIndicator = isExpenseSplit && (hasMultipleSplits || isReportOpen); const shouldShowEditSplitOnDeleteAction = !!transaction?.transactionID && shouldOpenSplitExpenseEditFlowOnDelete([transaction.transactionID]); const isReportSubmitter = isCurrentUserSubmitter(chatIOUReport); const draftTransactionIDs = Object.keys(transactionDrafts ?? {}); diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 0b5153099fb7..378c4289c4c0 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -76,6 +76,7 @@ import { getTripIDFromTransactionParentReportID, isExpenseReport, isInvoiceReport, + isOpenReport, isPaidGroupPolicy, isReportApproved, isReportInGroupPolicy, @@ -351,7 +352,8 @@ function MoneyRequestView({ const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`); const hasMultipleSplits = useHasMultipleSplitChildren(transaction?.comment?.originalTransactionID); - const shouldShowSplitIndicator = isExpenseSplit && hasMultipleSplits; + const isReportOpen = isOpenReport(moneyRequestReport); + const shouldShowSplitIndicator = isExpenseSplit && (hasMultipleSplits || isReportOpen); const isSplitAvailable = moneyRequestReport && transaction && diff --git a/src/hooks/useDeleteTransactions.ts b/src/hooks/useDeleteTransactions.ts index 3908bc55da1d..f0e0e488f468 100644 --- a/src/hooks/useDeleteTransactions.ts +++ b/src/hooks/useDeleteTransactions.ts @@ -92,14 +92,13 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac } const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.comment?.originalTransactionID}`]; - const hasMultipleSplits = getChildTransactions(allTransactions, allReports, originalTransaction?.transactionID, true).length > 1; - if (!shouldRedirectDeleteToSplitExpenseEdit(transaction, originalTransaction) || (!hasMultipleSplits && isPerDiemRequestTransactionUtils(originalTransaction))) { + if (!shouldRedirectDeleteToSplitExpenseEdit(transaction, originalTransaction)) { return undefined; } return transaction; }, - [allTransactions, allReports], + [allTransactions], ); const shouldOpenSplitExpenseEditFlowOnDelete = useCallback( diff --git a/src/hooks/useExpenseActions.ts b/src/hooks/useExpenseActions.ts index 674752c18b60..8e33c74effd1 100644 --- a/src/hooks/useExpenseActions.ts +++ b/src/hooks/useExpenseActions.ts @@ -27,6 +27,7 @@ import { getAddExpenseDropdownOptions, getPolicyExpenseChat, isDM, + isOpenReport, isSelfDM, navigateOnDeleteExpense, } from '@libs/ReportUtils'; @@ -169,8 +170,9 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic // Split indicator const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); - const hasMultipleSplits = !!transaction?.comment?.originalTransactionID && getChildTransactions(allTransactions, allReports, transaction.comment.originalTransactionID, true).length > 1; - const hasSplitIndicator = isExpenseSplit && hasMultipleSplits; + const hasMultipleSplits = !!transaction?.comment?.originalTransactionID && getChildTransactions(allTransactions, allReports, transaction.comment.originalTransactionID).length > 1; + const isReportOpen = isOpenReport(moneyRequestReport); + const hasSplitIndicator = isExpenseSplit && (hasMultipleSplits || isReportOpen); const shouldShowEditSplitOnDeleteAction = !!transaction?.transactionID && shouldOpenSplitExpenseEditFlowOnDelete([transaction.transactionID]); // Duplicate report throttle diff --git a/src/hooks/useHasMultipleSplitChildren.ts b/src/hooks/useHasMultipleSplitChildren.ts index 45966dfdc1c8..45f0e588951a 100644 --- a/src/hooks/useHasMultipleSplitChildren.ts +++ b/src/hooks/useHasMultipleSplitChildren.ts @@ -15,7 +15,11 @@ function selectChildTransactionInfo(transactions: OnyxCollection, o } const result: ChildTransactionInfo[] = []; for (const t of Object.values(transactions ?? {})) { - if (t?.comment?.originalTransactionID === originalTransactionID && t?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { + if ( + t?.comment?.originalTransactionID === originalTransactionID && + t?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && + t?.reportID !== CONST.REPORT.UNREPORTED_REPORT_ID + ) { result.push({reportID: t?.reportID, isSplitSource: t?.comment?.source === CONST.IOU.TYPE.SPLIT}); } } diff --git a/src/hooks/useSelectedTransactionsActions.ts b/src/hooks/useSelectedTransactionsActions.ts index edefbf4ab72d..7cb4ea374e48 100644 --- a/src/hooks/useSelectedTransactionsActions.ts +++ b/src/hooks/useSelectedTransactionsActions.ts @@ -28,7 +28,7 @@ import { isTrackExpenseReport, } from '@libs/ReportUtils'; import {getCurrentSearchQueryJSON} from '@libs/SearchQueryUtils'; -import {getChildTransactions, getOriginalTransactionWithSplitInfo, hasTransactionBeenRejected} from '@libs/TransactionUtils'; +import {getOriginalTransactionWithSplitInfo, hasTransactionBeenRejected} from '@libs/TransactionUtils'; import type {IOUType} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -471,12 +471,8 @@ function useSelectedTransactionsActions({ const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${firstTransaction?.comment?.originalTransactionID}`]; const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(firstTransaction, originalTransaction); - const hasMultipleSplits = getChildTransactions(allTransactions, allReports, firstTransaction?.comment?.originalTransactionID, true).length > 1; const canSplitTransaction = - selectedTransactionsList.length === 1 && - report && - !(isExpenseSplit && hasMultipleSplits) && - isSplitAction(report, [firstTransaction], originalTransaction, login ?? '', currentUserAccountID, policy); + selectedTransactionsList.length === 1 && report && !isExpenseSplit && isSplitAction(report, [firstTransaction], originalTransaction, login ?? '', currentUserAccountID, policy); if (canSplitTransaction) { options.push({ diff --git a/src/libs/actions/SplitExpenses.ts b/src/libs/actions/SplitExpenses.ts index 3ad037e19906..eb7856a66de3 100644 --- a/src/libs/actions/SplitExpenses.ts +++ b/src/libs/actions/SplitExpenses.ts @@ -5,7 +5,7 @@ import {calculateAmount} from '@libs/IOUUtils'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import {rand64} from '@libs/NumberUtils'; -import {getTransactionDetails} from '@libs/ReportUtils'; +import {getTransactionDetails, isOpenReport} from '@libs/ReportUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; import {buildOptimisticTransaction, getChildTransactions, getOriginalTransactionWithSplitInfo, isDistanceRequest} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; @@ -82,9 +82,10 @@ function initSplitExpense(transaction: OnyxEntry, policy?: OnyxEntr const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`]; const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); const relatedTransactions = getChildTransactions(allTransactions, allReports, originalTransactionID); - const hasMultipleSplits = getChildTransactions(allTransactions, allReports, originalTransactionID, true).length > 1; + const hasMultipleSplits = relatedTransactions.length > 1; const transactionReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`]; - const shouldShowSplitIndicator = isExpenseSplit && hasMultipleSplits; + const isReportOpen = isOpenReport(transactionReport); + const shouldShowSplitIndicator = isExpenseSplit && (hasMultipleSplits || isReportOpen); if (isExpenseSplit && shouldShowSplitIndicator) { const transactionDetails = getTransactionDetails(originalTransaction); diff --git a/tests/actions/IOUTest/SplitTest.ts b/tests/actions/IOUTest/SplitTest.ts index 16228b98ba05..81b00b0bb20e 100644 --- a/tests/actions/IOUTest/SplitTest.ts +++ b/tests/actions/IOUTest/SplitTest.ts @@ -4997,131 +4997,6 @@ describe('initSplitExpense', () => { expect(splitExpenses?.[1].merchant).toBeTruthy(); expect(splitExpenses?.[1].merchant).toContain('100'); }); - - it('should let you split the expense again after its other split half was deleted', async () => { - const originalTransactionID = 'dissolved-original'; - const remainingTransactionID = 'dissolved-remaining'; - const deletedSiblingTransactionID = 'dissolved-deleted-sibling'; - const expenseReportID = 'dissolved-expense-report'; - - // Given an open expense report (an open report previously kept the remaining transaction stuck in the "edit splits" flow) - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`, { - reportID: expenseReportID, - type: CONST.REPORT.TYPE.EXPENSE, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }); - - // And the original parent expense transaction still exists, hidden on the split report - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`, { - transactionID: originalTransactionID, - amount: -100, - currency: 'USD', - merchant: 'Test Merchant', - comment: {comment: 'Original expense'}, - created: DateUtils.getDBTime(), - reportID: CONST.REPORT.SPLIT_REPORT_ID, - }); - - // And the sibling split was unreported and then deleted - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${deletedSiblingTransactionID}`, { - transactionID: deletedSiblingTransactionID, - amount: -50, - currency: 'USD', - merchant: 'Test Merchant', - comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT}, - created: DateUtils.getDBTime(), - reportID: CONST.REPORT.UNREPORTED_REPORT_ID, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - }); - - // And the remaining split is the only child left and still references the original - const remainingTransaction: Transaction = { - transactionID: remainingTransactionID, - amount: -50, - currency: 'USD', - merchant: 'Test Merchant', - comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT}, - created: DateUtils.getDBTime(), - reportID: expenseReportID, - }; - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${remainingTransactionID}`, remainingTransaction); - await waitForBatchedUpdates(); - - // When the user initiates a split on the remaining transaction - initSplitExpense(remainingTransaction, undefined); - await waitForBatchedUpdates(); - - // Then a fresh split is started keyed by the remaining transaction (2 new splits) - const freshDraft = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${remainingTransactionID}`); - expect(freshDraft).toBeTruthy(); - expect(freshDraft?.comment?.splitExpenses).toHaveLength(2); - - // And the split's edit flow keyed by the original transaction is not re-opened - const editDraft = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${originalTransactionID}`); - expect(editDraft).toBeFalsy(); - }); - - it('should open the edit-splits flow for an intact multi-child split', async () => { - const originalTransactionID = 'intact-original'; - const firstChildTransactionID = 'intact-child-1'; - const secondChildTransactionID = 'intact-child-2'; - const expenseReportID = 'intact-expense-report'; - - // Given an open expense report - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`, { - reportID: expenseReportID, - type: CONST.REPORT.TYPE.EXPENSE, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }); - - // And the original parent expense transaction still exists, hidden on the split report - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`, { - transactionID: originalTransactionID, - amount: -100, - currency: 'USD', - merchant: 'Test Merchant', - comment: {comment: 'Original expense'}, - created: DateUtils.getDBTime(), - reportID: CONST.REPORT.SPLIT_REPORT_ID, - }); - - // And two split children both live on the expense report (intact split, no deletions) - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${firstChildTransactionID}`, { - transactionID: firstChildTransactionID, - amount: -50, - currency: 'USD', - merchant: 'Test Merchant', - comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT}, - created: DateUtils.getDBTime(), - reportID: expenseReportID, - }); - const secondChildTransaction: Transaction = { - transactionID: secondChildTransactionID, - amount: -50, - currency: 'USD', - merchant: 'Test Merchant', - comment: {originalTransactionID, source: CONST.IOU.TYPE.SPLIT}, - created: DateUtils.getDBTime(), - reportID: expenseReportID, - }; - await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${secondChildTransactionID}`, secondChildTransaction); - await waitForBatchedUpdates(); - - // When the user opens the edit-splits flow from one of the children - initSplitExpense(secondChildTransaction, undefined); - await waitForBatchedUpdates(); - - // Then the edit-splits draft is keyed by the original transaction and rebuilt from the existing children - const editDraft = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${originalTransactionID}`); - expect(editDraft).toBeTruthy(); - expect(editDraft?.comment?.splitExpenses).toHaveLength(2); - - // And no fresh split was started keyed by the child the user opened it from - const freshDraft = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${secondChildTransactionID}`); - expect(freshDraft).toBeFalsy(); - }); }); describe('addSplitExpenseField', () => { diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index 8de001a5bd4a..7f248752a620 100644 --- a/tests/unit/ReportSecondaryActionUtilsTest.ts +++ b/tests/unit/ReportSecondaryActionUtilsTest.ts @@ -3381,61 +3381,6 @@ describe('getSecondaryTransactionThreadActions', () => { expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SPLIT)).toBe(true); }); - it('includes the SPLIT option after the other split half was deleted', async () => { - // Given an open expense report owned by the current user - const report = { - reportID: REPORT_ID, - policyID: POLICY_ID, - type: CONST.REPORT.TYPE.EXPENSE, - ownerAccountID: EMPLOYEE_ACCOUNT_ID, - managerID: EMPLOYEE_ACCOUNT_ID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - } as unknown as Report; - - // And a surviving split child that still references the original (its sibling was unreported then deleted) - const survivingSplit = { - transactionID: 'SURVIVING_SPLIT', - status: CONST.TRANSACTION.STATUS.POSTED, - amount: 50, - merchant: 'Merchant', - date: '2025-01-01', - reportID: REPORT_ID, - comment: {originalTransactionID: 'ORIGINAL_TXN', source: CONST.IOU.TYPE.SPLIT}, - } as unknown as Transaction; - - // And the original ("parent") expense transaction still existing, hidden on the split report - const originalTransaction = { - transactionID: 'ORIGINAL_TXN', - amount: 100, - merchant: 'Merchant', - date: '2025-01-01', - reportID: CONST.REPORT.SPLIT_REPORT_ID, - comment: {}, - } as unknown as Transaction; - - // And the current user is a member of the policy - const policy = { - id: POLICY_ID, - type: CONST.POLICY.TYPE.TEAM, - isPolicyExpenseChatEnabled: true, - employeeList: { - [EMPLOYEE_EMAIL]: {email: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.USER}, - [ADMIN_EMAIL]: {email: ADMIN_EMAIL, role: CONST.POLICY.ROLE.ADMIN}, - }, - role: CONST.POLICY.ROLE.ADMIN, - } as unknown as Policy; - - await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - - // When the secondary transaction-thread actions are computed - const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, EMPLOYEE_ACCOUNT_ID, report, survivingSplit, actionR14932, originalTransaction, policy); - - // Then the SPLIT option is available - expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SPLIT)).toBe(true); - }); - it('does not include the SPLIT option if the current user does not belong to the workspace', async () => { const report = { reportID: REPORT_ID, diff --git a/tests/unit/hooks/useHasMultipleSplitChildren.test.ts b/tests/unit/hooks/useHasMultipleSplitChildren.test.ts deleted file mode 100644 index aa46f0b37834..000000000000 --- a/tests/unit/hooks/useHasMultipleSplitChildren.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -import {renderHook, waitFor} from '@testing-library/react-native'; -import Onyx from 'react-native-onyx'; -import useHasMultipleSplitChildren from '@hooks/useHasMultipleSplitChildren'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import createRandomTransaction from '../../utils/collections/transaction'; - -const ORIGINAL_TRANSACTION_ID = 'ORIGINAL_TXN'; - -function splitChild(id: string, reportID: string, pendingAction?: typeof CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { - return { - ...createRandomTransaction(1), - transactionID: id, - reportID, - pendingAction, - comment: {originalTransactionID: ORIGINAL_TRANSACTION_ID, source: CONST.IOU.TYPE.SPLIT}, - }; -} - -describe('useHasMultipleSplitChildren', () => { - beforeAll(() => { - Onyx.init({keys: ONYXKEYS}); - }); - - beforeEach(async () => { - await Onyx.clear(); - }); - - it('returns false when there is no original transaction', () => { - // Given no original transaction id - // When the hook is rendered - const {result} = renderHook(() => useHasMultipleSplitChildren(undefined)); - - // Then it reports the transaction is not part of a multi-child split - expect(result.current).toBe(false); - }); - - it('returns false when only one split child remains', async () => { - // Given a single split child for the original - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c1`, splitChild('c1', 'REPORT_1')); - - // When the hook is rendered - const {result} = renderHook(() => useHasMultipleSplitChildren(ORIGINAL_TRANSACTION_ID)); - - // Then it is not a multi-child split - await waitFor(() => expect(result.current).toBe(false)); - }); - - it('counts an unreported child so a split with one reported and one unreported half stays a split', async () => { - // Given one split child on a report and one that has been unreported but not deleted - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c1`, splitChild('c1', 'REPORT_1')); - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c2`, splitChild('c2', CONST.REPORT.UNREPORTED_REPORT_ID)); - - // When the hook is rendered - const {result} = renderHook(() => useHasMultipleSplitChildren(ORIGINAL_TRANSACTION_ID)); - - // Then the unreported half still counts, so it is a multi-child split - await waitFor(() => expect(result.current).toBe(true)); - }); - - it('does not count a child that is pending deletion', async () => { - // Given one live split child and one that has been deleted - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c1`, splitChild('c1', 'REPORT_1')); - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c2`, splitChild('c2', CONST.REPORT.UNREPORTED_REPORT_ID, CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)); - - // When the hook is rendered - const {result} = renderHook(() => useHasMultipleSplitChildren(ORIGINAL_TRANSACTION_ID)); - - // Then the split is dissolved (only the live child counts) - await waitFor(() => expect(result.current).toBe(false)); - }); - - it('ignores children that belong to a different original transaction', async () => { - // Given two split children pointing at a different original - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c1`, {...splitChild('c1', 'REPORT_1'), comment: {originalTransactionID: 'OTHER', source: CONST.IOU.TYPE.SPLIT}}); - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}c2`, {...splitChild('c2', 'REPORT_2'), comment: {originalTransactionID: 'OTHER', source: CONST.IOU.TYPE.SPLIT}}); - - // When the hook is rendered for our original - const {result} = renderHook(() => useHasMultipleSplitChildren(ORIGINAL_TRANSACTION_ID)); - - // Then they are not counted - await waitFor(() => expect(result.current).toBe(false)); - }); -}); diff --git a/tests/unit/hooks/useSelectedTransactionsActions.test.ts b/tests/unit/hooks/useSelectedTransactionsActions.test.ts index 0817cc1d454c..becea1f113a8 100644 --- a/tests/unit/hooks/useSelectedTransactionsActions.test.ts +++ b/tests/unit/hooks/useSelectedTransactionsActions.test.ts @@ -904,130 +904,6 @@ describe('useSelectedTransactionsActions', () => { expect(initSplitExpense).toHaveBeenCalled(); }); - it('should show split option after the other split half was deleted', async () => { - // Given an open expense report the current user owns and belongs to - const transactionID = '123'; - const report = { - ...createRandomReport(1, undefined), - type: CONST.REPORT.TYPE.EXPENSE, - ownerAccountID: CURRENT_USER_ACCOUNT_ID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }; - const policy = { - ...createRandomPolicy(1), - isPolicyExpenseChatEnabled: true, - role: CONST.POLICY.ROLE.ADMIN, - employeeList: { - [CURRENT_USER_LOGIN]: {role: CONST.POLICY.ROLE.ADMIN}, - }, - }; - const reportActions: ReportAction[] = []; - - // And a single selected transaction still tagged as a split child - const transaction = { - ...createRandomTransaction(1), - transactionID, - amount: 1000, - status: CONST.TRANSACTION.STATUS.POSTED, - comment: {originalTransactionID: 'ORIGINAL_TXN', source: CONST.IOU.TYPE.SPLIT}, - }; - - mockSelectedTransactionIDs.push(transactionID); - - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); - await Onyx.merge(ONYXKEYS.SESSION, {accountID: CURRENT_USER_ACCOUNT_ID}); - - jest.spyOn(require('@libs/TransactionUtils'), 'getOriginalTransactionWithSplitInfo').mockReturnValue({ - isBillSplit: false, - isExpenseSplit: true, - originalTransaction: transaction, - }); - - // And no siblings remain, so the split has dissolved - jest.spyOn(require('@libs/TransactionUtils'), 'getChildTransactions').mockReturnValue([transaction]); - jest.spyOn(require('@libs/ReportSecondaryActionUtils'), 'isSplitAction').mockReturnValue(true); - - // When the bulk selected-transactions actions are computed - const {result} = renderHook(() => - useSelectedTransactionsActions({ - report, - reportActions, - allTransactionsLength: 1, - policy, - beginExportWithTemplate: mockBeginExportWithTemplate, - }), - ); - - // Then the split option is available - await waitFor(() => { - const splitOption = result.current.options.find((option) => option.value === 'split'); - expect(splitOption).toBeDefined(); - }); - }); - - it('should hide split option for an intact multi-child split', async () => { - // Given an open expense report the current user owns and belongs to - const transactionID = '123'; - const report = { - ...createRandomReport(1, undefined), - type: CONST.REPORT.TYPE.EXPENSE, - ownerAccountID: CURRENT_USER_ACCOUNT_ID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }; - const policy = { - ...createRandomPolicy(1), - isPolicyExpenseChatEnabled: true, - role: CONST.POLICY.ROLE.ADMIN, - employeeList: { - [CURRENT_USER_LOGIN]: {role: CONST.POLICY.ROLE.ADMIN}, - }, - }; - const reportActions: ReportAction[] = []; - - // And a single selected transaction still tagged as a split child - const transaction = { - ...createRandomTransaction(1), - transactionID, - amount: 1000, - status: CONST.TRANSACTION.STATUS.POSTED, - comment: {originalTransactionID: 'ORIGINAL_TXN', source: CONST.IOU.TYPE.SPLIT}, - }; - - mockSelectedTransactionIDs.push(transactionID); - - await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); - await Onyx.merge(ONYXKEYS.SESSION, {accountID: CURRENT_USER_ACCOUNT_ID}); - - jest.spyOn(require('@libs/TransactionUtils'), 'getOriginalTransactionWithSplitInfo').mockReturnValue({ - isBillSplit: false, - isExpenseSplit: true, - originalTransaction: transaction, - }); - - // And siblings still remain, so it is an intact split (edited via "Edit splits", not re-split) - jest.spyOn(require('@libs/TransactionUtils'), 'getChildTransactions').mockReturnValue([transaction, transaction]); - jest.spyOn(require('@libs/ReportSecondaryActionUtils'), 'isSplitAction').mockReturnValue(true); - - // When the bulk selected-transactions actions are computed - const {result} = renderHook(() => - useSelectedTransactionsActions({ - report, - reportActions, - allTransactionsLength: 1, - policy, - beginExportWithTemplate: mockBeginExportWithTemplate, - }), - ); - - // Then the split option is not offered - await waitFor(() => { - expect(result.current.options.length).toBeGreaterThan(0); - }); - expect(result.current.options.find((option) => option.value === 'split')).toBeUndefined(); - }); - it('should show merge option when transaction can be merged', async () => { const transactionID = '123'; const report = createRandomReport(1, undefined);