Skip to content

Include hidden participants for expense member list #61818

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

Merged
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
3 changes: 1 addition & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2781,8 +2781,7 @@ function getParticipantsAccountIDsForDisplay(

function getParticipantsList(report: Report, personalDetails: OnyxEntry<PersonalDetailsList>, isRoomMembersList = false, reportMetadata: OnyxEntry<ReportMetadata> = undefined): number[] {
const isReportGroupChat = isGroupChat(report);
const isReportIOU = isIOUReport(report);
const shouldExcludeHiddenParticipants = !isReportGroupChat && !isReportIOU;
const shouldExcludeHiddenParticipants = !isReportGroupChat && !isMoneyRequestReport(report) && !isMoneyRequest(report);
const chatParticipants = getParticipantsAccountIDsForDisplay(report, isRoomMembersList || shouldExcludeHiddenParticipants, false, false, reportMetadata);

return chatParticipants.filter((accountID) => {
Expand Down
110 changes: 110 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getIconsForParticipants,
getInvoiceChatByParticipants,
getMostRecentlyVisitedReport,
getParticipantsList,
getPolicyExpenseChat,
getQuickActionDetails,
getReportIDFromLink,
Expand Down Expand Up @@ -57,6 +58,7 @@ import {chatReportR14932 as mockedChatReport} from '../../__mocks__/reportData/r
import * as NumberUtils from '../../src/libs/NumberUtils';
import {convertedInvoiceChat} from '../data/Invoice';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';
import createRandomTransaction from '../utils/collections/transaction';
import * as LHNTestUtils from '../utils/LHNTestUtils';
Expand Down Expand Up @@ -2501,4 +2503,112 @@ describe('ReportUtils', () => {
expect(resultNames).toEqual(expect.arrayContaining(expectedNames));
});
});

describe('getParticipantsList', () => {
it('should exclude hidden participants', () => {
const report: Report = {
...createRandomReport(1),
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const participants = getParticipantsList(report, participantsPersonalDetails);
expect(participants.length).toBe(1);
});

it('should include hidden participants for IOU report', () => {
const report: Report = {
...createRandomReport(1),
type: CONST.REPORT.TYPE.IOU,
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const participants = getParticipantsList(report, participantsPersonalDetails);
expect(participants.length).toBe(2);
});

it('should include hidden participants for expense report', () => {
const report: Report = {
...createRandomReport(1),
type: CONST.REPORT.TYPE.EXPENSE,
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const participants = getParticipantsList(report, participantsPersonalDetails);
expect(participants.length).toBe(2);
});

it('should include hidden participants for IOU transaction report', async () => {
const parentReport: Report = {
...createRandomReport(0),
type: CONST.REPORT.TYPE.IOU,
};
const parentReportAction: ReportAction = {
...createRandomReportAction(0),
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
message: [],
previousMessage: [],
originalMessage: {
amount: 1,
currency: 'USD',
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
},
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, parentReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, {
[parentReportAction.reportActionID]: parentReportAction,
});

const report: Report = {
...createRandomReport(1),
parentReportID: parentReport.reportID,
parentReportActionID: parentReportAction.reportActionID,
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const participants = getParticipantsList(report, participantsPersonalDetails);
expect(participants.length).toBe(2);
});

it('should include hidden participants for expense transaction report', async () => {
const parentReport: Report = {
...createRandomReport(0),
type: CONST.REPORT.TYPE.EXPENSE,
};
const parentReportAction: ReportAction = {
...createRandomReportAction(0),
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
message: [],
previousMessage: [],
originalMessage: {
amount: 1,
currency: 'USD',
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
},
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, parentReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, {
[parentReportAction.reportActionID]: parentReportAction,
});

const report: Report = {
...createRandomReport(1),
parentReportID: parentReport.reportID,
parentReportActionID: parentReportAction.reportActionID,
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const participants = getParticipantsList(report, participantsPersonalDetails);
expect(participants.length).toBe(2);
});
});
});