Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - LHN - "Removed 0 user" displayed on #Admins preview when room member leaves room. #54406

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,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 = {
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
...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 = {
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
...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)}`);
});
});
});