import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import MobileMenu from "./MobileMenu";
vi.mock("../menu-item/MenuItem", () => ({
default: vi.fn(() =>
MenuItem
),
}));
vi.mock("../close-icon/CloseIcon", () => ({
default: vi.fn(() => CloseIcon
),
}));
describe("MobileMenu", () => {
const mockToggleMenu = vi.fn();
const mockLinks = [
{ hideOptions: vi.fn(() => true), name: "Link1" },
{ hideOptions: vi.fn(() => false), name: "Link2" },
];
const mockLinkComponent = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
});
test("renders correctly when menu is open", () => {
render(
,
);
expect(screen.getByText("CloseIcon")).toBeInTheDocument();
expect(screen.getByText("MenuItem")).toBeInTheDocument();
expect(screen.getByText("MenuItem")).toBeInTheDocument();
});
test("renders correctly when menu is closed", () => {
render(
,
);
expect(screen.getByText("CloseIcon")).toBeInTheDocument();
expect(screen.queryByText("MenuItem")).not.toBeInTheDocument();
});
test("calls toggleMenu when close icon is clicked", () => {
render(
,
);
fireEvent.click(screen.getByText("CloseIcon"));
expect(mockToggleMenu).toHaveBeenCalledTimes(1);
});
test("filters links based on hideOptions", () => {
render(
,
);
expect(mockLinks[0].hideOptions).toHaveBeenCalledWith({ loggedIn: true });
expect(mockLinks[1].hideOptions).toHaveBeenCalledWith({ loggedIn: true });
expect(screen.getAllByText("MenuItem")).toHaveLength(1);
});
});