From 74377428fa582832f09f6872816edbc058b0e090 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 2 Oct 2025 00:28:54 +0700 Subject: [PATCH 1/2] fix: IOU details are not visible preview on Search --- src/libs/OptionsListUtils/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 3f69aac71008..9aa29feccd1a 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -451,13 +451,13 @@ function shouldShowLastActorDisplayName(report: OnyxEntry, lastActorDeta /** * Update alternate text for the option when applicable */ -function getAlternateText(option: OptionData, {showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig) { +function getAlternateText(option: OptionData, {showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig, lastActorDetails: Partial | null = {}) { const report = getReportOrDraftReport(option.reportID); const isAdminRoom = reportUtilsIsAdminRoom(report); const isAnnounceRoom = reportUtilsIsAnnounceRoom(report); const isGroupChat = reportUtilsIsGroupChat(report); const isExpenseThread = isMoneyRequest(report); - const formattedLastMessageText = formatReportLastMessageText(option.lastMessageText ?? ''); + const formattedLastMessageText = formatReportLastMessageText(Parser.htmlToText(option.lastMessageText ?? '')) || getLastMessageTextForReport({report, lastActorDetails}); const reportPrefix = getReportSubtitlePrefix(report); const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText; @@ -839,8 +839,9 @@ function createOption( subtitle = getChatRoomSubtitle(report, true, !!result.private_isArchived); // If displaying chat preview line is needed, let's overwrite the default alternate text - result.alternateText = showPersonalDetails && personalDetail?.login ? personalDetail.login : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}); - + const lastActorDetails = personalDetails?.[report?.lastActorAccountID ?? String(CONST.DEFAULT_NUMBER_ID)]; + result.alternateText = + showPersonalDetails && personalDetail?.login ? personalDetail.login : getAlternateText(result, {showChatPreviewLine, forcePolicyNamePreview}, lastActorDetails); reportName = showPersonalDetails ? getDisplayNameForParticipant({accountID: accountIDs.at(0)}) || formatPhoneNumber(personalDetail?.login ?? '') : getReportName(report); } else { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing From b977aba744a4000c2980f68045d1500e5969ff8e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 2 Oct 2025 14:33:22 +0700 Subject: [PATCH 2/2] add unit test --- src/libs/OptionsListUtils/index.ts | 1 + tests/unit/OptionsListUtilsTest.tsx | 122 +++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 9aa29feccd1a..9f5b4ec7fc0a 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2588,6 +2588,7 @@ export { combineOrderingOfReportsAndPersonalDetails, createOptionFromReport, createOptionList, + createOption, filterAndOrderOptions, filterOptions, filterReports, diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 106351717887..ee1bdee8f2c2 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -10,6 +10,7 @@ import DateUtils from '@libs/DateUtils'; import type {OptionList, Options, SearchOption} from '@libs/OptionsListUtils'; import { canCreateOptimisticPersonalDetailOption, + createOption, createOptionList, filterAndOrderOptions, filterReports, @@ -35,7 +36,7 @@ import initOnyxDerivedValues from '@userActions/OnyxDerived'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetails, Policy, Report} from '@src/types/onyx'; +import type {PersonalDetails, Policy, Report, ReportAction, Transaction} from '@src/types/onyx'; import {getFakeAdvancedReportAction} from '../utils/LHNTestUtils'; import {localeCompare} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -2081,4 +2082,123 @@ describe('OptionsListUtils', () => { expect(result).toBe(''); }); }); + + describe('createOption', () => { + it('should return alternative text correctly when the last action is report preview action', async () => { + const report = { + chatType: '', + currency: 'USD', + description: '', + errorFields: {}, + hasOutstandingChildRequest: false, + hasOutstandingChildTask: false, + iouReportID: '456', + lastMessageHtml: '', + lastMessageText: '', + participants: { + '1': { + notificationPreference: 'always', + }, + '2': { + notificationPreference: 'always', + }, + }, + reportID: '123', + type: 'chat', + lastActorAccountID: 1, + } as unknown as Report; + + const reportPreviewAction = { + actionName: 'REPORTPREVIEW', + actorAccountID: 1, + childManagerAccountID: 2, + childOwnerAccountID: 1, + childReportID: '456', + childReportName: 'IOU', + created: '2025-10-02 06:50:36.302', + reportActionID: '12345678', + shouldShow: true, + message: [ + { + html: 'Iron Man owes ₫34', + text: 'Iron Man owes ₫34', + type: 'COMMENT', + whisperedTo: [], + }, + ], + } as unknown as ReportAction; + + const iouReport = { + chatReportID: '123', + currency: 'VND', + managerID: 2, + ownerAccountID: 1, + parentReportActionID: '12345678', + parentReportID: '123', + participants: { + '19960856': { + notificationPreference: '', + }, + '20669492': { + notificationPreference: '', + }, + }, + reportID: '456', + reportName: 'IOU', + total: 3400, + } as unknown as Report; + + const iouAction = { + actorAccountID: 1, + message: [ + { + type: 'COMMENT', + html: '₫34 expense', + text: '₫34 expense', + isEdited: false, + whisperedTo: [], + isDeletedParentAction: false, + deleted: '', + reactions: [], + }, + ], + originalMessage: { + IOUReportID: '456', + IOUTransactionID: '123456', + amount: 3400, + comment: '', + currency: 'VND', + participantAccountIDs: [1, 2], + }, + actionName: 'IOU', + reportActionID: '789', + } as unknown as ReportAction; + + const transaction = { + transactionID: '123456', + amount: 3400, + currency: 'VND', + reportID: '3993091505909230', + comment: { + comment: '', + }, + merchant: '(none)', + created: '2025-10-02', + category: '', + taxAmount: 0, + reimbursable: true, + } as unknown as Transaction; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[reportPreviewAction.reportActionID]: reportPreviewAction}); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, iouReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, {[iouAction.reportActionID]: iouAction}); + await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); + await waitForBatchedUpdates(); + + const result = createOption([1, 2], PERSONAL_DETAILS, report, {showChatPreviewLine: true}); + + expect(result.alternateText).toBe('Iron Man owes ₫34'); + }); + }); });