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
11 changes: 4 additions & 7 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,19 +699,16 @@ function getWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>)
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = getDisplayNamesWithTooltips(getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), isMultipleParticipant);
const displayNamesWithTooltipsText = displayNamesWithTooltips
.map(({displayName, pronouns}, index) => {
const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`;

.map(({displayName}, index) => {
if (index === displayNamesWithTooltips.length - 1) {
return `${formattedText}.`;
return `${displayName}.`;
}
if (index === displayNamesWithTooltips.length - 2) {
return `${formattedText} ${translateLocal('common.and')}`;
return `${displayName} ${translateLocal('common.and')}`;
}
if (index < displayNamesWithTooltips.length - 2) {
return `${formattedText},`;
return `${displayName},`;
}

return '';
})
.join(' ');
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

describe('SidebarUtils', () => {
beforeAll(() =>
Expand Down Expand Up @@ -338,6 +340,29 @@ describe('SidebarUtils', () => {
});
});

describe('getWelcomeMessage', () => {
it('do not return pronouns in the welcome message text when it is group chat', async () => {
const MOCK_REPORT: Report = {
...LHNTestUtils.getFakeReport(),
chatType: 'group',
type: 'chat',
};
return (
waitForBatchedUpdates()
// When Onyx is updated to contain that report
.then(() =>
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
}),
)
.then(() => {
const result = SidebarUtils.getWelcomeMessage(MOCK_REPORT, undefined);
expect(result.messageText).toBe('This chat is with One and Two.');
})
);
});
});

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
Expand Down
5 changes: 3 additions & 2 deletions tests/utils/LHNTestUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {EnvironmentProvider} from '@components/withEnvironment';
import {CurrentReportIDContextProvider} from '@hooks/useCurrentReportID';
import {ReportIDsContextProvider} from '@hooks/useReportIDs';
import DateUtils from '@libs/DateUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {buildParticipantsFromAccountIDs} from '@libs/ReportUtils';
import ReportActionItemSingle from '@pages/home/report/ReportActionItemSingle';
import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -64,6 +64,7 @@ const fakePersonalDetails: PersonalDetailsList = {
displayName: 'Email Two',
avatar: 'none',
firstName: 'Two',
pronouns: '__predefined_sheHerHers',
},
3: {
accountID: 3,
Expand Down Expand Up @@ -133,7 +134,7 @@ let lastFakeTransactionID = 0;
function getFakeReport(participantAccountIDs = [1, 2], millisecondsInThePast = 0, isUnread = false, adminIDs: number[] = []): Report {
const lastVisibleActionCreated = DateUtils.getDBTime(Date.now() - millisecondsInThePast);

const participants = ReportUtils.buildParticipantsFromAccountIDs(participantAccountIDs);
const participants = buildParticipantsFromAccountIDs(participantAccountIDs);

adminIDs.forEach((id) => {
participants[id] = {
Expand Down