From d50649c5da273e0b36fce62c0b8d01795072a1ae Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 17 Feb 2025 09:32:12 +0700 Subject: [PATCH 1/3] fix: LHN - Pronouns are displayed in the LHN preview of the group chat --- src/libs/SidebarUtils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index f6234da9263a1..6e9a1711f57d5 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -699,19 +699,16 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) 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(' '); From fafc43fcdebd864e5c56690130a4041a80b6809c Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 17 Feb 2025 15:18:45 +0700 Subject: [PATCH 2/3] fix: add new test for getWelcomeMessage --- tests/unit/SidebarUtilsTest.ts | 25 +++++++++++++++++++++++++ tests/utils/LHNTestUtils.tsx | 1 + 2 files changed, 26 insertions(+) diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index b6660d0c02162..8ad784d724517 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -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(() => @@ -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 diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index 2818aa49545f5..fdf794c4a5f0d 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -64,6 +64,7 @@ const fakePersonalDetails: PersonalDetailsList = { displayName: 'Email Two', avatar: 'none', firstName: 'Two', + pronouns: '__predefined_sheHerHers', }, 3: { accountID: 3, From baec00bb599c9f85c3b76addd59ae65e3df7f1f6 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 17 Feb 2025 16:01:11 +0700 Subject: [PATCH 3/3] fix lint --- tests/utils/LHNTestUtils.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index fdf794c4a5f0d..22e3c9ee67f32 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -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'; @@ -134,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] = {