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
10 changes: 10 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7284,6 +7284,16 @@ function getMovedActionMessage(translate: LocalizedTranslate, action: ReportActi
}
const {toPolicyID, newParentReportID, movedReportID} = movedActionOriginalMessage;
const toPolicyName = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${toPolicyID}`]?.name ?? '';

// The destination policy may not be available locally (e.g. the current user isn't a member of it and never opened it),
// which would render the message with a blank workspace name. In that case, fall back to the server-rendered action
// message, which already contains the name, until the policy is delivered locally.
if (!toPolicyName) {
const storedHtml = getReportActionHtml(action);
if (storedHtml) {
return storedHtml;
}
}
return translate('iou.movedAction', !isDM(report), getReportURLForCurrentContext(movedReportID), getReportURLForCurrentContext(newParentReportID), toPolicyName);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ui/ReportActionItemTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,15 @@ describe('ReportActionItem', () => {

describe('System notification actions', () => {
it('MOVED action renders moved message', async () => {
// Seed the destination policy locally so the message is computed live (the member scenario).
// Without a local policy, getMovedActionMessage falls back to the stored action HTML.
await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}policy1`, {
id: 'policy1',
name: 'Test Workspace',
});
});

const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.MOVED, {
toPolicyID: 'policy1',
newParentReportID: 'report2',
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20572,6 +20572,34 @@ describe('ReportUtils', () => {
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

it('should fall back to the stored action message when the destination policy is not available locally', () => {
const storedHtml = 'moved this report to the <a href="https://new.expensify.com">Test Workspace</a> workspace';
const action = createMock<ReportAction>({
...LHNTestUtils.getFakeReportAction(),
actionName: CONST.REPORT.ACTIONS.TYPE.MOVED,
message: [
{
type: 'COMMENT',
html: storedHtml,
text: 'moved this report to the Test Workspace workspace',
isEdited: false,
whisperedTo: [],
isDeletedParentAction: false,
},
],
originalMessage: {
// A policy ID that is intentionally not present in Onyx, mirroring a non-member user.
toPolicyID: '99999999',
newParentReportID: '11111',
movedReportID: '22222',
},
});

const report = LHNTestUtils.getFakeReport();
const result = getMovedActionMessage(translateLocal, action, report);
expect(result).toBe(storedHtml);
});
});
describe('getReportActionWithSmartscanError', () => {
const chatReportID = '100';
Expand Down
Loading