From d24e79a5d7ebc5109e64078431647c28899723a7 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Mon, 23 Feb 2026 22:40:31 +0530 Subject: [PATCH] Fixed report name computation for some reportActions --- src/libs/ReportNameUtils.ts | 18 ++-- tests/unit/ReportUtilsTest.ts | 169 ++++++++++++++++++++++++++++++---- 2 files changed, 159 insertions(+), 28 deletions(-) diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index ab2010c5bd442..94faee8cb13f0 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -393,7 +393,7 @@ function computeReportNameBasedOnReportAction( ) { const harvesting = !isMarkAsClosedAction(parentReportAction) ? (getOriginalMessage(parentReportAction)?.harvesting ?? false) : false; if (harvesting) { - return translate('iou.automaticallySubmitted'); + return Parser.htmlToText(translate('iou.automaticallySubmitted')); } return translate('iou.submitted', getOriginalMessage(parentReportAction)?.message); } @@ -401,7 +401,7 @@ function computeReportNameBasedOnReportAction( if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) { const {automaticAction} = getOriginalMessage(parentReportAction) ?? {}; if (automaticAction) { - return translate('iou.automaticallyForwarded'); + return Parser.htmlToText(translate('iou.automaticallyForwarded')); } return translate('iou.forwarded'); } @@ -566,7 +566,7 @@ function computeReportNameBasedOnReportAction( } if (isMovedAction(parentReportAction)) { - return getMovedActionMessage(translate, parentReportAction, parentReport); + return Parser.htmlToText(getMovedActionMessage(translate, parentReportAction, parentReport)); } if ( @@ -591,13 +591,13 @@ function computeReportNameBasedOnReportAction( } if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.VBBA) { if (originalMessage.automaticAction) { - return translate('iou.automaticallyPaidWithBusinessBankAccount', undefined, last4Digits); + return Parser.htmlToText(translate('iou.automaticallyPaidWithBusinessBankAccount', undefined, last4Digits)); } return translate('iou.businessBankAccount', undefined, last4Digits); } if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { if (originalMessage.automaticAction) { - return translate('iou.automaticallyPaidWithExpensify'); + return Parser.htmlToText(translate('iou.automaticallyPaidWithExpensify')); } return translate('iou.paidWithExpensify'); } @@ -607,7 +607,7 @@ function computeReportNameBasedOnReportAction( if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) { const {automaticAction} = getOriginalMessage(parentReportAction) ?? {}; if (automaticAction) { - return translate('iou.automaticallyApproved'); + return Parser.htmlToText(translate('iou.automaticallyApproved')); } return translate('iou.approvedMessage'); } @@ -629,11 +629,11 @@ function computeReportNameBasedOnReportAction( } if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.COMPANY_CARD_CONNECTION_BROKEN)) { - return getCompanyCardConnectionBrokenMessage(translate, parentReportAction); + return Parser.htmlToText(getCompanyCardConnectionBrokenMessage(translate, parentReportAction)); } if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.PLAID_BALANCE_FAILURE)) { - return getPlaidBalanceFailureMessage(translate, parentReportAction); + return Parser.htmlToText(getPlaidBalanceFailureMessage(translate, parentReportAction)); } if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.TRAVEL_UPDATE)) { @@ -651,7 +651,7 @@ function computeReportNameBasedOnReportAction( } if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SETTLEMENT_ACCOUNT_LOCKED)) { - return getSettlementAccountLockedMessage(translate, parentReportAction); + return Parser.htmlToText(getSettlementAccountLockedMessage(translate, parentReportAction)); } return undefined; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 4f287a8d154bd..f3f785e5f57ab 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1307,9 +1307,9 @@ describe('ReportUtils', () => { const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}; const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}}; - expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe( - 'approved via workspace rules', - ); + + // Note: computeReportName returns the text version, not HTML + expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('approved via workspace rules'); }); test('shown when the report is approved', () => { @@ -1334,9 +1334,9 @@ describe('ReportUtils', () => { const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}; const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}}; - expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe( - 'approved via workspace rules', - ); + + // Note: computeReportName returns the text version, not HTML + expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('approved via workspace rules'); }); }); @@ -1363,9 +1363,9 @@ describe('ReportUtils', () => { const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}; const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}}; - expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe( - 'submitted via delay submissions', - ); + + // Note: computeReportName returns the text version, not HTML + expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('submitted via delay submissions'); }); test('shown when report is submitted and status is closed', () => { @@ -1390,9 +1390,9 @@ describe('ReportUtils', () => { const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}; const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}}; - expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe( - 'submitted via delay submissions', - ); + + // Note: computeReportName returns the text version, not HTML + expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('submitted via delay submissions'); }); }); @@ -2227,9 +2227,9 @@ describe('ReportUtils', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[vbbaPayAction.reportActionID]: vbbaPayAction}, }; const reportName = computeReportName(threadReport, undefined, policies, undefined, undefined, participantsPersonalDetails, reportActions); - expect(reportName).toBe( - 'paid with bank account 7890 via workspace rules', - ); + + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('paid with bank account 7890 via workspace rules'); }); test('should return forwarded action name', () => { @@ -2275,9 +2275,8 @@ describe('ReportUtils', () => { }; const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); - expect(reportName).toBe( - 'approved via workspace rules', - ); + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('approved via workspace rules'); }); test('should return submitted action name', () => { @@ -2401,10 +2400,142 @@ describe('ReportUtils', () => { }; const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('The Regions Bank cards connection is broken. To restore card imports, log into your bank.'); + }); + + test('should handle automatically paid with Expensify action', () => { + const expensifyPayAction: ReportAction = { + ...baseParentReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + originalMessage: { + type: CONST.IOU.REPORT_ACTION_TYPE.PAY, + paymentType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY, + automaticAction: true, + }, + }; + + const threadReport: Report = { + ...baseExpenseReport, + parentReportID: baseChatReport.reportID, + parentReportActionID: expensifyPayAction.reportActionID, + }; + + const reportActions = { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[expensifyPayAction.reportActionID]: expensifyPayAction}, + }; + const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('paid with Expensify via workspace rules'); + }); + + test('should handle plaid balance failure action', () => { + const plaidBalanceFailureAction: ReportAction = { + ...baseParentReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.PLAID_BALANCE_FAILURE, + originalMessage: { + maskedAccountNumber: '****1234', + policyID: '1', + }, + }; + + const threadReport: Report = { + ...baseExpenseReport, + parentReportID: baseChatReport.reportID, + parentReportActionID: plaidBalanceFailureAction.reportActionID, + }; + + const reportActions = { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[plaidBalanceFailureAction.reportActionID]: plaidBalanceFailureAction}, + }; + const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + + // Note: computeReportName returns the text version, not HTML expect(reportName).toBe( - `The Regions Bank cards connection is broken. To restore card imports, log into your bank.`, + 'the Plaid connection to your business bank account is broken. Please reconnect your bank account ****1234 so you can continue to use your Expensify Cards.', ); }); + + test('should handle settlement account locked action', () => { + const settlementAccountLockedAction: ReportAction = { + ...baseParentReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.SETTLEMENT_ACCOUNT_LOCKED, + originalMessage: { + maskedBankAccountNumber: '****5678', + policyID: 'policy1', + }, + }; + + const threadReport: Report = { + ...baseExpenseReport, + parentReportID: baseChatReport.reportID, + parentReportActionID: settlementAccountLockedAction.reportActionID, + }; + + const reportActions = { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[settlementAccountLockedAction.reportActionID]: settlementAccountLockedAction}, + }; + const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe( + 'business bank account ****5678 has been automatically locked due to an issue with either Reimbursement or Expensify Card settlement. Please fix the issue in your workspace settings.', + ); + }); + + test('should handle automatically forwarded action', () => { + const autoForwardedAction: ReportAction = { + ...baseParentReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.FORWARDED, + originalMessage: { + amount: 169, + currency: 'USD', + automaticAction: true, + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + }, + }; + + const threadReport: Report = { + ...baseExpenseReport, + parentReportID: baseChatReport.reportID, + parentReportActionID: autoForwardedAction.reportActionID, + }; + + const reportActions = { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[autoForwardedAction.reportActionID]: autoForwardedAction}, + }; + const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('approved via workspace rules'); + }); + + test('should handle automatically submitted via harvesting action', () => { + const autoSubmittedAction: ReportAction = { + ...baseParentReportAction, + actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, + originalMessage: { + harvesting: true, + amount: 1000, + currency: 'USD', + }, + }; + + const threadReport: Report = { + ...baseExpenseReport, + parentReportID: baseChatReport.reportID, + parentReportActionID: autoSubmittedAction.reportActionID, + }; + + const reportActions = { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[autoSubmittedAction.reportActionID]: autoSubmittedAction}, + }; + const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions); + + // Note: computeReportName returns the text version, not HTML + expect(reportName).toBe('submitted via delay submissions'); + }); }); describe('Invoices', () => {