-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cd3a4e
commit 814b2f0
Showing
11 changed files
with
202 additions
and
98 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,26 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { Header } from './Header'; | ||
|
||
const mockNavigate = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => mockNavigate, | ||
})); | ||
|
||
describe('components/Header.tsx', () => { | ||
it('should render itself & its children', () => { | ||
const tree = render(<Header>Test Header</Header>); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should navigate back', () => { | ||
render(<Header>Test Header</Header>); | ||
|
||
fireEvent.click(screen.getByLabelText('Go Back')); | ||
expect(mockNavigate).toHaveBeenNthCalledWith(1, -1); | ||
|
||
expect(mockNavigate).toHaveBeenCalledTimes(1); | ||
expect(mockNavigate).toHaveBeenCalledWith(-1); | ||
}); | ||
}); |
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,29 @@ | ||
import { ArrowLeftIcon } from '@primer/octicons-react'; | ||
import type { ReactNode } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
interface IHeader { | ||
children: ReactNode; | ||
} | ||
|
||
export const Header = ({ children }: IHeader) => { | ||
const navigate = useNavigate(); | ||
return ( | ||
<div className="mx-8 mt-4 flex items-center justify-between py-2"> | ||
<button | ||
type="button" | ||
className="focus:outline-none" | ||
title="Go Back" | ||
onClick={() => navigate(-1)} | ||
> | ||
<ArrowLeftIcon | ||
size={20} | ||
className="hover:text-gray-400" | ||
aria-label="Go Back" | ||
/> | ||
</button> | ||
|
||
<h3 className="text-lg font-semibold">{children}</h3> | ||
</div> | ||
); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.