import type { EvaluatedBlock } from '@ministryofjustice/hmpps-forge/core/components' import { GovUKHeading } from './govukHeading' const render = (props: Record) => GovUKHeading.render(props as EvaluatedBlock) describe('GovUKHeading', () => { describe('block building', () => { it('should stamp the govukHeading variant when called as a builder', () => { // Arrange & Act const built = GovUKHeading({ text: 'Page title' }) // Assert expect(built.variant).toBe('govukHeading') }) }) describe('rendering', () => { it('should render an h1 with the large heading class by default', () => { // Arrange & Act const output = render({ text: 'Page title' }) // Assert expect(output).toBe('

Page title

') }) it('should default the level from the size', () => { // Arrange & Act const medium = render({ text: 'Section', size: 'm' }) const small = render({ text: 'Subsection', size: 's' }) const extraLarge = render({ text: 'Page', size: 'xl' }) // Assert expect(medium).toBe('

Section

') expect(small).toBe('

Subsection

') expect(extraLarge).toBe('

Page

') }) it('should let an explicit level override the size default', () => { // Arrange & Act const output = render({ text: 'Goal', size: 'm', level: 4 }) // Assert expect(output).toBe('

Goal

') }) it('should render a caption above the heading text matched to the size', () => { // Arrange & Act const output = render({ text: 'Page title', size: 'xl', caption: 'Section name' }) // Assert expect(output).toBe( '

Section namePage title

', ) }) it('should append additional classes and attributes', () => { // Arrange & Act const output = render({ text: 'Title', classes: 'app-title', attributes: { id: 'main-title' } }) // Assert expect(output).toBe('

Title

') }) it('should render HTML in the text and caption unescaped', () => { // Arrange & Act const output = render({ text: 'Goal: saving', caption: 'SP' }) // Assert expect(output).toBe( '

SPGoal: saving

', ) }) }) })