import { describe, it, expect } from 'vitest'; import { sanitizeEmailHtml, sanitizeSignatureHtml, parseHtmlSafely, hasRichFormatting, } from '../email-sanitization'; describe('email-sanitization', () => { describe('sanitizeEmailHtml', () => { it('should remove script tags', () => { const malicious = '

Hello

'; const clean = sanitizeEmailHtml(malicious); expect(clean).not.toContain(''; const clean = sanitizeSignatureHtml(malicious); expect(clean).not.toContain(''; parseHtmlSafely(html); expect(executed).toBe(false); }); it('should handle malformed HTML gracefully', () => { const malformed = '

Unclosed

Tags'; const doc = parseHtmlSafely(malformed); expect(doc).toBeInstanceOf(Document); expect(doc.body.textContent).toContain('Unclosed'); }); }); describe('hasRichFormatting', () => { it('should detect tables', () => { const html = '
Data
'; expect(hasRichFormatting(html)).toBe(true); }); it('should detect images', () => { const html = ''; expect(hasRichFormatting(html)).toBe(true); }); it('should detect inline styles', () => { const html = '
Styled
'; expect(hasRichFormatting(html)).toBe(true); }); it('should detect formatting tags', () => { expect(hasRichFormatting('Bold')).toBe(true); expect(hasRichFormatting('Strong')).toBe(true); expect(hasRichFormatting('Emphasized')).toBe(true); }); it('should detect headings', () => { expect(hasRichFormatting('

Title

')).toBe(true); expect(hasRichFormatting('

Subtitle

')).toBe(true); }); it('should detect lists', () => { expect(hasRichFormatting('')).toBe(true); expect(hasRichFormatting('
  1. Item
')).toBe(true); }); it('should return false for plain text', () => { const plain = '

Just plain text

'; expect(hasRichFormatting(plain)).toBe(false); }); it('should return false for simple paragraphs', () => { const simple = '

Line 1

Line 2

'; expect(hasRichFormatting(simple)).toBe(false); }); it('should handle empty HTML', () => { expect(hasRichFormatting('')).toBe(false); expect(hasRichFormatting(' ')).toBe(false); }); }); });