Skip to content

Commit

Permalink
fix: testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhan-slurrp committed Apr 22, 2024
1 parent 20f0cf3 commit 617f163
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/components/PageLayout/__test__/PageLayout.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { PageLayout } from "..";
import * as hooks from "../../../hooks"
import * as hooks from "../../../hooks";

// Mocking the useDevice hook
jest.mock("../../../hooks", () => ({
useDevice: jest.fn().mockReturnValue({isMobile:false}),
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 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("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 on mobile", () => {
jest.spyOn(hooks, "useDevice").mockImplementation(() => ({
isMobile: true,
isDesktop: false,
isTablet: false,
isTabletPortrait: 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();
});
it("does not render sidebar when not provided", () => {
render(<PageLayout />);
const sidebarContent = screen.queryByTestId("sidebar");
expect(sidebarContent).toBeNull();
});
});

0 comments on commit 617f163

Please sign in to comment.