Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -7083,12 +7086,16 @@ function startSplitBill({
*/
function completeSplitBill(
chatReportID: string,
reportAction: OnyxTypes.ReportAction,
reportAction: OnyxEntry<OnyxTypes.ReportAction>,
updatedTransaction: OnyxEntry<OnyxTypes.Transaction>,
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;
Expand Down
59 changes: 59 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
cancelPayment,
canIOUBePaid,
canUnapproveIOU,
completeSplitBill,
createDistanceRequest,
deleteMoneyRequest,
getIOUReportActionToApproveOrPay,
Expand All @@ -28,6 +29,7 @@ import {
setDraftSplitTransaction,
setMoneyRequestCategory,
splitBill,
startSplitBill,
submitReport,
trackExpense,
unholdRequest,
Expand Down Expand Up @@ -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('<h1>test</h1>');

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('<h1>test</h1>');
});
});

describe('saveSplitTransactions', () => {
Expand Down