Skip to content

Commit a211ddb

Browse files
authored
Fix benefits hub landing page showing TOC with only one section (#1842)
1 parent 2d657a9 commit a211ddb

2 files changed

Lines changed: 69 additions & 12 deletions

File tree

src/components/benefitsHub/template.test.tsx

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('BenefitsHub with valid data', () => {
250250
expect(instagramLink.href).toBe('https://www.instagram.com/deptvetaffairs')
251251
})
252252

253-
test('renders on-this-page component when spokes exist', () => {
253+
test('renders on-this-page component when more than one spoke exists', () => {
254254
const mockSpokes = [
255255
{
256256
type: 'paragraph--list_of_link_teasers' as const,
@@ -274,6 +274,28 @@ describe('BenefitsHub with valid data', () => {
274274
},
275275
],
276276
},
277+
{
278+
type: 'paragraph--list_of_link_teasers' as const,
279+
id: 'spoke-2',
280+
entityId: 3,
281+
title: 'More health topics',
282+
isHubPage: true,
283+
linkTeasers: [
284+
{
285+
type: 'paragraph--link_teaser' as const,
286+
id: 'teaser-2',
287+
entityId: 4,
288+
uri: '/health-care/cost/',
289+
title: 'Health care costs',
290+
options: [],
291+
summary: 'Learn about costs',
292+
isHubPage: true,
293+
componentParams: {
294+
sectionHeader: 'More health topics',
295+
},
296+
},
297+
],
298+
},
277299
]
278300

279301
render(
@@ -288,12 +310,51 @@ describe('BenefitsHub with valid data', () => {
288310
/>
289311
)
290312

291-
// Check that the va-on-this-page element is rendered
292-
const onThisPageElement = document.querySelector('va-on-this-page')
293-
expect(onThisPageElement).toBeInTheDocument()
313+
expect(document.querySelector('va-on-this-page')).toBeInTheDocument()
314+
})
315+
316+
test('does not render on-this-page component when only one spoke exists', () => {
317+
const mockSpokes = [
318+
{
319+
type: 'paragraph--list_of_link_teasers' as const,
320+
id: 'spoke-1',
321+
entityId: 1,
322+
title: 'Get VA health care',
323+
isHubPage: true,
324+
linkTeasers: [
325+
{
326+
type: 'paragraph--link_teaser' as const,
327+
id: 'teaser-1',
328+
entityId: 2,
329+
uri: '/health-care/apply/',
330+
title: 'Apply for health care',
331+
options: [],
332+
summary: 'Apply for VA health care benefits',
333+
isHubPage: true,
334+
componentParams: {
335+
sectionHeader: 'Get VA health care',
336+
},
337+
},
338+
],
339+
},
340+
]
341+
342+
render(
343+
<BenefitsHub
344+
{...mockBenefitsData}
345+
title={'Benefits Hub with One Spoke'}
346+
intro={'Testing with a single spoke.'}
347+
spokes={mockSpokes}
348+
fieldLinks={null}
349+
connectWithUs={null}
350+
relatedLinks={null}
351+
/>
352+
)
353+
354+
expect(document.querySelector('va-on-this-page')).not.toBeInTheDocument()
294355
})
295356

296-
test('does not render on-this-page component when no spokes exist', () => {
357+
test('does not render on-this-page component when spokes is empty', () => {
297358
render(
298359
<BenefitsHub
299360
{...mockBenefitsData}
@@ -306,9 +367,7 @@ describe('BenefitsHub with valid data', () => {
306367
/>
307368
)
308369

309-
// Check that the va-on-this-page element is not rendered when spokes is empty
310-
const onThisPageElement = document.querySelector('va-on-this-page')
311-
expect(onThisPageElement).not.toBeInTheDocument()
370+
expect(document.querySelector('va-on-this-page')).not.toBeInTheDocument()
312371
})
313372

314373
test('does not render on-this-page component when spokes is null', () => {
@@ -321,9 +380,7 @@ describe('BenefitsHub with valid data', () => {
321380
/>
322381
)
323382

324-
// Check that the va-on-this-page element is not rendered when spokes is null
325-
const onThisPageElement = document.querySelector('va-on-this-page')
326-
expect(onThisPageElement).not.toBeInTheDocument()
383+
expect(document.querySelector('va-on-this-page')).not.toBeInTheDocument()
327384
})
328385
test('renders BenefitsHub component with relatedLinks', () => {
329386
const mockRelatedLinks = {

src/components/benefitsHub/template.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function BenefitsHub({
4747
dangerouslySetInnerHTML={{ __html: intro }}
4848
/>
4949
)}
50-
{spokes?.length > 0 && <va-on-this-page></va-on-this-page>}
50+
{spokes?.length > 1 && <va-on-this-page></va-on-this-page>}
5151
{alert && <AlertBlock {...alert} />}
5252
{spokes?.map((spokeSection) => (
5353
<div key={spokeSection.id}>

0 commit comments

Comments
 (0)