Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for RootLayout #217

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Fragment } from "react/jsx-runtime";

import { styled } from "@mui/material";
import Divider from "@mui/material/Divider";
import List from "@mui/material/List";
import Typography from "@mui/material/Typography";
import styled from "@mui/material/styles/styled";

import CartDrawerItem from "@/containers/drawers/cart-drawer/components/CartDrawerItem";
import { useCartStore } from "@/store/cart/cartStore";
Expand Down
12 changes: 12 additions & 0 deletions src/layouts/root-layout/RootLayout.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { styled } from "@mui/material";
import Box from "@mui/material/Box";

import theme from "@/theme/theme";

export const SidebarOmitWrapper = styled(Box)({
margin: "auto",
maxWidth: "1900px",
[theme.breakpoints.up("md")]: {
paddingLeft: "78px",
},
});
12 changes: 1 addition & 11 deletions src/layouts/root-layout/RootLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { ScrollRestoration } from "react-router-dom";

import { styled } from "@mui/material";
import Box from "@mui/material/Box";

import AppSuspenseWithOutlet from "@/components/app-suspense-with-outlet/AppSuspenseWithOutlet";
import Footer from "@/layouts/footer/Footer";
import Navbar from "@/layouts/navbar/Navbar";
import { SidebarOmitWrapper } from "@/layouts/root-layout/RootLayout.styles";
import Sidebar from "@/layouts/sidebar/Sidebar";

const SidebarOmitWrapper = styled(Box)(({ theme }) => ({
margin: "auto",
maxWidth: "1900px",
[theme.breakpoints.up("md")]: {
paddingLeft: "78px",
},
}));

export default function RootLayout() {
return (
<>
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/src/layouts/root-layout/RootLayout.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { screen } from "@testing-library/react";

import renderWithProviders from "@tests/unit/utils/renderWithProviders";

import RootLayout from "@/layouts/root-layout/RootLayout";

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
ScrollRestoration: () => <div data-testid="scroll-restoration" />,
}));

jest.mock("@/layouts/footer/Footer", () => ({
__esModule: true,
default: () => <div data-testid="footer" />,
}));

jest.mock(
"@/components/app-suspense-with-outlet/AppSuspenseWithOutlet",
() => ({
__esModule: true,
default: () => <div data-testid="children" />,
})
);

describe("<RootLayout />", () => {
it("should render correctly", () => {
renderWithProviders(<RootLayout />);

const footer = screen.getByTestId("footer");
expect(footer).toBeInTheDocument();

const children = screen.getByTestId("children");
expect(children).toBeInTheDocument();
});
});
Loading