Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/benefitsHub/template.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ describe('BenefitsHub with valid data', () => {
).toBeInTheDocument()
})

test('intro text splits on CRLF and renders br between segments', () => {
const { container } = render(
<BenefitsHub
{...mockBenefitsData}
intro={'First line\r\nSecond line\r\nThird'}
/>
)

const introRoot = container.querySelector('.va-introtext')
expect(introRoot?.querySelectorAll('br')).toHaveLength(2)
expect(introRoot).toHaveTextContent('First lineSecond lineThird')
})

test('intro text shows angle brackets as literal text, not nested markup', () => {
const introWithEscapedTags =
'Plain.\r\n<p>If you care</p>\r\n<script>evil()</script>'
const { container } = render(
<BenefitsHub {...mockBenefitsData} intro={introWithEscapedTags} />
)

const introParagraph = container.querySelector('p.va-introtext')
expect(introParagraph).toBeInTheDocument()
expect(
screen.getByText(/<script>evil\(\)<\/script>/, { exact: false })
).toBeInTheDocument()
})

test('renders BenefitsHub component with icon', () => {
render(
<BenefitsHub
Expand Down
13 changes: 9 additions & 4 deletions src/components/benefitsHub/template.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Fragment } from 'react'
import { getHubIcon } from '@/lib/utils/benefitsHub'
import { recordEvent } from '@/lib/analytics/recordEvent'
import { BenefitsHub as FormattedBenefitsHub } from './formatted-type'
Expand Down Expand Up @@ -42,10 +43,14 @@ export function BenefitsHub({
<h1>{title}</h1>
)}
{intro && (
<p
className="va-introtext"
dangerouslySetInnerHTML={{ __html: intro }}
/>
<p className="va-introtext">
{intro.split('\r\n').map((segment, index) => (
<Fragment key={index}>
{index > 0 ? <br /> : null}
{segment}
</Fragment>
))}
</p>
)}
{spokes?.length > 1 && <va-on-this-page></va-on-this-page>}
{alert && <AlertBlock {...alert} />}
Expand Down
Loading