mirror of
https://github.com/SomboChea/ui
synced 2024-11-28 00:44:30 +07:00
refactor: adds missing test spec for button click in not found (#222)
* refactor: adds missing test spec for button click in not found * refactor: improves test description
This commit is contained in:
parent
a38b93e127
commit
531295a6d0
@ -27,7 +27,7 @@ const StyledHeading = styled(Typography)({
|
|||||||
const NotFound: React.FC = () => {
|
const NotFound: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const handleGomHome = useCallback(() => {
|
const handleGoHome = useCallback(() => {
|
||||||
history.push('/');
|
history.push('/');
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ const NotFound: React.FC = () => {
|
|||||||
<StyledHeading className="not-found-text" variant="h4">
|
<StyledHeading className="not-found-text" variant="h4">
|
||||||
{NOT_FOUND_TEXT}
|
{NOT_FOUND_TEXT}
|
||||||
</StyledHeading>
|
</StyledHeading>
|
||||||
<Button onClick={handleGomHome} variant="contained">
|
<Button onClick={handleGoHome} variant="contained">
|
||||||
{GO_TO_HOME_PAGE}
|
{GO_TO_HOME_PAGE}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import { render } from '@testing-library/react';
|
import { render, fireEvent } from '@testing-library/react';
|
||||||
|
|
||||||
import NotFound from './NotFound';
|
import NotFound, { GO_TO_HOME_PAGE } from './NotFound';
|
||||||
|
|
||||||
describe('<NotFound /> component', () => {
|
describe('<NotFound /> component', () => {
|
||||||
test('should load the component in default state', () => {
|
test('should load the component in default state', () => {
|
||||||
@ -13,5 +13,17 @@ describe('<NotFound /> component', () => {
|
|||||||
);
|
);
|
||||||
expect(container.firstChild).toMatchSnapshot();
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
test.todo('Test Button Click');
|
test('go to Home Page button click', () => {
|
||||||
|
const spy = jest.spyOn(React, 'useCallback');
|
||||||
|
const { getByText } = render(
|
||||||
|
<Router>
|
||||||
|
<NotFound />
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
|
||||||
|
const node = getByText(GO_TO_HOME_PAGE);
|
||||||
|
fireEvent.click(node);
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user