import {render, screen, waitFor} from '@testing-library/react';
import WithoutAuthComponent from "@/core/components/Middleware/WithoutAuthComponent";
import MockAppWithProviders from "../../../../../mocks/AppWithProvider";
import WithoutAuthMiddleware from "@/middlewares/WithoutAuth";

describe('WithoutAuthComponent From WithoutAuthMiddleware', () => {
    describe('Rendering', () => {
        it('should render the message with correct text when backUrlDecodedPath is not provided', async () => {

            localStorage.setItem("_token", 'token');

            render(<MockAppWithProviders><WithoutAuthMiddleware /></MockAppWithProviders>);

            await waitFor(()=>{
                expect(screen.queryByText('شما دسترسی لازم به این صفحه را دارید نیاز به ورود مجدد نیست.')).toBeInTheDocument();

                expect(screen.queryByText('درحال رفتن به صفحه داشبورد...')).toBeInTheDocument();
            })

        });

        it('should render the message with a different text when backUrlDecodedPath is provided', async() => {
          render(<MockAppWithProviders><WithoutAuthComponent backUrlDecodedPath="/dashboard/change-password" /></MockAppWithProviders>);

            localStorage.setItem("_token", 'token');

            render(<MockAppWithProviders><WithoutAuthMiddleware /></MockAppWithProviders>);

            await waitFor(()=>{

                expect(screen.queryByText('درحال رفتن به صفحه قبل...')).toBeInTheDocument();
            })


        });
    });
});
