Skip to content

Commit

Permalink
test for pages (#164)
Browse files Browse the repository at this point in the history
* transaction id

* saving pages

* all dashboard layouts
  • Loading branch information
abhiShandy authored Jan 9, 2024
1 parent 5bb8a7c commit e5918c2
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 20 deletions.
9 changes: 9 additions & 0 deletions tests/pages/hospitals/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[]');

Expand All @@ -24,4 +25,12 @@ describe('Hospitals', () => {
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(Page.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
9 changes: 9 additions & 0 deletions tests/pages/profile/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[]');

Expand All @@ -24,4 +25,12 @@ describe('Profile', () => {
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(Page.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
11 changes: 10 additions & 1 deletion tests/pages/saving/[slug].test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -17,12 +18,20 @@ describe('Saving', () => {
const { container } = render(
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => {} }}
value={{ transaction: {}, setTransaction: () => { } }}
>
<SavingSlug />
</TransactionContext.Provider>
</SessionProvider>,
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(SavingSlug.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
8 changes: 7 additions & 1 deletion tests/pages/saving/__snapshots__/done.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Saving should render 1`] = `
exports[`Saving should render when redirect fails 1`] = `
<div>
Paiement échoué...
</div>
`;

exports[`Saving should render when redirect succeeds 1`] = `
<div>
<div
class="flex flex-col gap-3 items-center mt-14"
Expand Down
52 changes: 44 additions & 8 deletions tests/pages/saving/done.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,52 @@ 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';
import { useRouter } from 'next/router';

jest.mock('next/router', () => ({
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(
<QueryClientProvider client={queryClient}>
<DrawContext.Provider value={{ draw: {}, setDraw: () => { } }}>
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => { } }}
>
<Done />
</TransactionContext.Provider>
</SessionProvider>
</DrawContext.Provider>
</QueryClientProvider>,
);
expect(container).toMatchSnapshot();
});

it('should render when redirect fails', () => {
useRouter.mockReturnValueOnce({
query: {
redirect_status: 'failed',
},
});

const queryClient = new QueryClient();
const { container } = render(
<QueryClientProvider client={queryClient}>
<DrawContext.Provider value={{ draw: {}, setDraw: () => {} }}>
<DrawContext.Provider value={{ draw: {}, setDraw: () => { } }}>
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => {} }}
value={{ transaction: {}, setTransaction: () => { } }}
>
<Done />
</TransactionContext.Provider>
Expand All @@ -31,4 +59,12 @@ describe('Saving', () => {
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(Done.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
11 changes: 10 additions & 1 deletion tests/pages/saving/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@ 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(
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => {} }}
value={{ transaction: {}, setTransaction: () => { } }}
>
<Saving />
</TransactionContext.Provider>
</SessionProvider>,
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(Saving.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
13 changes: 11 additions & 2 deletions tests/pages/saving/new.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -16,10 +17,10 @@ describe('Saving', () => {
const queryClient = new QueryClient();
const { container } = render(
<QueryClientProvider client={queryClient}>
<DrawContext.Provider value={{ draw: {}, setDraw: () => {} }}>
<DrawContext.Provider value={{ draw: {}, setDraw: () => { } }}>
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => {} }}
value={{ transaction: {}, setTransaction: () => { } }}
>
<NewSaving />
</TransactionContext.Provider>
Expand All @@ -29,4 +30,12 @@ describe('Saving', () => {
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(NewSaving.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
9 changes: 9 additions & 0 deletions tests/pages/saving/operation/[saving].test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
13 changes: 11 additions & 2 deletions tests/pages/saving/summary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -24,13 +25,13 @@ describe('Saving Summary', () => {
<DrawContext.Provider
value={{
draw: {},
setDraw: () => {},
setDraw: () => { },
saving: { plan: { currency: 'GBP' }, target: { currency: 'USD' } },
}}
>
<SessionProvider session={{ user: { data: { access_token: {} } } }}>
<TransactionContext.Provider
value={{ transaction: {}, setTransaction: () => {} }}
value={{ transaction: {}, setTransaction: () => { } }}
>
<QueryClientProvider client={queryClient}>
<SavingSummary />
Expand All @@ -41,4 +42,12 @@ describe('Saving Summary', () => {
);
expect(container).toMatchSnapshot();
});

it('should use DashboardLayout as layout', () => {
expect(SavingSummary.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>,
);
});
});
15 changes: 10 additions & 5 deletions tests/pages/transactions/[id].test.js
Original file line number Diff line number Diff line change
@@ -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(<Page />);
// expect(container).toMatchSnapshot();
// });

it('should have DashboardLayout', () => {
expect(Page.getLayout(<div />)).toEqual(
<DashboardLayout className="space-y-8">
<div />
</DashboardLayout>
);
});
});

1 comment on commit e5918c2

@vercel
Copy link

@vercel vercel bot commented on e5918c2 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wii-qare-fe – ./

wii-qare-fe-git-main-wiiqare.vercel.app
wii-qare-fe.vercel.app
wii-qare-fe-wiiqare.vercel.app

Please sign in to comment.