import { describe, it, expect } from 'vitest'; import { convertHtmlToBlockNote, convertMarkdownToBlocks } from './contentConversion'; describe('convertHtmlToBlockNote', () => { it('should handle empty input', async () => { expect(await convertHtmlToBlockNote('')).toEqual([]); // @ts-ignore expect(await convertHtmlToBlockNote(null)).toEqual([]); // @ts-ignore expect(await convertHtmlToBlockNote(undefined)).toEqual([]); }); it('should convert simple paragraphs', async () => { const html = '
Hello World
'; const result = await convertHtmlToBlockNote(html); expect(result).toHaveLength(1); expect(result[0].type).toBe('paragraph'); const text = result[0].content?.find((c: any) => c.type === 'text'); expect(text?.text).toBe('Hello World'); }); it('should convert headings', async () => { const html = 'Bold and Italic
'; const result = await convertHtmlToBlockNote(html); const paragraph = result[0]; const content = paragraph.content || []; const boldSegment = content.find((c: any) => c.text === 'Bold'); expect(boldSegment?.styles).toMatchObject({ bold: true }); const italicSegment = content.find((c: any) => c.text === 'Italic'); expect(italicSegment?.styles).toMatchObject({ italic: true }); }); it('should handle links', async () => { const html = 'Click here
'; const result = await convertHtmlToBlockNote(html); const content = result[0].content || []; const linkSegment = content.find((c: any) => c.type === 'link'); expect(linkSegment).toBeDefined(); expect(linkSegment?.href).toBe('https://example.com'); }); it('should convert standalone images to image blocks', async () => { const html = '
Actual content
`; const result = await convertHtmlToBlockNote(html); // Should contain the paragraph with actual content const paragraph = result.find(b => b.type === 'paragraph'); expect(paragraph).toBeDefined(); const text = paragraph?.content?.find((c: any) => c.type === 'text'); expect(text?.text).toContain('Actual content'); // Should NOT contain CSS text const allText = result .flatMap(b => (b.content || [])) .filter((c: any) => c.type === 'text') .map((c: any) => c.text) .join(' '); expect(allText).not.toContain('font-family'); expect(allText).not.toContain('MsoNormal'); expect(allText).not.toContain('@font-face'); }); it('should strip Outlook conditional comments with CSS inside style tags', async () => { // Outlook/Word emails wrap CSS in and // also use insideHello from Outlook