diff --git a/mocks/AppWithProvider.jsx b/mocks/AppWithProvider.jsx index 46096f2..a81bb3c 100644 --- a/mocks/AppWithProvider.jsx +++ b/mocks/AppWithProvider.jsx @@ -2,12 +2,12 @@ import App from "@/pages/_app"; import fa from "&/locales/fa/app.json" const translations = {fa}; -const MockAppWithProviders = ({Component, locale, title, isBot}) => { +const MockAppWithProviders = ({children, locale, title, isBot}) => { const pageProps = { title: title || '', isBot: isBot || true, locale: locale || 'fa', messages: translations[locale || 'fa'] } - - return () + + return ( (<>{children})} pageProps={pageProps}/>) } export default MockAppWithProviders \ No newline at end of file diff --git a/src/components/first/__tests__/index.test.js b/src/components/first/__tests__/index.test.js index 987b7c5..7e60576 100644 --- a/src/components/first/__tests__/index.test.js +++ b/src/components/first/__tests__/index.test.js @@ -1,6 +1,6 @@ +import FirstComponent from "@/components/first"; import {render, screen} from "@testing-library/react"; import MockAppWithProviders from "../../../../mocks/AppWithProvider"; -import FirstComponent from "@/components/first"; import {server} from "../../../../mocks/server"; import {rest} from "msw"; import {GET_USER_ROUTE} from "@/core/data/apiRoutes"; @@ -8,33 +8,31 @@ import {GET_USER_ROUTE} from "@/core/data/apiRoutes"; describe('First page component', () => { describe('Rendering', () => { it('Should see app name text', () => { - render() + render(, {wrapper: MockAppWithProviders}) const appNameElement = screen.getByTestId('app-name') expect(appNameElement).toHaveTextContent('سامانه CRM') }); }); describe('behavior', () => { it('Should see login button when is not auth', async () => { - render() + render(, {wrapper: MockAppWithProviders}) const buttonLoginOrDashboard = await screen.findByTestId('button-login-or-dashboard') expect(buttonLoginOrDashboard).toHaveTextContent('ورود کارشناس') expect(buttonLoginOrDashboard).not.toHaveTextContent('داشبورد') }); it('Should see dashboard button when is auth', async () => { localStorage.setItem("_token", 'token'); - render() + render(, {wrapper: MockAppWithProviders}) const buttonLoginOrDashboard = await screen.findByTestId('button-login-or-dashboard') expect(buttonLoginOrDashboard).not.toHaveTextContent('ورود کارشناس') expect(buttonLoginOrDashboard).toHaveTextContent('داشبورد') }); it('Should see login button when token expire', async () => { localStorage.setItem("_token", 'token'); - server.use([ - rest.get(GET_USER_ROUTE, (req, res, ctx) => { - return res(ctx.status(403)) - }) - ]) - render() + server.use([rest.get(GET_USER_ROUTE, (req, res, ctx) => { + return res(ctx.status(403)) + })]) + render(, {wrapper: MockAppWithProviders}) const buttonLoginOrDashboard = await screen.findByTestId('button-login-or-dashboard') expect(buttonLoginOrDashboard).toHaveTextContent('ورود کارشناس') expect(buttonLoginOrDashboard).not.toHaveTextContent('داشبورد') diff --git a/src/pages/dashboard/change-password/index.jsx b/src/pages/dashboard/change-password/index.jsx index 670e184..f744382 100644 --- a/src/pages/dashboard/change-password/index.jsx +++ b/src/pages/dashboard/change-password/index.jsx @@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) { messages: (await import(`&/locales/${locale}/app.json`)).default, title: "Dashboard.change_password", isBot, + locale }, }; } diff --git a/src/pages/dashboard/edit-profile/index.jsx b/src/pages/dashboard/edit-profile/index.jsx index 9460506..dfa2eec 100644 --- a/src/pages/dashboard/edit-profile/index.jsx +++ b/src/pages/dashboard/edit-profile/index.jsx @@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) { messages: (await import(`&/locales/${locale}/app.json`)).default, title: "Dashboard.edit_profile", isBot, + locale }, }; } diff --git a/src/pages/dashboard/index.jsx b/src/pages/dashboard/index.jsx index af824d5..eed56eb 100644 --- a/src/pages/dashboard/index.jsx +++ b/src/pages/dashboard/index.jsx @@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) { messages: (await import(`&/locales/${locale}/app.json`)).default, title: "Dashboard.dashboard_page", isBot, + locale }, }; } diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 2e146c6..996ba03 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -16,6 +16,7 @@ export async function getServerSideProps({req, locale}) { messages: (await import(`&/locales/${locale}/app.json`)).default, title: "first_page", isBot, + locale }, }; } diff --git a/src/pages/login-expert.jsx b/src/pages/login-expert.jsx index 1cc6abf..393f916 100644 --- a/src/pages/login-expert.jsx +++ b/src/pages/login-expert.jsx @@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) { messages: (await import(`&/locales/${locale}/app.json`)).default, title: "Titles.title_login_expert_page", isBot, + locale }, }; }