|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { usePathname } from "next/navigation"; |
| 3 | +import { beforeEach, describe, expect, it, type Mock, vi } from "vitest"; |
| 4 | + |
| 5 | +import { PublicChrome } from "../PublicChrome"; |
| 6 | + |
| 7 | +vi.mock("../Footer", () => ({ |
| 8 | + Footer: () => <footer data-testid="public-footer">footer</footer>, |
| 9 | +})); |
| 10 | +vi.mock("../ResourceBanner", () => ({ |
| 11 | + ResourceBanner: () => ( |
| 12 | + <section data-testid="public-resource-banner">banner</section> |
| 13 | + ), |
| 14 | +})); |
| 15 | + |
| 16 | +describe("PublicChrome", () => { |
| 17 | + beforeEach(() => { |
| 18 | + (usePathname as Mock).mockReturnValue("/"); |
| 19 | + }); |
| 20 | + |
| 21 | + it("renders ResourceBanner + Footer on public routes", () => { |
| 22 | + render(<PublicChrome />); |
| 23 | + expect(screen.getByTestId("public-resource-banner")).toBeInTheDocument(); |
| 24 | + expect(screen.getByTestId("public-footer")).toBeInTheDocument(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("renders nothing on /admin", () => { |
| 28 | + (usePathname as Mock).mockReturnValue("/admin"); |
| 29 | + const { container } = render(<PublicChrome />); |
| 30 | + expect(container).toBeEmptyDOMElement(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("renders nothing on nested /admin/* routes", () => { |
| 34 | + (usePathname as Mock).mockReturnValue("/admin/declarations"); |
| 35 | + const { container } = render(<PublicChrome />); |
| 36 | + expect(container).toBeEmptyDOMElement(); |
| 37 | + }); |
| 38 | + |
| 39 | + it("renders chrome on non-admin nested routes", () => { |
| 40 | + (usePathname as Mock).mockReturnValue("/mon-espace/declarations"); |
| 41 | + render(<PublicChrome />); |
| 42 | + expect(screen.getByTestId("public-footer")).toBeInTheDocument(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments