import { HtmlBlock } from './html' import type { EvaluatedBlock } from '../../components/types/structures.type' import { StructureType } from '../../authoring/types/enums' describe('html component', () => { const mockBlock = (overrides?: Partial): EvaluatedBlock => ({ type: StructureType.BLOCK, variant: 'html', content: '

Default content

', ...overrides, }) as EvaluatedBlock it('should render HTML content without wrapper', async () => { const block = mockBlock({ content: '

Test content

', }) const result = await HtmlBlock.render(block) expect(result).toBe('

Test content

') }) it('should render HTML content with wrapper div when classes are provided', async () => { const block = mockBlock({ content: '

Test content

', classes: 'custom-class', }) const result = await HtmlBlock.render(block) expect(result).toBe('

Test content

') }) it('should render HTML content with wrapper div when attributes are provided', async () => { const block = mockBlock({ content: '

Test content

', attributes: { 'data-test': 'value', id: 'test-id', }, }) const result = await HtmlBlock.render(block) expect(result).toBe('

Test content

') }) it('should render HTML content with wrapper div when both classes and attributes are provided', async () => { const block = mockBlock({ content: '

Test content

', classes: 'custom-class', attributes: { 'data-test': 'value', }, }) const result = await HtmlBlock.render(block) expect(result).toBe('

Test content

') }) it('should render complex HTML content', async () => { const block = mockBlock({ content: `

By proceeding, you agree to our Terms of Service

`, }) const result = await HtmlBlock.render(block) expect(result).toBe(`

By proceeding, you agree to our Terms of Service

`) }) it('should have the correct variant', () => { expect(HtmlBlock.variant).toBe('html') }) describe('tag element', () => { it('should render content within the specified tag', async () => { // Arrange const block = mockBlock({ tag: 'p', content: 'Hello world' }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('

Hello world

') }) it('should apply classes to the tag element', async () => { // Arrange const block = mockBlock({ tag: 'h1', content: 'Title', classes: 'govuk-heading-l' }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('

Title

') }) it('should apply attributes to the tag element', async () => { // Arrange const block = mockBlock({ tag: 'p', content: 'Text', attributes: { id: 'intro' } }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('

Text

') }) it('should apply both classes and attributes to the tag element', async () => { // Arrange const block = mockBlock({ tag: 'p', content: 'Text', classes: 'govuk-body', attributes: { 'data-test': 'value' }, }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('

Text

') }) it('should render void elements as self-closing', async () => { // Arrange const block = mockBlock({ tag: 'hr', classes: 'govuk-section-break' }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('
') }) it('should ignore content for void elements', async () => { // Arrange const block = mockBlock({ tag: 'hr', content: 'should be ignored', classes: 'govuk-section-break' }) // Act const result = await HtmlBlock.render(block) // Assert expect(result).toBe('
') }) }) })