import {render, screen} from "@testing-library/react";
import MockAppWithProviders from "../../../../../../mocks/AppWithProvider";
import SidebarListSubItem from "@/components/layouts/Dashboard/Sidebar/SidebarListSubItem";
import AccessibilityIcon from "@mui/icons-material/Accessibility";

describe('SidebarListSubItemComponent', () => {
    describe('Rendering', () => {
        const sampleItem={
            showSubItem:true,
            key: "sidebar.role-management",
            name : "role_management",
            type: "menu",
            route: "/dashboard/role-management",
            icon: <AccessibilityIcon />,
            selected: false,
            permission: "manage_roles",
            subItem :[
                {
                    key: "greaterThan",
                    route: "/dashboard/role-management",
                    secondary: "between",
                    name : "sidebar.admin",
                    selected: true,
                    icon: <AccessibilityIcon aria-label="Sidebar Icon"/>,
                }
            ]
        }
        it('should show subitem name in sidebar', () => {
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            expect(screen.getByText('بزرگتر از')).toBeInTheDocument();

        });
        it('should not show subitem name in sidebar', () => {
            const sampleItem={
                showSubItem:false,
                key: "sidebar.role-management",
                name : "role_management",
                type: "menu",
                route: "/dashboard/role-management",
                icon: <AccessibilityIcon />,
                selected: false,
                permission: "manage_roles",
                subItem :[
                    {
                        key: "greaterThan",
                        route: "/dashboard/role-management",
                        secondary: "between",
                        name : "sidebar.admin",
                        selected: false,
                        icon: <AccessibilityIcon />,
                    }
                ]
            }
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            expect(screen.queryByText('مدیریت نقش ها')).not.toBeInTheDocument();
        });
        it('should show subitem secondary in sidebar', () => {
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            expect(screen.getByText('میان')).toBeInTheDocument();
        });

        it('should not show subitem secondary in sidebar', () => {
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            expect(screen.queryByText('secondry')).not.toBeInTheDocument();
        });
        it('should have selected class for subitem', () => {
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            const parentElement = screen.queryByText('بزرگتر از').parentElement.parentElement;
            expect(parentElement).toHaveClass('Mui-selected');
        });

        it('should not have selected class for subitem', () => {
            const sampleItem={
                showSubItem:true,
                key: "sidebar.role-management",
                name : "role_management",
                type: "menu",
                route: "/dashboard/role-management",
                icon: <AccessibilityIcon />,
                selected: false,
                permission: "manage_roles",
                subItem :[
                    {
                        key: "greaterThan",
                        route: "/dashboard/role-management",
                        secondary: "between",
                        name : "sidebar.admin",
                        selected: false,
                        icon: <AccessibilityIcon />,
                    }
                ]
            }
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            const parentElement = screen.queryByText('بزرگتر از').parentElement.parentElement;
            expect(parentElement).not.toHaveClass('Mui-selected');
        });
        it('should show subitem icon', () => {
            render(<MockAppWithProviders><SidebarListSubItem item={sampleItem} /></MockAppWithProviders>);
            const iconElement = screen.getByLabelText("Sidebar Icon");
            expect(iconElement).toBeInTheDocument();
        });
    })
})