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

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

            const requiredPermissions = ["NEXT_PUBLIC_HAS_WIDGET"];
            render(<MockAppWithProviders><AppPermission permissions={requiredPermissions}/>{'children'}</MockAppWithProviders>);

            await waitFor(()=>{
                expect(screen.queryByText('children')).toBeInTheDocument();
            })
        });
        it('do not show related child if permission does not exist', async () => {

            const requiredPermissions = ["MISSING_PERMISSION"];
            render(<MockAppWithProviders><AppPermission permissions={requiredPermissions} /></MockAppWithProviders>);

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