From 5fc26d2a85b4a344df79490bd84875730b37aefa Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 24 Jul 2025 23:44:14 +0700 Subject: [PATCH 1/4] fix: description with mark down is displayed in HTML tags on the expense preview --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 53a321417c26..e53b76482097 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7067,7 +7067,7 @@ function completeSplitBill( sessionAccountID: number, sessionEmail?: string, ) { - const parsedComment = getParsedComment(updatedTransaction?.comment?.comment ?? ''); + const parsedComment = getParsedComment(Parser.htmlToMarkdown(updatedTransaction?.comment?.comment ?? '')); if (updatedTransaction?.comment) { // eslint-disable-next-line no-param-reassign updatedTransaction.comment.comment = parsedComment; From 54d20f82fbe5678a86fdc9a721a0224a81f90986 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 28 Jul 2025 14:38:21 +0700 Subject: [PATCH 2/4] add unit test --- src/libs/actions/IOU.ts | 9 +++++- tests/actions/IOUTest.ts | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 59d8374269ee..7bc2354370df 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7050,6 +7050,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. @@ -7062,11 +7065,15 @@ function startSplitBill({ */ function completeSplitBill( chatReportID: string, - reportAction: OnyxTypes.ReportAction, + reportAction: OnyxEntry, updatedTransaction: OnyxEntry, sessionAccountID: number, sessionEmail?: string, ) { + if (!reportAction) { + return; + } + const parsedComment = getParsedComment(Parser.htmlToMarkdown(updatedTransaction?.comment?.comment ?? '')); if (updatedTransaction?.comment) { // eslint-disable-next-line no-param-reassign diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index d1fdfdc7d289..5800b43772d8 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('should update the description correctly when completing the split bill', 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 + expect(splitTransaction?.comment?.comment).toBe('

test

'); + }); }); describe('saveSplitTransactions', () => { From 0cf6d17ef27b842792033fd2fa14e75181fcb656 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 28 Jul 2025 14:41:32 +0700 Subject: [PATCH 3/4] fix lint --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 5800b43772d8..4bf4ed88bb1a 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -2358,7 +2358,7 @@ describe('actions/IOU', () => { } : undefined; - const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); + 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(); From 9ac3cd7ca7bfdcfecc6154282e6b0063368b154b Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Tue, 29 Jul 2025 21:46:52 +0700 Subject: [PATCH 4/4] update explain comment --- tests/actions/IOUTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 4bf4ed88bb1a..1e88431cb3da 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -2317,7 +2317,7 @@ describe('actions/IOU', () => { expect(report?.participants?.[RORY_ACCOUNT_ID].notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS); }); - it('should update the description correctly when completing the split bill', async () => { + 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, @@ -2370,7 +2370,7 @@ describe('actions/IOU', () => { splitTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransactionID}`); - // Then the description should be the same + // Then the description should be the same since it was not changed expect(splitTransaction?.comment?.comment).toBe('

test

'); }); });