import { render, screen, fireEvent, waitFor  } from '@testing-library/react';
import MockAppWithProviders from "../../../../../mocks/AppWithProvider";
import WithAuthComponent from "@/core/components/Middleware/WithAuthComponent";
import mockRouter from 'next-router-mock';

describe('WithAuthComponent From WithAuthMiddleware', () => {
    describe('Rendering', () => {
        it('should see expired text in render component', () => {
            render(<MockAppWithProviders><WithAuthComponent /></MockAppWithProviders>);

            const authText = screen.queryByText('دسترسی شما منقضی شده است لطفا دوباره ورود نمایید.');

            expect(authText).toBeInTheDocument();
        });

        it('should see login button in render component', () => {
            render(<MockAppWithProviders><WithAuthComponent /></MockAppWithProviders>);

            const loginButton = screen.queryByText('ورود');

            expect(loginButton).toBeInTheDocument();
        });
    });
    describe('behavior', () => {
        it('should see if router updated in login button', () => {

            mockRouter.query.back_url = 'back_url'
            render(<MockAppWithProviders><WithAuthComponent /></MockAppWithProviders>);

            const loginButton = screen.queryByText('ورود');

            fireEvent.click(loginButton);

            expect(mockRouter).toMatchObject({
                query: { back_url: "back_url" },
            });
        });
    });
});
