Skip to content

Commit

Permalink
Merge pull request #154 from yaswanth-deriv/yaswanth/FEQ-1996_Added_t…
Browse files Browse the repository at this point in the history
…est_for_page_layout_component

Yaswanth/feq 1996 added test for page layout component
  • Loading branch information
shayan-deriv authored Apr 1, 2024
2 parents b4c276a + c27d513 commit 17c2fa9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
42 changes: 42 additions & 0 deletions src/components/PageLayout/__test__/PageLayout.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { PageLayout } from "..";
import * as hooks from "../../../hooks"

// Mocking the useDevice hook
jest.mock("../../../hooks", () => ({
useDevice: jest.fn().mockReturnValue({isMobile:false}),
}));

describe("PageLayout Component", () => {
it("renders children correctly", () => {
render(
<PageLayout>
<div>Content</div>
</PageLayout>
);
const content =screen.getByText("Content")
expect(content).toBeInTheDocument();
});

it("renders sidebar when provided and not on mobile", () => {
const sidebar = <div>Sidebar</div>;
render(<PageLayout sidebar={sidebar} />);
const sidebarContent =screen.getByText("Sidebar")
expect(sidebarContent).toBeInTheDocument();
});

it("does not render sidebar on mobile", () => {
jest.spyOn(hooks,'useDevice').mockImplementation(()=>({isMobile:true, isDesktop:false, isTablet:false}))
const sidebar = <div>Sidebar</div>;
render(<PageLayout sidebar={sidebar} />);
const sidebarContent =screen.queryByText("Sidebar")
expect(sidebarContent).not.toBeInTheDocument()
});

it("does not render sidebar when not provided", () => {
render(<PageLayout />);
const sidebarContent=screen.queryByTestId("sidebar")
expect(sidebarContent).toBeNull();
});
});
2 changes: 1 addition & 1 deletion src/components/PageLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { useDevice } from "../../hooks/useDevice";
import { useDevice } from "../../hooks";
import "./PageLayout.scss";

type PageLayoutProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {useDevice} from './useDevice'
export {useOnClickOutside} from './useOnClickOutside'
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ export { Text } from "./components/Text";
export { TextArea } from "./components/TextArea";
export { ToggleSwitch } from "./components/ToggleSwitch";
export { Tooltip } from "./components/Tooltip";
export { useDevice } from "./hooks/useDevice";
export { useOnClickOutside } from "./hooks/useOnClickOutside";
export { useDevice,useOnClickOutside } from "./hooks";
export { VerticalTab, VerticalTabItems } from "./components/VerticalTab";

0 comments on commit 17c2fa9

Please sign in to comment.