Skip to content

Commit 2aa69b1

Browse files
authored
Merge pull request #86245 from dukenv0307/fix/66411-part-15
refactor getChatListItemReportName to use conciergeReportID from useOnyx
2 parents f26fe42 + a120e72 commit 2aa69b1

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12886,7 +12886,7 @@ function isWaitingForSubmissionFromCurrentUser(chatReport: OnyxEntry<Report>, po
1288612886
return chatReport?.isOwnPolicyExpenseChat && !policy?.harvesting?.enabled;
1288712887
}
1288812888

12889-
function getChatListItemReportName(action: ReportAction & {reportName?: string}, report: Report | undefined): string {
12889+
function getChatListItemReportName(action: ReportAction & {reportName?: string}, report: Report | undefined, conciergeReportID: string | undefined): string {
1289012890
if (report && isInvoiceReport(report)) {
1289112891
const properInvoiceReport = report;
1289212892
properInvoiceReport.chatReportID = report.parentReportID;
@@ -12901,12 +12901,12 @@ function getChatListItemReportName(action: ReportAction & {reportName?: string},
1290112901
if (report?.reportID) {
1290212902
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
1290312903
// eslint-disable-next-line @typescript-eslint/no-deprecated
12904-
return getReportName({report: getReport(report?.reportID, allReports)});
12904+
return getReportName({report: getReport(report?.reportID, allReports), conciergeReportID});
1290512905
}
1290612906

1290712907
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
1290812908
// eslint-disable-next-line @typescript-eslint/no-deprecated
12909-
return getReportName({report});
12909+
return getReportName({report, conciergeReportID});
1291012910
}
1291112911

1291212912
/**

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ function PureReportActionItem({
552552

553553
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
554554
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
555+
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
555556
const {transitionActionSheetState} = ActionSheetAwareScrollView.useActionSheetAwareScrollViewActions();
556557
const {translate, formatPhoneNumber, localeCompare, formatTravelDate, getLocalDateFromDatetime} = useLocalize();
557558
const {showConfirmModal} = useConfirmModal();
@@ -2044,7 +2045,7 @@ function PureReportActionItem({
20442045
}}
20452046
numberOfLines={1}
20462047
>
2047-
{getChatListItemReportName(action, report)}
2048+
{getChatListItemReportName(action, report, conciergeReportID)}
20482049
</TextLink>
20492050
</View>
20502051
{children}

tests/unit/ReportUtilsTest.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
getAvailableReportFields,
7575
getBillableAndTaxTotal,
7676
getChatByParticipants,
77+
getChatListItemReportName,
7778
getChatRoomSubtitle,
7879
getDefaultWorkspaceAvatar,
7980
getDisplayNameForParticipant,
@@ -15078,6 +15079,65 @@ describe('ReportUtils', () => {
1507815079
});
1507915080
});
1508015081

15082+
describe('getChatListItemReportName', () => {
15083+
const conciergeReportID = 'concierge-report-123';
15084+
15085+
beforeEach(async () => {
15086+
await Onyx.clear();
15087+
await waitForBatchedUpdates();
15088+
});
15089+
15090+
it('should return CONCIERGE_DISPLAY_NAME when conciergeReportID matches report ID', async () => {
15091+
const conciergeReport: Report = {
15092+
reportID: conciergeReportID,
15093+
type: CONST.REPORT.TYPE.CHAT,
15094+
};
15095+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`, conciergeReport);
15096+
await waitForBatchedUpdates();
15097+
15098+
const action = {...createRandomReportAction(1)};
15099+
const result = getChatListItemReportName(action, conciergeReport, conciergeReportID);
15100+
expect(result).toBe(CONST.CONCIERGE_DISPLAY_NAME);
15101+
});
15102+
15103+
it('should not return CONCIERGE_DISPLAY_NAME when conciergeReportID does not match report ID', async () => {
15104+
const regularReport: Report = {
15105+
reportID: 'regular-report-456',
15106+
type: CONST.REPORT.TYPE.CHAT,
15107+
reportName: 'Regular Chat',
15108+
};
15109+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${regularReport.reportID}`, regularReport);
15110+
await waitForBatchedUpdates();
15111+
15112+
const action = {...createRandomReportAction(2)};
15113+
const result = getChatListItemReportName(action, regularReport, conciergeReportID);
15114+
expect(result).not.toBe(CONST.CONCIERGE_DISPLAY_NAME);
15115+
});
15116+
15117+
it('should return action.reportName when set, regardless of conciergeReportID', () => {
15118+
const conciergeReport: Report = {
15119+
reportID: conciergeReportID,
15120+
type: CONST.REPORT.TYPE.CHAT,
15121+
};
15122+
const action = {...createRandomReportAction(3), reportName: 'Custom Action Name'};
15123+
const result = getChatListItemReportName(action, conciergeReport, conciergeReportID);
15124+
expect(result).toBe('Custom Action Name');
15125+
});
15126+
15127+
it('should use Onyx-connected conciergeReportID when explicit parameter is undefined', async () => {
15128+
const conciergeReport: Report = {
15129+
reportID: conciergeReportID,
15130+
type: CONST.REPORT.TYPE.CHAT,
15131+
};
15132+
await Onyx.set(ONYXKEYS.CONCIERGE_REPORT_ID, conciergeReportID);
15133+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`, conciergeReport);
15134+
await waitForBatchedUpdates();
15135+
15136+
const action = {...createRandomReportAction(4)};
15137+
const result = getChatListItemReportName(action, conciergeReport, undefined);
15138+
expect(result).toBe(CONST.CONCIERGE_DISPLAY_NAME);
15139+
});
15140+
});
1508115141
describe('buildOptimisticApprovedReportAction', () => {
1508215142
it('should set actorAccountID to the provided currentUserAccountID', () => {
1508315143
const customAccountID = 99;

0 commit comments

Comments
 (0)