Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Links of sidebar_menu now working at view_profile_section #3086

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
37 changes: 34 additions & 3 deletions src/components/ProfileDropdown/ProfileDropdown.spec.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -238,15 +238,46 @@ 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(
<MockedProvider mocks={MOCKS} addTypename={false}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<Routes>
<Route path="/orglist" element={<ProfileDropdown />} />
</Routes>
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);

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');

render(
<MockedProvider mocks={MOCKS} addTypename={false}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<ProfileDropdown />
<Routes>
<Route path="/:orgId" element={<ProfileDropdown />} />
</Routes>
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
Expand All @@ -260,6 +291,6 @@ describe('ProfileDropdown Component', () => {
userEvent.click(screen.getByTestId('profileBtn'));
});

expect(mockNavigate).toHaveBeenCalledWith('/member/123');
expect(mockNavigate).toHaveBeenCalledWith('/member/321');
});
});
6 changes: 3 additions & 3 deletions src/components/ProfileDropdown/ProfileDropdown.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<void> => {
try {
Expand Down Expand Up @@ -103,7 +103,7 @@ const profileDropdown = (): JSX.Element => {
onClick={() =>
userRole === 'User'
? navigate(`/user/settings`)
: navigate(`/member/${userID}`)
: navigate(`/member/${orgId || ''}`)
}
aria-label="View Profile"
>
Expand Down
Loading