import { BlockType, StructureType } from '@ministryofjustice/hmpps-forge/core/authoring' import type { RenderedBlock } from '@ministryofjustice/hmpps-forge/core/components' import { normaliseMojTextHtmlContent } from './mojParamNormalisers' const renderedBlock = (html: string): RenderedBlock => ({ block: { type: StructureType.BLOCK, blockType: BlockType.BASIC, variant: 'html', }, html, }) describe('normaliseMojTextHtmlContent', () => { it('should preserve text when html is present without blocks', () => { // Arrange const content = { text: 'Text remains', html: '
HTML
', } // Act const result = normaliseMojTextHtmlContent(content) // Assert expect(result).toEqual({ text: 'Text remains', html: 'HTML
' }) }) it('should suppress text and use blocks before html when blocks are present', () => { // Arrange const content = { text: 'Ignored', html: 'HTML ignored
', blocks: [renderedBlock('Block
')], } // Act const result = normaliseMojTextHtmlContent(content) // Assert expect(result).toEqual({ text: undefined, html: 'Block
' }) }) it('should return undefined html when blocks are empty and html is missing', () => { // Arrange const content = { text: 'Text remains', blocks: [], } // Act const result = normaliseMojTextHtmlContent(content) // Assert expect(result).toEqual({ text: 'Text remains', html: undefined }) }) })