-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the departmental account icon
- Loading branch information
Michelle Ho
committed
Dec 6, 2024
1 parent
c88af0e
commit fcd19c6
Showing
9 changed files
with
158 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
|
||
import { School } from 'lucide-react'; | ||
import DynamicModal from '@/components/modal/dynamic-modal'; | ||
import { faUser } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; | ||
import User from '@/lib/access/user'; | ||
import Role from '@/lib/access/role'; | ||
|
||
const DeptAccountIcon = ({ currentUser }: { currentUser: User }) => { | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const openDepartmentalModal = () => { | ||
setIsModalOpen(true); | ||
}; | ||
|
||
const closeDepartmentalModal = () => { | ||
setIsModalOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{currentUser.roles.includes(Role.DEPARTMENTAL) && ( | ||
<div | ||
onClick={openDepartmentalModal} | ||
className="flex justify-center items-center rounded-full | ||
h-[45px] w-[45px] bg-seafoam mx-auto relative lg:ml-24" | ||
> | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<FontAwesomeIcon aria-label="user" icon={faUser} width={14} height={16} /> | ||
<div | ||
className="bg-blue-background rounded-full flex justify-center | ||
items-center h-[20px] w-[25px] absolute left-7 bottom-0" | ||
> | ||
<School | ||
className="fill-white stroke-1 p-0.5" | ||
aria-label="Departmental Account Icon" | ||
/> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<p>You are not in your personal account</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</div> | ||
)} | ||
{isModalOpen && ( | ||
<DynamicModal | ||
open={isModalOpen} | ||
title={'Warning'} | ||
body={'You are not in your personal account.'} | ||
buttons={[]} | ||
onClose={closeDepartmentalModal} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default DeptAccountIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ui/tests/components/layout/navbar/dept-account-icon.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import DeptAccountIcon from '@/components/layout/navbar/dept-account-icon'; | ||
import User, { AnonymousUser } from '@/lib/access/user'; | ||
import * as NextCasClient from 'next-cas-client/app'; | ||
import Role from '@/lib/access/role'; | ||
|
||
const testUser: User = JSON.parse(process.env.TEST_USER_A as string); | ||
jest.mock('next-cas-client/app'); | ||
|
||
describe('Dept Account Icon', () => { | ||
it('should render the Departmental Account icon and open warning modal when clicked on', () => { | ||
testUser.roles = [Role.DEPARTMENTAL]; | ||
render(<DeptAccountIcon currentUser={testUser} />); | ||
|
||
fireEvent.focus(document); | ||
expect(screen.getByRole('button', { name: 'Departmental Account Icon' })).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByRole('button', { name: 'Departmental Account Icon' })); | ||
expect(screen.getByRole('alertdialog', { name: 'Warning' })).toBeInTheDocument(); | ||
expect(screen.getByRole('alertdialog')).toHaveTextContent('You are not in your personal account'); | ||
}); | ||
|
||
it('should not render the Departmental Account icon for other roles', () => { | ||
jest.spyOn(NextCasClient, 'getCurrentUser').mockResolvedValue(AnonymousUser); | ||
testUser.roles = [Role.ANONYMOUS, Role.ADMIN, Role.UH, Role.OWNER]; | ||
render(<DeptAccountIcon currentUser={testUser} />); | ||
|
||
fireEvent.focus(document); | ||
expect(screen.queryByRole('button', { name: 'Departmental Account Icon' })).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters