@@ -16,6 +16,7 @@ import "@testing-library/jest-dom";
1616import dlsLogo from "../public/generic/logo-short.svg" ;
1717import { Footer , FooterLink , FooterLinks } from "./Footer" ;
1818import { renderWithProviders } from "../../__test-utils__/helpers" ;
19+ import { MemoryRouter , Link } from "react-router-dom" ;
1920
2021describe ( "Footer logo and copyright" , ( ) => {
2122 test ( "Should render" , async ( ) => {
@@ -99,3 +100,88 @@ describe("Footer Links", () => {
99100 expect ( link ) . toHaveAttribute ( "href" , "link-two-href" ) ;
100101 } ) ;
101102} ) ;
103+
104+ test ( "Should render FooterLink with linkComponent and 'to' prop" , async ( ) => {
105+ renderWithProviders (
106+ < MemoryRouter initialEntries = { [ "/" ] } >
107+ < Footer >
108+ < FooterLinks >
109+ < FooterLink linkComponent = { Link } to = "/about" >
110+ About
111+ </ FooterLink >
112+ </ FooterLinks >
113+ </ Footer >
114+ </ MemoryRouter > ,
115+ ) ;
116+
117+ const link = await screen . findByText ( "About" ) ;
118+ expect ( link ) . toBeInTheDocument ( ) ;
119+ expect ( link ) . toHaveAttribute ( "href" , "/about" ) ;
120+ } ) ;
121+
122+ test ( "Should not render a valid link when only 'to' is provided without linkComponent" , ( ) => {
123+ renderWithProviders (
124+ < Footer >
125+ < FooterLinks >
126+ < FooterLink to = "/about" > About</ FooterLink >
127+ </ FooterLinks >
128+ </ Footer > ,
129+ ) ;
130+
131+ const link = screen . getByText ( "About" ) ;
132+ expect ( link ) . toBeInTheDocument ( ) ;
133+ expect ( link ) . not . toHaveAttribute ( "href" , "/about" ) ;
134+ } ) ;
135+
136+ test ( "Should fall back to href when linkComponent is provided without 'to'" , ( ) => {
137+ renderWithProviders (
138+ < MemoryRouter >
139+ < Footer >
140+ < FooterLinks >
141+ < FooterLink linkComponent = { Link } href = "/about" >
142+ About
143+ </ FooterLink >
144+ </ FooterLinks >
145+ </ Footer >
146+ </ MemoryRouter > ,
147+ ) ;
148+
149+ const link = screen . getByText ( "About" ) ;
150+ expect ( link ) . toBeInTheDocument ( ) ;
151+ expect ( link . tagName ) . toBe ( "A" ) ;
152+ expect ( link ) . toHaveAttribute ( "href" , "/about" ) ;
153+ } ) ;
154+
155+ test ( "Should use href when both 'href' and 'to' are provided without linkComponent" , ( ) => {
156+ renderWithProviders (
157+ < Footer >
158+ < FooterLinks >
159+ < FooterLink href = "/about" to = "/somewhereElse" >
160+ About
161+ </ FooterLink >
162+ </ FooterLinks >
163+ </ Footer > ,
164+ ) ;
165+
166+ const link = screen . getByText ( "About" ) ;
167+ expect ( link ) . toBeInTheDocument ( ) ;
168+ expect ( link ) . toHaveAttribute ( "href" , "/about" ) ;
169+ } ) ;
170+
171+ test ( "Should use 'to' when both 'href' and 'to' are provided with linkComponent" , ( ) => {
172+ renderWithProviders (
173+ < MemoryRouter >
174+ < Footer >
175+ < FooterLinks >
176+ < FooterLink linkComponent = { Link } href = "/somewhereElse" to = "/about" >
177+ About
178+ </ FooterLink >
179+ </ FooterLinks >
180+ </ Footer >
181+ </ MemoryRouter > ,
182+ ) ;
183+
184+ const link = screen . getByText ( "About" ) ;
185+ expect ( link ) . toBeInTheDocument ( ) ;
186+ expect ( link ) . toHaveAttribute ( "href" , "/about" ) ;
187+ } ) ;
0 commit comments