2025-10-10 09:06:44 +00:00
|
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
2025-04-08 07:43:51 +00:00
|
|
|
import { Layout } from "@ui/components/Layout";
|
2025-10-23 19:36:21 +00:00
|
|
|
import { SessionTestProvider } from "@xtablo/shared/contexts/SessionContext";
|
2025-04-08 07:43:51 +00:00
|
|
|
import { BrowserRouter } from "react-router-dom";
|
2025-10-23 19:36:21 +00:00
|
|
|
import { renderWithProviders } from "../utils/testHelpers";
|
2025-04-08 07:43:51 +00:00
|
|
|
|
|
|
|
|
describe("Layout", () => {
|
|
|
|
|
it("renders the layout with children", () => {
|
2025-07-09 06:41:48 +00:00
|
|
|
renderWithProviders(<Layout />);
|
2025-04-08 07:43:51 +00:00
|
|
|
|
|
|
|
|
// Check if the mobile menu button is present
|
|
|
|
|
expect(screen.getByRole("button", { name: /menu/i })).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.skip("toggles mobile menu when menu button is clicked", () => {
|
|
|
|
|
// Mock viewport width to mobile size
|
|
|
|
|
global.innerWidth = 500; // Mobile width
|
|
|
|
|
global.dispatchEvent(new Event("resize"));
|
|
|
|
|
|
|
|
|
|
render(
|
|
|
|
|
<BrowserRouter>
|
2025-10-23 09:54:45 +00:00
|
|
|
<SessionTestProvider testUser={undefined}>
|
2025-07-09 06:41:48 +00:00
|
|
|
<Layout />
|
2025-10-23 09:54:45 +00:00
|
|
|
</SessionTestProvider>
|
2025-04-08 07:43:51 +00:00
|
|
|
</BrowserRouter>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Get the menu button
|
|
|
|
|
const menuButton = screen.getByRole("button", { name: /menu/i });
|
|
|
|
|
|
|
|
|
|
// Verify initial mobile state
|
2025-04-10 05:29:48 +00:00
|
|
|
const navigation = screen.getByLabelText("Main navigation");
|
2025-04-08 07:43:51 +00:00
|
|
|
expect(navigation).toHaveClass("-translate-x-full");
|
|
|
|
|
expect(navigation).not.toHaveClass("translate-x-0");
|
|
|
|
|
|
|
|
|
|
// Click the menu button to show
|
|
|
|
|
fireEvent.click(menuButton);
|
|
|
|
|
expect(navigation).toHaveClass("translate-x-0");
|
|
|
|
|
|
|
|
|
|
// Click again to hide
|
|
|
|
|
fireEvent.click(menuButton);
|
|
|
|
|
expect(navigation).toHaveClass("-translate-x-full");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("renders the side navigation", () => {
|
2025-07-09 06:41:48 +00:00
|
|
|
renderWithProviders(<Layout />);
|
2025-04-08 07:43:51 +00:00
|
|
|
|
|
|
|
|
// Check if the side navigation is present
|
2025-10-10 06:21:56 +00:00
|
|
|
expect(screen.getByRole("navigation", { name: "Main navigation" })).toBeInTheDocument();
|
2025-04-08 07:43:51 +00:00
|
|
|
});
|
|
|
|
|
});
|