From e5918c2261e516d3b1bd442af39babd548f45248 Mon Sep 17 00:00:00 2001 From: Abhi Shandilya Date: Tue, 9 Jan 2024 07:59:28 -0500 Subject: [PATCH] test for pages (#164) * transaction id * saving pages * all dashboard layouts --- tests/pages/hospitals/index.test.js | 9 ++++ tests/pages/profile/index.test.js | 9 ++++ tests/pages/saving/[slug].test.js | 11 +++- .../saving/__snapshots__/done.test.js.snap | 8 ++- tests/pages/saving/done.test.js | 52 ++++++++++++++++--- tests/pages/saving/index.test.js | 11 +++- tests/pages/saving/new.test.js | 13 ++++- tests/pages/saving/operation/[saving].test.js | 9 ++++ tests/pages/saving/summary.test.js | 13 ++++- tests/pages/transactions/[id].test.js | 15 ++++-- 10 files changed, 130 insertions(+), 20 deletions(-) diff --git a/tests/pages/hospitals/index.test.js b/tests/pages/hospitals/index.test.js index bb21e5fe..303fb396 100644 --- a/tests/pages/hospitals/index.test.js +++ b/tests/pages/hospitals/index.test.js @@ -3,6 +3,7 @@ import { render } from '@testing-library/react'; import { DrawContext } from '@/pages/_app'; import { SessionProvider } from 'next-auth/react'; require('jest-fetch-mock').enableMocks(); +import DashboardLayout from '../../../layouts/Dashboard'; fetch.mockResponse('[]'); @@ -24,4 +25,12 @@ describe('Hospitals', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(Page.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/profile/index.test.js b/tests/pages/profile/index.test.js index 3fdf7f58..05289720 100644 --- a/tests/pages/profile/index.test.js +++ b/tests/pages/profile/index.test.js @@ -3,6 +3,7 @@ import { render } from '@testing-library/react'; import { DrawContext } from '@/pages/_app'; import { SessionProvider } from 'next-auth/react'; require('jest-fetch-mock').enableMocks(); +import DashboardLayout from '../../../layouts/Dashboard'; fetch.mockResponse('[]'); @@ -24,4 +25,12 @@ describe('Profile', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(Page.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/saving/[slug].test.js b/tests/pages/saving/[slug].test.js index 72b5cb62..6c745a39 100644 --- a/tests/pages/saving/[slug].test.js +++ b/tests/pages/saving/[slug].test.js @@ -2,6 +2,7 @@ import SavingSlug from '@/pages/saving/[slug]'; import { render } from '@testing-library/react'; import { TransactionContext } from '@/components/organisms/Transaction'; import { SessionProvider } from 'next-auth/react'; +import DashboardLayout from '../../../layouts/Dashboard'; jest.mock('next/router', () => ({ useRouter: jest.fn().mockReturnValue({ @@ -17,7 +18,7 @@ describe('Saving', () => { const { container } = render( {} }} + value={{ transaction: {}, setTransaction: () => { } }} > @@ -25,4 +26,12 @@ describe('Saving', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(SavingSlug.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/saving/__snapshots__/done.test.js.snap b/tests/pages/saving/__snapshots__/done.test.js.snap index 62c531c7..b181c07b 100644 --- a/tests/pages/saving/__snapshots__/done.test.js.snap +++ b/tests/pages/saving/__snapshots__/done.test.js.snap @@ -1,6 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Saving should render 1`] = ` +exports[`Saving should render when redirect fails 1`] = ` +
+ Paiement échoué... +
+`; + +exports[`Saving should render when redirect succeeds 1`] = `
({ - useRouter: jest.fn().mockReturnValue({ - query: { - redirect_status: 'succeeded', - }, - }), + useRouter: jest.fn(), })); describe('Saving', () => { - it('should render', () => { + it('should render when redirect succeeds', () => { + useRouter.mockReturnValueOnce({ + query: { + redirect_status: 'succeeded', + }, + }); + + const queryClient = new QueryClient(); + const { container } = render( + + { } }}> + + { } }} + > + + + + + , + ); + expect(container).toMatchSnapshot(); + }); + + it('should render when redirect fails', () => { + useRouter.mockReturnValueOnce({ + query: { + redirect_status: 'failed', + }, + }); + const queryClient = new QueryClient(); const { container } = render( - {} }}> + { } }}> {} }} + value={{ transaction: {}, setTransaction: () => { } }} > @@ -31,4 +59,12 @@ describe('Saving', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(Done.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/saving/index.test.js b/tests/pages/saving/index.test.js index 26288c75..8407472c 100644 --- a/tests/pages/saving/index.test.js +++ b/tests/pages/saving/index.test.js @@ -2,13 +2,14 @@ import Saving from '@/pages/saving'; import { render } from '@testing-library/react'; import { TransactionContext } from '@/components/organisms/Transaction'; import { SessionProvider } from 'next-auth/react'; +import DashboardLayout from '../../../layouts/Dashboard'; describe('Saving', () => { it('should render', () => { const { container } = render( {} }} + value={{ transaction: {}, setTransaction: () => { } }} > @@ -16,4 +17,12 @@ describe('Saving', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(Saving.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/saving/new.test.js b/tests/pages/saving/new.test.js index 0eec72c1..9fc4d97b 100644 --- a/tests/pages/saving/new.test.js +++ b/tests/pages/saving/new.test.js @@ -4,6 +4,7 @@ import { TransactionContext } from '@/components/organisms/Transaction'; import { SessionProvider } from 'next-auth/react'; import { DrawContext } from '../../../pages/_app'; import { QueryClientProvider, QueryClient } from 'react-query'; +import DashboardLayout from '../../../layouts/Dashboard'; jest.mock('next/router', () => ({ useRouter: jest.fn().mockReturnValue({ @@ -16,10 +17,10 @@ describe('Saving', () => { const queryClient = new QueryClient(); const { container } = render( - {} }}> + { } }}> {} }} + value={{ transaction: {}, setTransaction: () => { } }} > @@ -29,4 +30,12 @@ describe('Saving', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(NewSaving.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/saving/operation/[saving].test.js b/tests/pages/saving/operation/[saving].test.js index eb230b33..e85b8f28 100644 --- a/tests/pages/saving/operation/[saving].test.js +++ b/tests/pages/saving/operation/[saving].test.js @@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react"; import Page from "@/pages/saving/operation/[saving]"; import { SessionProvider } from "next-auth/react"; import { QueryClient, QueryClientProvider } from "react-query"; +import DashboardLayout from "../../../../layouts/Dashboard"; jest.mock('next/router', () => ({ useRouter: jest.fn().mockReturnValue({ @@ -28,4 +29,12 @@ describe("Page", () => { const pageTitle = screen.getAllByText("Récharger mon épargne"); expect(pageTitle).toHaveLength(2); }); + + it('should use DashboardLayout as layout', () => { + expect(Page.getLayout(
)).toEqual( + +
+ , + ); + }); }); \ No newline at end of file diff --git a/tests/pages/saving/summary.test.js b/tests/pages/saving/summary.test.js index 8260e0f2..d2010154 100644 --- a/tests/pages/saving/summary.test.js +++ b/tests/pages/saving/summary.test.js @@ -4,6 +4,7 @@ import { TransactionContext } from '@/components/organisms/Transaction'; import { SessionProvider } from 'next-auth/react'; import { DrawContext } from '../../../pages/_app'; import { QueryClientProvider, QueryClient } from 'react-query'; +import DashboardLayout from '../../../layouts/Dashboard'; require('jest-fetch-mock').enableMocks(); @@ -24,13 +25,13 @@ describe('Saving Summary', () => { {}, + setDraw: () => { }, saving: { plan: { currency: 'GBP' }, target: { currency: 'USD' } }, }} > {} }} + value={{ transaction: {}, setTransaction: () => { } }} > @@ -41,4 +42,12 @@ describe('Saving Summary', () => { ); expect(container).toMatchSnapshot(); }); + + it('should use DashboardLayout as layout', () => { + expect(SavingSummary.getLayout(
)).toEqual( + +
+ , + ); + }); }); diff --git a/tests/pages/transactions/[id].test.js b/tests/pages/transactions/[id].test.js index a5c797e9..3a583c2b 100644 --- a/tests/pages/transactions/[id].test.js +++ b/tests/pages/transactions/[id].test.js @@ -1,10 +1,15 @@ import Page from '@/pages/transactions/[id]'; -import { render } from '@testing-library/react'; +import DashboardLayout from '../../../layouts/Dashboard'; + describe('Transactions id page', () => { it.todo('should render the page'); - // it('should render the page', () => { - // const { container } = render(); - // expect(container).toMatchSnapshot(); - // }); + + it('should have DashboardLayout', () => { + expect(Page.getLayout(
)).toEqual( + +
+ + ); + }); });