import {render, screen, waitFor} from '@testing-library/react';
import MockAppWithProviders from "../../../mocks/AppWithProvider";
import RolePermissionMiddleware from "@/middlewares/RolePermission";


describe('RolePermissionMiddleware From RolePermissionMiddleware',  () => {
    describe('Behavior', () => {
        it('show related child if permission exist', async () => {

            const requiredPermissions = ["manage_users"];
            render(<MockAppWithProviders><RolePermissionMiddleware requiredPermissions={requiredPermissions}/>{'children'}</MockAppWithProviders>);

            await waitFor(()=>{
                expect(screen.queryByText('children')).toBeInTheDocument();

            })

        });
        it('show related error if permission not exist', async () => {

            const requiredPermissions = ["other-permission"];

            render(<MockAppWithProviders><RolePermissionMiddleware requiredPermissions={requiredPermissions}/></MockAppWithProviders>);

            await waitFor(()=>{

                expect(screen.queryByText('شما دسترسی لازم برای مشاهده این صفحه را ندارید!')).toBeInTheDocument();

            })


        });
    });
});
