-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create BackToCluster button component (#837)
* Create BackToCluster button component * Move back button code to its own component * Make BackButton generic * Add jest test to BackButton
- Loading branch information
Showing
5 changed files
with
64 additions
and
36 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 React from 'react'; | ||
import Button from '@components/Button'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { EOS_ARROW_BACK } from 'eos-icons-react'; | ||
|
||
export const BackButton = ({ children, url }) => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<div className="flex mb-8"> | ||
<div className="flex w-2/5"> | ||
<Button | ||
className="w-2/3 text-jungle-green-500 text-left py-0 px-0" | ||
size="small" | ||
type="transparent" | ||
onClick={() => navigate(url)} | ||
> | ||
<EOS_ARROW_BACK className="inline-block fill-jungle-green-500" /> | ||
{children} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BackButton; |
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,21 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import * as router from 'react-router'; | ||
|
||
import BackButton from './'; | ||
|
||
const navigate = jest.fn(); | ||
|
||
describe('BackButton', () => { | ||
it('should display a back button with correct text and url', () => { | ||
jest.spyOn(router, 'useNavigate').mockImplementation(() => navigate); | ||
|
||
render(<BackButton url="/back/hell">Back to hell!</BackButton>); | ||
const backButton = screen.getByRole('button'); | ||
expect(backButton).toHaveTextContent('Back to hell!'); | ||
|
||
fireEvent.click(backButton); | ||
expect(navigate).toHaveBeenCalledWith('/back/hell'); | ||
}); | ||
}); |
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,3 @@ | ||
import BackButton from './BackButton'; | ||
|
||
export default BackButton; |
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