11import { render , screen , waitFor } from "@testing-library/react" ;
22import "@testing-library/jest-dom" ;
33
4- import dlsLogo from "../public/dls.svg" ;
5-
4+ import dlsLogo from "../public/generic/logo-short.svg" ;
65import { Footer , FooterLink , FooterLinks } from "./Footer" ;
6+ import { ImageColorSchemeSwitch } from "./ImageColorSchemeSwitch" ;
7+ import { ThemeProvider } from "../themes/ThemeProvider" ;
8+
9+ jest . mock ( "./ImageColorSchemeSwitch" ) ;
10+ // @ts -expect-error: doesn't find mockImplementation outside of testing.
11+ ImageColorSchemeSwitch . mockImplementation ( ( ) => < img src = "src" alt = "alt" /> ) ;
12+
713describe ( "Footer" , ( ) => {
8- test ( "Should render logo only" , async ( ) => {
9- render ( < Footer logo = { dlsLogo } /> ) ;
14+ test ( "Should render logo only" , ( ) => {
15+ render ( < Footer logo = { { src : dlsLogo , alt : "t" } } /> ) ;
1016
11- await waitFor ( ( ) => {
12- expect ( screen . getByRole ( "img" ) ) . toBeInTheDocument ( ) ;
13- // No copyright text
14- expect ( screen . queryByRole ( "paragraph" ) ) . not . toBeTruthy ( ) ;
15- } ) ;
17+ expect ( screen . getByRole ( "img" ) ) . toBeInTheDocument ( ) ;
18+ // No copyright text
19+ expect ( screen . queryByRole ( "paragraph" ) ) . not . toBeInTheDocument ( ) ;
20+ } ) ;
21+
22+ test ( "Should render logo via theme" , ( ) => {
23+ render (
24+ < ThemeProvider >
25+ < Footer logo = "theme" />
26+ </ ThemeProvider > ,
27+ ) ;
28+
29+ expect ( screen . getByRole ( "img" ) ) . toBeInTheDocument ( ) ;
1630 } ) ;
1731
1832 test ( "Should render copyright only" , async ( ) => {
@@ -33,12 +47,15 @@ describe("Footer", () => {
3347 test ( "Should render logo and copyright" , async ( ) => {
3448 const copyrightText = "add text here" ;
3549 const currentYear = new Date ( ) . getFullYear ( ) ;
36- render ( < Footer logo = { dlsLogo } copyright = { copyrightText } /> ) ;
50+ render (
51+ < Footer logo = { { src : dlsLogo , alt : "" } } copyright = { copyrightText } /> ,
52+ ) ;
3753
3854 await waitFor ( ( ) => {
3955 expect ( screen . getByRole ( "img" ) ) . toBeInTheDocument ( ) ;
40- expect ( screen . queryByRole ( "paragraph" ) ) . toBeInTheDocument ( ) ;
41- expect ( screen . queryByRole ( "paragraph" ) ?. textContent ) . toStrictEqual (
56+ const paragraph = screen . getByRole ( "paragraph" ) ;
57+ expect ( paragraph ) . toBeInTheDocument ( ) ;
58+ expect ( paragraph . textContent ) . toStrictEqual (
4259 `Copyright © ${ currentYear } ${ copyrightText } ` ,
4360 ) ;
4461 } ) ;
0 commit comments