Skip to content

Commit

Permalink
Merge pull request #54406 from FitseTLT/fix-admin-room-lhn-on-externa…
Browse files Browse the repository at this point in the history
…l-user-leaving-room

Fix - LHN - "Removed 0 user" displayed on #Admins preview when room member leaves room.
  • Loading branch information
Gonals authored Feb 12, 2025
2 parents 3aa5143 + 0cef8d8 commit 0a05fc5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ function getOptionData({
result.alternateText = getRenamedAction(lastAction);
} else if (isTaskAction(lastAction)) {
result.alternateText = formatReportLastMessageText(getTaskReportActionMessage(lastAction).text);
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_ROOM) {
const actionMessage = getReportActionMessageText(lastAction);
result.alternateText = actionMessage ? `${lastActorDisplayName}: ${actionMessage}` : '';
} else if (isInviteOrRemovedAction(lastAction)) {
const lastActionOriginalMessage = lastAction?.actionName ? getOriginalMessage(lastAction) : null;
const targetAccountIDs = lastActionOriginalMessage?.targetAccountIDs ?? [];
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import {getReportActionMessageText} from '@libs/ReportActionsUtils';
import SidebarUtils from '@libs/SidebarUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report, ReportAction, ReportActions, TransactionViolation, TransactionViolations} from '@src/types/onyx';
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
import type {TransactionViolationsCollectionDataSet} from '@src/types/onyx/TransactionViolation';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';

describe('SidebarUtils', () => {
beforeAll(() =>
Expand Down Expand Up @@ -334,4 +337,61 @@ describe('SidebarUtils', () => {
expect(result).toBe(false);
});
});

describe('getOptionsData', () => {
it('returns the last action message as an alternate text if the action is POLICYCHANGELOG_LEAVEROOM type', async () => {
// When a report has last action of POLICYCHANGELOG_LEAVEROOM type
const report: Report = {
...createRandomReport(1),
chatType: 'policyAdmins',
lastMessageHtml: 'removed 0 user',
lastMessageText: 'removed 0 user',
lastVisibleActionCreated: '2025-01-20 12:30:03.784',
participants: {
'18921695': {
notificationPreference: 'always',
},
},
};
const lastAction: ReportAction = {
...createRandomReportAction(2),
message: [
{
type: 'COMMENT',
html: '<muted-text>removed <mention-user accountID=19010378></mention-user> from <a href="https://dev.new.expensify.com:8082/r/5345362886584843" target="_blank">#r1</a></muted-text>',
text: 'removed from #r1',
isDeletedParentAction: false,
deleted: '',
},
],
actionName: CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_ROOM,
actorAccountID: 18921695,
person: [
{
type: 'TEXT',
style: 'strong',
text: 'f50',
},
],
originalMessage: undefined,
};
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);

const result = SidebarUtils.getOptionData({
report,
reportActions,
reportNameValuePairs: {},
hasViolations: false,
personalDetails: {},
policy: undefined,
parentReportAction: undefined,
preferredLocale: CONST.LOCALES.EN,
});

// 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)}`);
});
});
});

0 comments on commit 0a05fc5

Please sign in to comment.