|
| 1 | +import React from "react"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import App from "../App"; |
| 4 | + |
| 5 | +// Mock child components |
| 6 | +jest.mock("../components/Header", () => { |
| 7 | + return function DummyHeader() { |
| 8 | + return <div data-testid="header">Header</div>; |
| 9 | + }; |
| 10 | +}); |
| 11 | + |
| 12 | +jest.mock("../components/Footer", () => { |
| 13 | + return function DummyFooter() { |
| 14 | + return <div data-testid="footer">Footer</div>; |
| 15 | + }; |
| 16 | +}); |
| 17 | + |
| 18 | +jest.mock("../components/CSCalendar", () => { |
| 19 | + return function DummyCSCalendar() { |
| 20 | + return <div data-testid="calendar">Calendar</div>; |
| 21 | + }; |
| 22 | +}); |
| 23 | + |
| 24 | +jest.mock("../components/FloatButtonSection", () => { |
| 25 | + return function DummyFloatButtonSection() { |
| 26 | + return <div data-testid="float-button">Float Button</div>; |
| 27 | + }; |
| 28 | +}); |
| 29 | + |
| 30 | +jest.mock("../components/AnnouncementModule", () => { |
| 31 | + return function DummyAnnouncementModule() { |
| 32 | + return <div data-testid="announcement">Announcement</div>; |
| 33 | + }; |
| 34 | +}); |
| 35 | + |
| 36 | +jest.mock("../components/Toastify", () => { |
| 37 | + return function DummyToastify() { |
| 38 | + return <div data-testid="toastify">Toastify</div>; |
| 39 | + }; |
| 40 | +}); |
| 41 | + |
| 42 | +jest.mock("../store/StoreProvider", () => { |
| 43 | + return function DummyStoreProvider({ children }) { |
| 44 | + return <div data-testid="store-provider">{children}</div>; |
| 45 | + }; |
| 46 | +}); |
| 47 | + |
| 48 | +// Mock ThemeContext |
| 49 | +jest.mock("../store/Theme/ThemeContext", () => { |
| 50 | + const React = require("react"); |
| 51 | + const mockThemeContext = { |
| 52 | + theme: "light", |
| 53 | + toggleTheme: jest.fn(), |
| 54 | + }; |
| 55 | + return { |
| 56 | + __esModule: true, |
| 57 | + default: React.createContext(mockThemeContext), |
| 58 | + ThemeContext: React.createContext(mockThemeContext), |
| 59 | + }; |
| 60 | +}); |
| 61 | + |
| 62 | +describe("App", () => { |
| 63 | + it("should render without crashing", () => { |
| 64 | + render(<App />); |
| 65 | + }); |
| 66 | + |
| 67 | + it("should render Header component", () => { |
| 68 | + render(<App />); |
| 69 | + expect(screen.getByTestId("header")).toBeInTheDocument(); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should render Footer component", () => { |
| 73 | + render(<App />); |
| 74 | + expect(screen.getByTestId("footer")).toBeInTheDocument(); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should render CSCalendar component", () => { |
| 78 | + render(<App />); |
| 79 | + expect(screen.getByTestId("calendar")).toBeInTheDocument(); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should render FloatButtonSection component", () => { |
| 83 | + render(<App />); |
| 84 | + expect(screen.getByTestId("float-button")).toBeInTheDocument(); |
| 85 | + }); |
| 86 | + |
| 87 | + it("should render AnnouncementModule component", () => { |
| 88 | + render(<App />); |
| 89 | + expect(screen.getByTestId("announcement")).toBeInTheDocument(); |
| 90 | + }); |
| 91 | + |
| 92 | + it("should render Toastify component", () => { |
| 93 | + render(<App />); |
| 94 | + expect(screen.getByTestId("toastify")).toBeInTheDocument(); |
| 95 | + }); |
| 96 | +}); |
0 commit comments