import { describe, expect, it } from 'vitest'; import { htmlToReadableText } from '@/lib/html-to-readable-text'; describe('htmlToReadableText', () => { it('keeps paragraphs and line breaks', () => { expect(htmlToReadableText('

Hello Ann,

first line
second line

')) .toBe('Hello Ann,\n\nfirst line\nsecond line'); }); it('keeps link targets and image alt text', () => { expect(htmlToReadableText('

Read the report Logo

')) .toBe('Read the report (https://ex.com/a) [Logo]'); }); it('does not repeat a target that is the link text, and drops script and style', () => { expect(htmlToReadableText('ex.com')) .toBe('ex.com'); expect(htmlToReadableText('Write to Ann')) .toBe('Write to Ann (ann@ex.com)'); }); it('turns layout tables into lines and lists into bullets', () => { const html = '
NameAnn
CityBerlin
'; expect(htmlToReadableText(html)).toBe('Name Ann\nCity Berlin\n\n• one\n• two'); }); it('skips hidden preheaders and images without alt text', () => { expect(htmlToReadableText('
preheader

Body

')).toBe('Body'); }); });