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
9 changes: 9 additions & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,15 @@ function getLastMessageTextForReport(
lastMessageTextFromReport = getReportActionMessageText(lastReportAction);
}

if (reportID) {
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
// If the report is a one-transaction report, get the last message text from combined report actions so the LHN can display modifications to the transaction thread or the report itself
const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]);
if (transactionThreadReportID) {
lastMessageTextFromReport = getReportActionMessageText(lastReportAction);
}
}

return lastMessageTextFromReport || (report?.lastMessageText ?? '');
}

Expand Down
68 changes: 66 additions & 2 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import DateUtils from '@libs/DateUtils';
import {getReportActionMessageText} from '@libs/ReportActionsUtils';
import {getOriginalMessage, getReportActionMessageText} from '@libs/ReportActionsUtils';
import {getAllReportErrors} from '@libs/ReportUtils';
import SidebarUtils from '@libs/SidebarUtils';
import initOnyxDerivedValues from '@userActions/OnyxDerived';
Expand All @@ -13,7 +13,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx';
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
import type {TransactionViolationsCollectionDataSet} from '@src/types/onyx/TransactionViolation';
import {chatReportR14932} from '../../__mocks__/reportData/reports';
import {actionR14932 as mockIOUAction} from '../../__mocks__/reportData/actions';
import {chatReportR14932, iouReportR14932} from '../../__mocks__/reportData/reports';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';
Expand Down Expand Up @@ -1125,6 +1126,69 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
});

expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`);
});
it('returns the last action message as an alternate text if the expense report is the one expense report', async () => {
const IOUTransactionID = `${ONYXKEYS.COLLECTION.TRANSACTION}TRANSACTION_IOU` as const;

iouReportR14932.reportID = '5';
chatReportR14932.reportID = '6';
iouReportR14932.lastActorAccountID = undefined;

const report: Report = {
...createRandomReport(1),
chatType: 'policyExpenseChat',
pendingAction: null,
isOwnPolicyExpenseChat: true,
parentReportID: iouReportR14932.reportID,
parentReportActionID: mockIOUAction.reportActionID,
lastActorAccountID: undefined,
};

const linkedCreateAction: ReportAction = {
...mockIOUAction,
originalMessage: {...getOriginalMessage(mockIOUAction), IOUTransactionID},
childReportID: report.reportID,
reportActionID: '3',
};

const lastAction: ReportAction = {
...createRandomReportAction(1),
message: [
{
type: 'COMMENT',
html: 'test action',
text: 'test action',
},
],
originalMessage: {
whisperedTo: [],
},

created: DateUtils.getDBTime(),
lastModified: DateUtils.getDBTime(),
shouldShow: true,
pendingAction: null,
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
actorAccountID: undefined,
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReportR14932.reportID}`, iouReportR14932);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReportR14932.reportID}`, chatReportR14932);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[lastAction.reportActionID]: lastAction});
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportR14932.reportID}`, {[linkedCreateAction.reportActionID]: linkedCreateAction});

const result = SidebarUtils.getOptionData({
report: iouReportR14932,
reportAttributes: undefined,
reportNameValuePairs: {},
personalDetails: {},
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
});

expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`);
});
});
Expand Down
Loading