|
| 1 | +import React from "react"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import { PageLayout } from ".."; |
| 4 | + |
| 5 | +// Mocking the useDevice hook |
| 6 | +jest.mock("../../../hooks/useDevice", () => ({ |
| 7 | + ...jest.requireActual('../../../hooks/useDevice'), |
| 8 | + useDevice: jest.fn().mockReturnValue({isMobile:false}), |
| 9 | +})); |
| 10 | + |
| 11 | +describe("PageLayout Component", () => { |
| 12 | + it("renders children correctly", () => { |
| 13 | + render( |
| 14 | + <PageLayout> |
| 15 | + <div>Content</div> |
| 16 | + </PageLayout> |
| 17 | + ); |
| 18 | + const content =screen.getByText("Content") |
| 19 | + expect(content).toBeInTheDocument(); |
| 20 | + }); |
| 21 | + |
| 22 | + it("renders sidebar when provided and not on mobile", () => { |
| 23 | + const sidebar = <div>Sidebar</div>; |
| 24 | + render(<PageLayout sidebar={sidebar} />); |
| 25 | + const sidebarContent =screen.getByText("Sidebar") |
| 26 | + expect(sidebarContent).toBeInTheDocument(); |
| 27 | + }); |
| 28 | + |
| 29 | + it("does not render sidebar on mobile", () => { |
| 30 | + jest.spyOn(require("../../../hooks/useDevice"), "useDevice").mockImplementation(() => ({ isMobile: true })); |
| 31 | + const sidebar = <div>Sidebar</div>; |
| 32 | + render(<PageLayout sidebar={sidebar} />); |
| 33 | + const sidebarContent =screen.queryByText("Sidebar") |
| 34 | + expect(sidebarContent).not.toBeInTheDocument() |
| 35 | + }); |
| 36 | + |
| 37 | + it("does not render sidebar when not provided", () => { |
| 38 | + render(<PageLayout />); |
| 39 | + const sidebarContent=screen.queryByTestId("sidebar") |
| 40 | + expect(sidebarContent).toBeNull(); |
| 41 | + }); |
| 42 | +}); |
0 commit comments