|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import { usePathname } from "next/navigation"; |
| 3 | +import { beforeEach, describe, expect, it, type Mock } from "vitest"; |
| 4 | + |
| 5 | +import { PublicChrome } from "../PublicChrome"; |
| 6 | + |
| 7 | +// Renders real Footer + ResourceBanner; only their external deps |
| 8 | +// (next/link, next/image, next/navigation) are mocked globally in test/setup.ts, |
| 9 | +// so a regression inside either landmark would fail this file. |
| 10 | + |
| 11 | +describe("PublicChrome", () => { |
| 12 | + beforeEach(() => { |
| 13 | + (usePathname as Mock).mockReturnValue("/"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("renders ResourceBanner + Footer on public routes", () => { |
| 17 | + render(<PublicChrome />); |
| 18 | + expect( |
| 19 | + screen.getByRole("region", { name: /ressources et aide/i }), |
| 20 | + ).toBeInTheDocument(); |
| 21 | + expect(screen.getByRole("contentinfo")).toBeInTheDocument(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("renders nothing on /admin", () => { |
| 25 | + (usePathname as Mock).mockReturnValue("/admin"); |
| 26 | + const { container } = render(<PublicChrome />); |
| 27 | + expect(container).toBeEmptyDOMElement(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("renders nothing on nested /admin/* routes", () => { |
| 31 | + (usePathname as Mock).mockReturnValue("/admin/declarations"); |
| 32 | + const { container } = render(<PublicChrome />); |
| 33 | + expect(container).toBeEmptyDOMElement(); |
| 34 | + }); |
| 35 | + |
| 36 | + it("renders chrome on non-admin nested routes", () => { |
| 37 | + (usePathname as Mock).mockReturnValue("/mon-espace/declarations"); |
| 38 | + render(<PublicChrome />); |
| 39 | + expect( |
| 40 | + screen.getByRole("region", { name: /ressources et aide/i }), |
| 41 | + ).toBeInTheDocument(); |
| 42 | + expect(screen.getByRole("contentinfo")).toBeInTheDocument(); |
| 43 | + }); |
| 44 | + |
| 45 | + it("renders chrome on sibling routes whose name merely starts with 'admin'", () => { |
| 46 | + (usePathname as Mock).mockReturnValue("/administrator"); |
| 47 | + render(<PublicChrome />); |
| 48 | + expect( |
| 49 | + screen.getByRole("region", { name: /ressources et aide/i }), |
| 50 | + ).toBeInTheDocument(); |
| 51 | + expect(screen.getByRole("contentinfo")).toBeInTheDocument(); |
| 52 | + }); |
| 53 | +}); |
0 commit comments