|
| 1 | +import "@testing-library/jest-dom"; |
| 2 | +import { render } from "@testing-library/react"; |
| 3 | + |
| 4 | +import { NextIntlClientProvider } from "next-intl"; |
| 5 | + |
| 6 | +import messages from "../../../../messages/en.json"; |
| 7 | + |
| 8 | +import Home from "./Home"; |
| 9 | + |
| 10 | +import { topLatestExhibits } from "@/mocks/exhibit"; |
| 11 | +import { ITopLatestExhibit } from "@/interfaces/ITopLatestExhibit"; |
| 12 | + |
| 13 | +jest.mock("@/navigation", () => ({ |
| 14 | + useRouter: jest.fn().mockReturnValue({ |
| 15 | + replace: jest.fn(), |
| 16 | + }), |
| 17 | +})); |
| 18 | + |
| 19 | +jest.mock("yet-another-react-lightbox", () => jest.fn()); |
| 20 | +jest.mock("yet-another-react-lightbox/plugins/zoom", () => ({})); |
| 21 | + |
| 22 | +describe("Home component", () => { |
| 23 | + const renderComponent = (exhibits: ITopLatestExhibit[]) => |
| 24 | + render( |
| 25 | + <NextIntlClientProvider locale="en" messages={messages}> |
| 26 | + <Home exhibits={exhibits} /> |
| 27 | + </NextIntlClientProvider>, |
| 28 | + ); |
| 29 | + |
| 30 | + it("should render component", () => { |
| 31 | + const { getByText } = renderComponent(topLatestExhibits); |
| 32 | + |
| 33 | + expect(getByText("Welcome to our official webpage")); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should render component with image gallery", () => { |
| 37 | + const { container } = renderComponent(topLatestExhibits); |
| 38 | + |
| 39 | + const imageGalleryElement = container.querySelector(".image-gallery"); |
| 40 | + |
| 41 | + expect(imageGalleryElement).toBeInTheDocument(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should not render component with image gallery if no images are discovered", () => { |
| 45 | + const exhibits = topLatestExhibits.map((exhibit) => ({ |
| 46 | + ...exhibit, |
| 47 | + imagesCollection: { items: [] }, |
| 48 | + })); |
| 49 | + |
| 50 | + const { container } = renderComponent(exhibits); |
| 51 | + |
| 52 | + const imageGalleryElement = container.querySelector(".image-gallery"); |
| 53 | + |
| 54 | + expect(imageGalleryElement).toBeNull(); |
| 55 | + }); |
| 56 | +}); |
0 commit comments