diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index 46943dff4b26d..fac38983df185 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -58,6 +58,11 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona accountID = getAccountIDsByLogins([mentionDisplayText])?.at(0) ?? -1; navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute(), mentionDisplayText); mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); + } else if (!isEmpty(htmlAttribAccountID)) { + // accountID not found in personal details and mention data not provided + accountID = parseInt(htmlAttribAccountID, 10); + mentionDisplayText = getDisplayNameOrDefault(); + navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute()); } else { // If neither an account ID or email is provided, don't render anything return null; diff --git a/tests/unit/MentionUserRendererTest.tsx b/tests/unit/MentionUserRendererTest.tsx index f0052ecd0f360..e134777bbf855 100644 --- a/tests/unit/MentionUserRendererTest.tsx +++ b/tests/unit/MentionUserRendererTest.tsx @@ -8,8 +8,11 @@ import OnyxListItemProvider from '@components/OnyxListItemProvider'; import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import Navigation from '@libs/Navigation/Navigation'; +import CONST from '@src/CONST'; +import IntlStore from '@src/languages/IntlStore'; import ROUTES from '@src/ROUTES'; import type {PersonalDetails} from '@src/types/onyx'; +import {translateLocal} from '../utils/TestHelper'; // Mock Navigation to avoid actual navigation calls jest.mock('@libs/Navigation/Navigation', () => ({ @@ -134,6 +137,7 @@ function buildTNode({accountID, data}: {accountID?: string; data?: string}): TTe describe('MentionUserRenderer', () => { beforeEach(() => { mockPersonalDetails = {}; + IntlStore.load(CONST.LOCALES.DEFAULT); jest.clearAllMocks(); }); @@ -188,6 +192,13 @@ describe('MentionUserRenderer', () => { expect(toJSON()).toBeNull(); }); + test('renders @Hidden when accountID not found in personal details and mention data not provided', () => { + mockPersonalDetails = {}; + const tnode = buildTNode({accountID: '203'}); + renderMention({tnode}); + expect(screen.getByText(`@${translateLocal('common.hidden')}`)).toBeVisible(); + }); + test('navigates to user profile when pressed with accountID', () => { mockPersonalDetails = { 103: {login: 'john@example.com', displayName: 'John Doe'},