Skip to content

Commit de90b2c

Browse files
authored
Merge pull request #89452 from shubham1206agra/refactor-getReportActionMessageFragments
[Internal QA] Refactor: simplified getReportActionMessageFragments to remove dependency from ONYXKEYS.COLLECTION.REPORT Onyx data
2 parents 8f13263 + 1cc32ab commit de90b2c

3 files changed

Lines changed: 2 additions & 65 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,13 +2354,6 @@ function getUpdateRoomDescriptionFragment(translate: LocalizedTranslate, reportA
23542354
}
23552355

23562356
function getReportActionMessageFragments(translate: LocalizedTranslate, action: ReportAction): Message[] {
2357-
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
2358-
const reportID = action.reportID;
2359-
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
2360-
const message = getReimbursedMessage(translate, action, report, deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID);
2361-
return [{text: message, html: `<muted-text>${message}</muted-text>`, type: 'COMMENT'}];
2362-
}
2363-
23642357
if (isOldDotReportAction(action)) {
23652358
const oldDotMessage = getMessageOfOldDotReportAction(translate, action);
23662359
const html = isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SELECTED_FOR_RANDOM_AUDIT) ? Parser.replace(oldDotMessage) : oldDotMessage;

src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ import {
7474
getPolicyChangeLogMaxExpenseAmountNoItemizedReceiptMessage,
7575
getPolicyChangeLogMaxExpenseAmountNoReceiptMessage,
7676
getPolicyChangeLogUpdateEmployee,
77+
getReimbursedMessage,
7778
getReimburserUpdateMessage,
7879
getRemovedCardFeedMessage,
7980
getRemovedConnectionMessage,
8081
getRenamedAction,
8182
getRenamedCardFeedMessage,
8283
getReportAction,
83-
getReportActionMessageFragments,
8484
getReportActionMessageText,
8585
getRequireCompanyCardsEnabledMessage,
8686
getRoomAvatarUpdatedMessage,
@@ -999,7 +999,7 @@ const ContextMenuActions: ContextMenuAction[] = [
999999
} else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED)) {
10001000
Clipboard.setString(getMarkedReimbursedMessage(translate, reportAction));
10011001
} else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
1002-
Clipboard.setString(getReportActionMessageFragments(translate, reportAction).at(0)?.text ?? '');
1002+
Clipboard.setString(getReimbursedMessage(translate, reportAction, report, currentUserPersonalDetails.accountID));
10031003
} else if (isReimbursementQueuedAction(reportAction)) {
10041004
Clipboard.setString(
10051005
getReimbursementQueuedActionMessage({reportAction, translate, formatPhoneNumber: formatPhoneNumberPhoneUtils, report, shouldUseShortDisplayName: false}),

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,62 +1223,6 @@ describe('ReportActionsUtils', () => {
12231223
});
12241224

12251225
describe('getReportActionMessageFragments', () => {
1226-
it('should return the correct fragment for the REIMBURSED action', () => {
1227-
const action = {
1228-
actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
1229-
reportActionID: '1',
1230-
created: '1',
1231-
message: [
1232-
{
1233-
type: 'TEXT',
1234-
style: 'strong',
1235-
text: 'Concierge',
1236-
},
1237-
{
1238-
type: 'TEXT',
1239-
style: 'normal',
1240-
text: ' reimbursed this report',
1241-
},
1242-
{
1243-
type: 'TEXT',
1244-
style: 'normal',
1245-
text: ' on behalf of you',
1246-
},
1247-
{
1248-
type: 'TEXT',
1249-
style: 'normal',
1250-
text: ' from the bank account ending in 1111',
1251-
},
1252-
{
1253-
type: 'TEXT',
1254-
style: 'normal',
1255-
text: '. Money is on its way to your bank account ending in 0000. Reimbursement estimated to complete on Dec 16.',
1256-
},
1257-
],
1258-
};
1259-
const expectedMessage = ReportActionsUtils.getReimbursedMessage(translateLocal, action, undefined, 0);
1260-
const expectedFragments = ReportActionsUtils.getReportActionMessageFragments(translateLocal, action);
1261-
expect(expectedFragments).toEqual([{text: expectedMessage, html: `<muted-text>${expectedMessage}</muted-text>`, type: 'COMMENT'}]);
1262-
});
1263-
1264-
it('should translate the REIMBURSED action using originalMessage.method when paymentMethod is absent (Pusher path)', () => {
1265-
// Given a REIMBURSED action that arrived via Pusher with only `method` set (as Auth stores it)
1266-
const action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSED> = {
1267-
actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
1268-
reportActionID: '2',
1269-
created: '2024-01-01',
1270-
originalMessage: {
1271-
method: 'Check',
1272-
},
1273-
};
1274-
// When we get the message fragments
1275-
const fragments = ReportActionsUtils.getReportActionMessageFragments(translateLocal, action);
1276-
// Then the translated message is used (not raw backend text)
1277-
const expectedMessage = ReportActionsUtils.getReimbursedMessage(translateLocal, action, undefined, 0);
1278-
expect(fragments).toEqual([{text: expectedMessage, html: `<muted-text>${expectedMessage}</muted-text>`, type: 'COMMENT'}]);
1279-
expect(expectedMessage).toContain('check');
1280-
});
1281-
12821226
it('should return the correct fragment for the DYNAMIC_EXTERNAL_WORKFLOW_ROUTED action', () => {
12831227
// Given a DYNAMIC_EXTERNAL_WORKFLOW_ROUTED action
12841228
const action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.DYNAMIC_EXTERNAL_WORKFLOW_ROUTED> = {

0 commit comments

Comments
 (0)