import { Fragment } from './fragment' import type { EvaluatedBlock } from '../../components/types/structures.type' import { StructureType } from '../../authoring/types/enums' const renderedBlock = (variant: string, html: string) => ({ block: { type: StructureType.BLOCK, variant }, html, }) const render = (blocks: unknown[]) => Fragment.render({ type: StructureType.BLOCK, variant: 'fragment', blocks, } as unknown as EvaluatedBlock) describe('fragment component', () => { it('should stamp the fragment variant when called as a builder', () => { const built = Fragment({ blocks: [] }) expect(built.variant).toBe('fragment') }) it('should concatenate child block HTML with no wrapper element', () => { const result = render([ renderedBlock('heading', '

Title

'), renderedBlock('body', '

Body

'), ]) expect(result).toBe('

Title

Body

') }) it('should render an empty string for no blocks', () => { expect(render([])).toBe('') }) it('should skip non-block children', () => { const result = render(['a string', renderedBlock('body', '

Body

'), null, undefined]) expect(result).toBe('

Body

') }) it('should flatten nested arrays of children in order', () => { const result = render([ [renderedBlock('body', '

One

'), renderedBlock('body', '

Two

')], renderedBlock('body', '

Three

'), ]) expect(result).toBe('

One

Two

Three

') }) })