Skip to content

Commit b73ebe2

Browse files
authored
Merge pull request Expensify#67107 from mkzie2/mkzie2-issue/65889
fix: description with mark down is displayed in HTML tags on the expense preview
2 parents 9e28913 + 083732d commit b73ebe2

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7073,6 +7073,9 @@ function startSplitBill({
70737073

70747074
Navigation.dismissModalWithReport({reportID: splitChatReport.reportID});
70757075
notifyNewAction(splitChatReport.reportID, currentUserAccountID);
7076+
7077+
// Return the split transactionID for testing purpose
7078+
return {splitTransactionID: splitTransaction.transactionID};
70767079
}
70777080

70787081
/** Used for editing a split expense while it's still scanning or when SmartScan fails, it completes a split expense started by startSplitBill above.
@@ -7085,12 +7088,16 @@ function startSplitBill({
70857088
*/
70867089
function completeSplitBill(
70877090
chatReportID: string,
7088-
reportAction: OnyxTypes.ReportAction,
7091+
reportAction: OnyxEntry<OnyxTypes.ReportAction>,
70897092
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>,
70907093
sessionAccountID: number,
70917094
sessionEmail?: string,
70927095
) {
7093-
const parsedComment = getParsedComment(updatedTransaction?.comment?.comment ?? '');
7096+
if (!reportAction) {
7097+
return;
7098+
}
7099+
7100+
const parsedComment = getParsedComment(Parser.htmlToMarkdown(updatedTransaction?.comment?.comment ?? ''));
70947101
if (updatedTransaction?.comment) {
70957102
// eslint-disable-next-line no-param-reassign
70967103
updatedTransaction.comment.comment = parsedComment;

tests/actions/IOUTest.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
cancelPayment,
1414
canIOUBePaid,
1515
canUnapproveIOU,
16+
completeSplitBill,
1617
createDistanceRequest,
1718
deleteMoneyRequest,
1819
getIOUReportActionToApproveOrPay,
@@ -28,6 +29,7 @@ import {
2829
setDraftSplitTransaction,
2930
setMoneyRequestCategory,
3031
splitBill,
32+
startSplitBill,
3133
submitReport,
3234
trackExpense,
3335
unholdRequest,
@@ -2315,6 +2317,63 @@ describe('actions/IOU', () => {
23152317
});
23162318
expect(report?.participants?.[RORY_ACCOUNT_ID].notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS);
23172319
});
2320+
2321+
it('the description should not be parsed again after completing the scan split bill without changing the description', async () => {
2322+
const reportID = '1';
2323+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
2324+
reportID,
2325+
type: CONST.REPORT.TYPE.CHAT,
2326+
chatType: CONST.REPORT.CHAT_TYPE.GROUP,
2327+
participants: {
2328+
[RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
2329+
[CARLOS_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
2330+
},
2331+
});
2332+
2333+
// Start a scan split bill
2334+
const {splitTransactionID} = startSplitBill({
2335+
participants: [{accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}],
2336+
currentUserLogin: RORY_EMAIL,
2337+
currentUserAccountID: RORY_ACCOUNT_ID,
2338+
comment: '# test',
2339+
currency: CONST.CURRENCY.USD,
2340+
existingSplitChatReportID: reportID,
2341+
receipt: {},
2342+
category: undefined,
2343+
tag: undefined,
2344+
taxCode: '',
2345+
taxAmount: 0,
2346+
});
2347+
2348+
await waitForBatchedUpdates();
2349+
2350+
let splitTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransactionID}`);
2351+
2352+
// Then the description should be parsed correctly
2353+
expect(splitTransaction?.comment?.comment).toBe('<h1>test</h1>');
2354+
2355+
const updatedSplitTransaction = splitTransaction
2356+
? {
2357+
...splitTransaction,
2358+
amount: 100,
2359+
}
2360+
: undefined;
2361+
2362+
const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
2363+
const iouAction = Object.values(reportActions ?? {}).find((action) => isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU));
2364+
2365+
expect(iouAction).toBeTruthy();
2366+
2367+
// Complete this split bill without changing the description
2368+
completeSplitBill(reportID, iouAction, updatedSplitTransaction, RORY_ACCOUNT_ID, RORY_EMAIL);
2369+
2370+
await waitForBatchedUpdates();
2371+
2372+
splitTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransactionID}`);
2373+
2374+
// Then the description should be the same since it was not changed
2375+
expect(splitTransaction?.comment?.comment).toBe('<h1>test</h1>');
2376+
});
23182377
});
23192378

23202379
describe('saveSplitTransactions', () => {

0 commit comments

Comments
 (0)