diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 2cf7c3150e79..67b54910165c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7071,6 +7071,9 @@ function startSplitBill({ Navigation.dismissModalWithReport({reportID: splitChatReport.reportID}); notifyNewAction(splitChatReport.reportID, currentUserAccountID); + + // Return the split transactionID for testing purpose + return {splitTransactionID: splitTransaction.transactionID}; } /** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above. @@ -7083,12 +7086,16 @@ function startSplitBill({ */ function completeSplitBill( chatReportID: string, - reportAction: OnyxTypes.ReportAction, + reportAction: OnyxEntry, updatedTransaction: OnyxEntry, sessionAccountID: number, sessionEmail?: string, ) { - const parsedComment = getParsedComment(updatedTransaction?.comment?.comment ?? ''); + if (!reportAction) { + return; + } + + const parsedComment = getParsedComment(Parser.htmlToMarkdown(updatedTransaction?.comment?.comment ?? '')); if (updatedTransaction?.comment) { // eslint-disable-next-line no-param-reassign updatedTransaction.comment.comment = parsedComment; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 8cf87fd84688..3fb70d1acdd7 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -13,6 +13,7 @@ import { cancelPayment, canIOUBePaid, canUnapproveIOU, + completeSplitBill, createDistanceRequest, deleteMoneyRequest, getIOUReportActionToApproveOrPay, @@ -28,6 +29,7 @@ import { setDraftSplitTransaction, setMoneyRequestCategory, splitBill, + startSplitBill, submitReport, trackExpense, unholdRequest, @@ -2314,6 +2316,63 @@ describe('actions/IOU', () => { }); expect(report?.participants?.[RORY_ACCOUNT_ID].notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS); }); + + it('the description should not be parsed again after completing the scan split bill without changing the description', async () => { + const reportID = '1'; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { + reportID, + type: CONST.REPORT.TYPE.CHAT, + chatType: CONST.REPORT.CHAT_TYPE.GROUP, + participants: { + [RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + [CARLOS_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS}, + }, + }); + + // Start a scan split bill + const {splitTransactionID} = startSplitBill({ + participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}], + currentUserLogin: RORY_EMAIL, + currentUserAccountID: RORY_ACCOUNT_ID, + comment: '# test', + currency: CONST.CURRENCY.USD, + existingSplitChatReportID: reportID, + receipt: {}, + category: undefined, + tag: undefined, + taxCode: '', + taxAmount: 0, + }); + + await waitForBatchedUpdates(); + + let splitTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransactionID}`); + + // Then the description should be parsed correctly + expect(splitTransaction?.comment?.comment).toBe('

test

'); + + const updatedSplitTransaction = splitTransaction + ? { + ...splitTransaction, + amount: 100, + } + : undefined; + + const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); + const iouAction = Object.values(reportActions ?? {}).find((action) => isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU)); + + expect(iouAction).toBeTruthy(); + + // Complete this split bill without changing the description + completeSplitBill(reportID, iouAction, updatedSplitTransaction, RORY_ACCOUNT_ID, RORY_EMAIL); + + await waitForBatchedUpdates(); + + splitTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransactionID}`); + + // Then the description should be the same since it was not changed + expect(splitTransaction?.comment?.comment).toBe('

test

'); + }); }); describe('saveSplitTransactions', () => {