CFE-15 Merge branch 'feature/CFE-15_custom_render_testing' into 'develop'

This commit is contained in:
AmirHossein Mahmoodi
2023-09-26 07:08:48 +00:00
7 changed files with 16 additions and 13 deletions

View File

@@ -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 (<App Component={Component} pageProps={pageProps}/>)
return (<App Component={() => (<>{children}</>)} pageProps={pageProps}/>)
}
export default MockAppWithProviders

View File

@@ -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(<MockAppWithProviders Component={FirstComponent}/>)
render(<FirstComponent/>, {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(<MockAppWithProviders Component={FirstComponent}/>)
render(<FirstComponent/>, {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(<MockAppWithProviders Component={FirstComponent}/>)
render(<FirstComponent/>, {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(<MockAppWithProviders Component={FirstComponent}/>)
server.use([rest.get(GET_USER_ROUTE, (req, res, ctx) => {
return res(ctx.status(403))
})])
render(<FirstComponent/>, {wrapper: MockAppWithProviders})
const buttonLoginOrDashboard = await screen.findByTestId('button-login-or-dashboard')
expect(buttonLoginOrDashboard).toHaveTextContent('ورود کارشناس')
expect(buttonLoginOrDashboard).not.toHaveTextContent('داشبورد')

View File

@@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) {
messages: (await import(`&/locales/${locale}/app.json`)).default,
title: "Dashboard.change_password",
isBot,
locale
},
};
}

View File

@@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) {
messages: (await import(`&/locales/${locale}/app.json`)).default,
title: "Dashboard.edit_profile",
isBot,
locale
},
};
}

View File

@@ -17,6 +17,7 @@ export async function getServerSideProps({req, locale}) {
messages: (await import(`&/locales/${locale}/app.json`)).default,
title: "Dashboard.dashboard_page",
isBot,
locale
},
};
}

View File

@@ -16,6 +16,7 @@ export async function getServerSideProps({req, locale}) {
messages: (await import(`&/locales/${locale}/app.json`)).default,
title: "first_page",
isBot,
locale
},
};
}

View File

@@ -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
},
};
}