diff --git a/src/components/ProfileDropdown/ProfileDropdown.spec.tsx b/src/components/ProfileDropdown/ProfileDropdown.spec.tsx index 06883768e6..769a084f9e 100644 --- a/src/components/ProfileDropdown/ProfileDropdown.spec.tsx +++ b/src/components/ProfileDropdown/ProfileDropdown.spec.tsx @@ -1,7 +1,7 @@ import React, { act } from 'react'; import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { BrowserRouter } from 'react-router-dom'; +import { BrowserRouter, Route, Routes } from 'react-router-dom'; import ProfileDropdown from './ProfileDropdown'; import { MockedProvider } from '@apollo/react-testing'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; @@ -238,7 +238,36 @@ describe('ProfileDropdown Component', () => { expect(mockNavigate).toHaveBeenCalledWith('/user/settings'); }); + test('navigates to /member/:orgId for non-user roles when orgId is not present', async () => { + window.history.pushState({}, 'Test page', '/orglist'); + setItem('SuperAdmin', true); // Set as admin + setItem('id', '123'); + + render( + + + + + } /> + + + + , + ); + + await act(async () => { + userEvent.click(screen.getByTestId('togDrop')); + }); + + await act(async () => { + userEvent.click(screen.getByTestId('profileBtn')); + }); + + expect(mockNavigate).toHaveBeenCalledWith('/member/'); + }); + test('navigates to /member/:userID for non-user roles', async () => { + window.history.pushState({}, 'Test page', '/321'); setItem('SuperAdmin', true); // Set as admin setItem('id', '123'); @@ -246,7 +275,9 @@ describe('ProfileDropdown Component', () => { - + + } /> + , @@ -260,6 +291,6 @@ describe('ProfileDropdown Component', () => { userEvent.click(screen.getByTestId('profileBtn')); }); - expect(mockNavigate).toHaveBeenCalledWith('/member/123'); + expect(mockNavigate).toHaveBeenCalledWith('/member/321'); }); }); diff --git a/src/components/ProfileDropdown/ProfileDropdown.tsx b/src/components/ProfileDropdown/ProfileDropdown.tsx index 059e5b910a..1148b9da8f 100644 --- a/src/components/ProfileDropdown/ProfileDropdown.tsx +++ b/src/components/ProfileDropdown/ProfileDropdown.tsx @@ -1,7 +1,7 @@ import Avatar from 'components/Avatar/Avatar'; import React from 'react'; import { ButtonGroup, Dropdown } from 'react-bootstrap'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useParams } from 'react-router-dom'; import useLocalStorage from 'utils/useLocalstorage'; import styles from './ProfileDropdown.module.css'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; @@ -36,8 +36,8 @@ const profileDropdown = (): JSX.Element => { const firstName = getItem('FirstName'); const lastName = getItem('LastName'); const userImage = getItem('UserImage'); - const userID = getItem('id'); const navigate = useNavigate(); + const { orgId } = useParams(); const logout = async (): Promise => { try { @@ -103,7 +103,7 @@ const profileDropdown = (): JSX.Element => { onClick={() => userRole === 'User' ? navigate(`/user/settings`) - : navigate(`/member/${userID}`) + : navigate(`/member/${orgId || ''}`) } aria-label="View Profile" >