Skip to content

Commit 17c2fa9

Browse files
authored
Merge pull request #154 from yaswanth-deriv/yaswanth/FEQ-1996_Added_test_for_page_layout_component
Yaswanth/feq 1996 added test for page layout component
2 parents b4c276a + c27d513 commit 17c2fa9

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { render, screen } from "@testing-library/react";
3+
import { PageLayout } from "..";
4+
import * as hooks from "../../../hooks"
5+
6+
// Mocking the useDevice hook
7+
jest.mock("../../../hooks", () => ({
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(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+
});
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+
});

src/components/PageLayout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { useDevice } from "../../hooks/useDevice";
2+
import { useDevice } from "../../hooks";
33
import "./PageLayout.scss";
44

55
type PageLayoutProps = {

src/hooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {useDevice} from './useDevice'
2+
export {useOnClickOutside} from './useOnClickOutside'

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ export { Text } from "./components/Text";
1919
export { TextArea } from "./components/TextArea";
2020
export { ToggleSwitch } from "./components/ToggleSwitch";
2121
export { Tooltip } from "./components/Tooltip";
22-
export { useDevice } from "./hooks/useDevice";
23-
export { useOnClickOutside } from "./hooks/useOnClickOutside";
22+
export { useDevice,useOnClickOutside } from "./hooks";
2423
export { VerticalTab, VerticalTabItems } from "./components/VerticalTab";

0 commit comments

Comments
 (0)