11import { render , screen } from "@testing-library/react" ;
22import { usePathname } from "next/navigation" ;
3- import { beforeEach , describe , expect , it , type Mock , vi } from "vitest" ;
3+ import { beforeEach , describe , expect , it , type Mock } from "vitest" ;
44
55import { PublicChrome } from "../PublicChrome" ;
66
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- } ) ) ;
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.
1510
1611describe ( "PublicChrome" , ( ) => {
1712 beforeEach ( ( ) => {
@@ -20,8 +15,10 @@ describe("PublicChrome", () => {
2015
2116 it ( "renders ResourceBanner + Footer on public routes" , ( ) => {
2217 render ( < PublicChrome /> ) ;
23- expect ( screen . getByTestId ( "public-resource-banner" ) ) . toBeInTheDocument ( ) ;
24- expect ( screen . getByTestId ( "public-footer" ) ) . toBeInTheDocument ( ) ;
18+ expect (
19+ screen . getByRole ( "region" , { name : / r e s s o u r c e s e t a i d e / i } ) ,
20+ ) . toBeInTheDocument ( ) ;
21+ expect ( screen . getByRole ( "contentinfo" ) ) . toBeInTheDocument ( ) ;
2522 } ) ;
2623
2724 it ( "renders nothing on /admin" , ( ) => {
@@ -39,6 +36,18 @@ describe("PublicChrome", () => {
3936 it ( "renders chrome on non-admin nested routes" , ( ) => {
4037 ( usePathname as Mock ) . mockReturnValue ( "/mon-espace/declarations" ) ;
4138 render ( < PublicChrome /> ) ;
42- expect ( screen . getByTestId ( "public-footer" ) ) . toBeInTheDocument ( ) ;
39+ expect (
40+ screen . getByRole ( "region" , { name : / r e s s o u r c e s e t a i d e / 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 : / r e s s o u r c e s e t a i d e / i } ) ,
50+ ) . toBeInTheDocument ( ) ;
51+ expect ( screen . getByRole ( "contentinfo" ) ) . toBeInTheDocument ( ) ;
4352 } ) ;
4453} ) ;
0 commit comments