diff --git a/src/components/first/__tests__/index.test.js b/src/components/first/__tests__/index.test.js index 7e60576..c098d67 100644 --- a/src/components/first/__tests__/index.test.js +++ b/src/components/first/__tests__/index.test.js @@ -1,42 +1,22 @@ -import FirstComponent from "@/components/first"; import {render, screen} from "@testing-library/react"; +import FirstComponent from "@/components/first"; import MockAppWithProviders from "../../../../mocks/AppWithProvider"; -import {server} from "../../../../mocks/server"; -import {rest} from "msw"; -import {GET_USER_ROUTE} from "@/core/data/apiRoutes"; -describe('First page component', () => { - describe('Rendering', () => { - it('Should see app name text', () => { - render(, {wrapper: MockAppWithProviders}) - const appNameElement = screen.getByTestId('app-name') - expect(appNameElement).toHaveTextContent('سامانه CRM') - }); +describe("First Page Component", () => { + describe("Rendering", () => { + it("App Name Text Rendered", () => { + render(); + const appNameElement = screen.queryByText(/سامانه CRM/i); + expect(appNameElement).toBeInTheDocument() + }) }); - describe('behavior', () => { - it('Should see login button when is not auth', async () => { - 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(, {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(, {wrapper: MockAppWithProviders}) - const buttonLoginOrDashboard = await screen.findByTestId('button-login-or-dashboard') - expect(buttonLoginOrDashboard).toHaveTextContent('ورود کارشناس') - expect(buttonLoginOrDashboard).not.toHaveTextContent('داشبورد') - }); - + describe("Behavioral", () => { + it("Show Login Button And Do Not Show Dashboard Button When User Is Not Authenticated", async () => { + render(); + const authenticationButtonLogin = await screen.queryByText(/ورود کارشناس/i) + const authenticationButtonDashboard = await screen.queryByText(/داشبورد/i) + expect(authenticationButtonLogin).toBeInTheDocument() + expect(authenticationButtonDashboard).not.toBeInTheDocument() + }) }); }); \ No newline at end of file