|
1 | 1 | import React from "react";
|
2 | 2 | import { render, screen } from "@testing-library/react";
|
3 | 3 | import { PageLayout } from "..";
|
4 |
| -import * as hooks from "../../../hooks" |
| 4 | +import * as hooks from "../../../hooks"; |
5 | 5 |
|
6 | 6 | // Mocking the useDevice hook
|
7 | 7 | jest.mock("../../../hooks", () => ({
|
8 |
| - useDevice: jest.fn().mockReturnValue({isMobile:false}), |
| 8 | + useDevice: jest.fn().mockReturnValue({ isMobile: false }), |
9 | 9 | }));
|
10 | 10 |
|
11 | 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 |
| - }); |
| 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 | 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 |
| - }); |
| 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 | 28 |
|
29 |
| - it("does not render sidebar on mobile", () => { |
30 |
| - jest.spyOn(hooks,'useDevice').mockImplementation(()=>({isMobile:true, isDesktop:false, isTablet:false})) |
31 |
| - const sidebar = <div>Sidebar</div>; |
32 |
| - render(<PageLayout sidebar={sidebar} />); |
33 |
| - const sidebarContent =screen.queryByText("Sidebar") |
34 |
| - expect(sidebarContent).not.toBeInTheDocument() |
35 |
| - }); |
| 29 | + it("does not render sidebar on mobile", () => { |
| 30 | + jest.spyOn(hooks, "useDevice").mockImplementation(() => ({ |
| 31 | + isMobile: true, |
| 32 | + isDesktop: false, |
| 33 | + isTablet: false, |
| 34 | + isTabletPortrait: false, |
| 35 | + })); |
| 36 | + const sidebar = <div>Sidebar</div>; |
| 37 | + render(<PageLayout sidebar={sidebar} />); |
| 38 | + const sidebarContent = screen.queryByText("Sidebar"); |
| 39 | + expect(sidebarContent).not.toBeInTheDocument(); |
| 40 | + }); |
36 | 41 |
|
37 |
| - it("does not render sidebar when not provided", () => { |
38 |
| - render(<PageLayout />); |
39 |
| - const sidebarContent=screen.queryByTestId("sidebar") |
40 |
| - expect(sidebarContent).toBeNull(); |
41 |
| - }); |
| 42 | + it("does not render sidebar when not provided", () => { |
| 43 | + render(<PageLayout />); |
| 44 | + const sidebarContent = screen.queryByTestId("sidebar"); |
| 45 | + expect(sidebarContent).toBeNull(); |
| 46 | + }); |
42 | 47 | });
|
0 commit comments