From c909e9562e3a05da18925b8cfcf88ba58723ec2e Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Tue, 29 Apr 2025 12:26:29 +0530 Subject: [PATCH 1/2] fix last message for report for moved action --- src/libs/OptionsListUtils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5b8028c9a3ed..9b76d0dca732 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -789,7 +789,11 @@ function getLastMessageTextForReport( lastMessageTextFromReport = getUpgradeWorkspaceMessage(); } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.TEAM_DOWNGRADE) { lastMessageTextFromReport = getDowngradeWorkspaceMessage(); - } else if (isActionableAddPaymentCard(lastReportAction) || isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY)) { + } else if ( + isActionableAddPaymentCard(lastReportAction) || + isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY) || + isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.MOVED) + ) { lastMessageTextFromReport = getReportActionMessageText(lastReportAction); } else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION) { lastMessageTextFromReport = getExportIntegrationLastMessageText(lastReportAction); From 2712df8489b1af703a3673286c42773217ab422a Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Tue, 29 Apr 2025 13:06:37 +0530 Subject: [PATCH 2/2] add test for moved action --- tests/unit/SidebarUtilsTest.ts | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index e3a8595cbd93..1a7683dd68da 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -798,6 +798,72 @@ describe('SidebarUtils', () => { // Then the alternate text should be equal to the message of the last action prepended with the last actor display name. expect(result?.alternateText).toBe(`You invited 1 member`); }); + it('returns the last action message as an alternate text if the action is MOVED type', async () => { + // When a report has last action of MOVED type + const policy: Policy = { + ...createRandomPolicy(1), + pendingAction: null, + }; + const session = { + authToken: 'sensitive-auth-token', + encryptedAuthToken: 'sensitive-encrypted-token', + email: 'user@example.com', + accountID: 12345, + }; + const report: Report = { + ...createRandomReport(4), + chatType: 'policyRoom', + lastMessageHtml: '', + lastMessageText: '', + lastVisibleActionCreated: '2025-04-27 12:30:03.784', + participants: { + '12345': { + notificationPreference: 'daily', + }, + }, + policyID: '1', + }; + const lastAction: ReportAction = { + ...createRandomReportAction(2), + message: [ + { + type: 'COMMENT', + html: "moved this report to the Three's Workspace workspace", + text: "moved this report to the Three's Workspace workspace", + isEdited: false, + whisperedTo: [], + isDeletedParentAction: false, + deleted: '', + }, + ], + originalMessage: { + lastModified: '2025-04-27 12:32:10.416', + targetAccountIDs: [19268914], + }, + actorAccountID: 12345, + actionName: CONST.REPORT.ACTIONS.TYPE.MOVED, + }; + const reportActions: ReportActions = {[lastAction.reportActionID]: lastAction}; + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, reportActions); + await Onyx.set(ONYXKEYS.SESSION, session); + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}1`, policy); + const result = SidebarUtils.getOptionData({ + report, + reportAttributes: {}, + reportActions, + reportNameValuePairs: {}, + hasViolations: false, + personalDetails: {}, + policy: undefined, + parentReportAction: undefined, + preferredLocale: CONST.LOCALES.EN, + oneTransactionThreadReport: undefined, + }); + + // Then the alternate text should be equal to the message of the last action prepended with the last actor display name. + expect(result?.alternateText).toBe(`${lastAction.person?.[0].text}: ${getReportActionMessageText(lastAction)}`); + }); }); }); });