From 4fc97ed2ac02686d4282fc17672098afd0d2b945 Mon Sep 17 00:00:00 2001 From: Pratap Rathi Date: Mon, 30 Dec 2024 20:16:50 +0530 Subject: [PATCH 1/2] fix: Links of sidebar_menu now working at view_profile_section --- src/components/ProfileDropdown/ProfileDropdown.spec.tsx | 9 ++++++--- src/components/ProfileDropdown/ProfileDropdown.tsx | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/ProfileDropdown/ProfileDropdown.spec.tsx b/src/components/ProfileDropdown/ProfileDropdown.spec.tsx index 06883768e6..5e083bbdf8 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'; @@ -239,6 +239,7 @@ describe('ProfileDropdown Component', () => { }); 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 +247,9 @@ describe('ProfileDropdown Component', () => { - + + } /> + , @@ -260,6 +263,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" > From 7e3a8e60dd2a826c53d999bfecb831a7612cea5d Mon Sep 17 00:00:00 2001 From: Pratap Rathi Date: Mon, 30 Dec 2024 21:16:37 +0530 Subject: [PATCH 2/2] Added Test when no organisation is selected --- .../ProfileDropdown/ProfileDropdown.spec.tsx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/ProfileDropdown/ProfileDropdown.spec.tsx b/src/components/ProfileDropdown/ProfileDropdown.spec.tsx index 5e083bbdf8..769a084f9e 100644 --- a/src/components/ProfileDropdown/ProfileDropdown.spec.tsx +++ b/src/components/ProfileDropdown/ProfileDropdown.spec.tsx @@ -238,6 +238,34 @@ 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