From 2272cd3b07c1dc7d4af2fafb359501d2ff426e4f Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 23 Oct 2023 13:28:07 -0400 Subject: [PATCH] test: item bottom navigation --- components/molecules/Navbar/ItemBottom.js | 10 ++-- .../molecules/Navbar/ItemBottom.test.js | 50 ++++++++++++++----- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/components/molecules/Navbar/ItemBottom.js b/components/molecules/Navbar/ItemBottom.js index 4649bc0a..76577f30 100644 --- a/components/molecules/Navbar/ItemBottom.js +++ b/components/molecules/Navbar/ItemBottom.js @@ -16,9 +16,8 @@ const ItemBottom = ({ title, icon, link, activePath }) => { {link ? ( ) : ( {icon({ size: 20 })}
{title}
diff --git a/components/molecules/Navbar/ItemBottom.test.js b/components/molecules/Navbar/ItemBottom.test.js index 89493c53..fe2d96a6 100644 --- a/components/molecules/Navbar/ItemBottom.test.js +++ b/components/molecules/Navbar/ItemBottom.test.js @@ -1,24 +1,28 @@ -import { render } from '@testing-library/react'; +import "@testing-library/jest-dom"; +import { render, screen } from '@testing-library/react'; import ItemBottom from './ItemBottom'; import { DrawContext } from '@/pages/_app'; import { SessionProvider } from 'next-auth/react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { SlHome } from 'react-icons/sl'; +import NextRouter from 'next/router' -jest.mock('next/router', () => ({ - useRouter: jest.fn().mockReturnValue({ - query: { - 'payment-intent': 'pi_1J4JrjGswQjYFZwX0Z1Z1Z1Z', - }, - }), -})); - describe('ItemBottom', () => { - it('should render the component', () => { - const { container } = render( + let container; + let routerSpy; + const pushMock = jest.fn(); + const setDrawMock = jest.fn(); + + beforeEach(() => { + + routerSpy = jest.spyOn(NextRouter, 'useRouter').mockReturnValue({ + push: pushMock, + }); + + const res = render( - + { , ); + + container = res.container; + }); + + it('should render the component', () => { expect(container).toMatchSnapshot(); }); + + it('should navigate to the link', () => { + + + const h6 = screen.getByText('Accueil'); + + expect(h6).toBeInTheDocument(); + h6.click(); + + expect(pushMock).toHaveBeenCalledTimes(1); + expect(pushMock).toHaveBeenCalledWith('/'); + + expect(setDrawMock).toHaveBeenCalledTimes(1); + expect(setDrawMock).toHaveBeenCalledWith(false); + }); + + });