diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0beabb7b0db1f..776627d166f92 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5268,7 +5268,7 @@ function getReportNameInternal({ // Not a room or PolicyExpenseChat, generate title from first 5 other participants formattedName = buildReportNameFromParticipantNames({report, personalDetails}); - return isArchivedNonExpense ? generateArchivedReportName(formattedName) : formattedName; + return isArchivedNonExpense ? generateArchivedReportName(formattedName) : formattedName || (report?.reportName ?? ''); } /** diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 760ea8005f972..715c7874b9e98 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -721,6 +721,50 @@ describe('ReportUtils', () => { expect(getReportName(expenseChatReport)).toEqual("Ragnar Lothbrok's expenses"); }); }); + + describe('Fallback scenarios', () => { + test('should fallback to report.reportName when primary name generation returns empty string', () => { + const reportWithFallbackName: Report = { + reportID: '3', + reportName: 'Custom Report Name', + ownerAccountID: undefined, + participants: {}, + policyID: undefined, + chatType: undefined, + }; + + const result = getReportName(reportWithFallbackName); + expect(result).toBe('Custom Report Name'); + }); + + test('should return empty string when both primary name generation and reportName are empty', () => { + const reportWithoutName: Report = { + reportID: '4', + reportName: '', + ownerAccountID: undefined, + participants: {}, + policyID: undefined, + chatType: undefined, + }; + + const result = getReportName(reportWithoutName); + expect(result).toBe(''); + }); + + test('should return empty string when reportName is undefined', () => { + const reportWithUndefinedName: Report = { + reportID: '5', + reportName: undefined, + ownerAccountID: undefined, + participants: {}, + policyID: undefined, + chatType: undefined, + }; + + const result = getReportName(reportWithUndefinedName); + expect(result).toBe(''); + }); + }); }); describe('requiresAttentionFromCurrentUser', () => {