import { describe, expect, it } from 'vitest'; import { appendHtmlSignature, appendPlainTextSignature, getPlainTextSignature, hasMeaningfulHtmlBody, } from '../signature-utils'; describe('signature-utils', () => { describe('getPlainTextSignature', () => { it('prefers text signatures when present', () => { expect(getPlainTextSignature({ textSignature: 'Regards,\nAlice', htmlSignature: '

Ignored

' })).toBe('Regards,\nAlice'); }); it('converts html-only signatures into plain text', () => { expect(getPlainTextSignature({ htmlSignature: '

Alice Example
alice@example.com

' })).toBe('Alice Example\nalice@example.com'); }); }); describe('appendPlainTextSignature', () => { it('appends a converted html signature to the text body', () => { expect(appendPlainTextSignature('Hello there', { htmlSignature: '

Alice
Engineering

' })).toBe('Hello there\n\n-- \nAlice\nEngineering'); }); it('leaves the body untouched when no signature exists', () => { expect(appendPlainTextSignature('Hello there', {})).toBe('Hello there'); }); }); describe('appendHtmlSignature', () => { it('appends a sanitized html signature, preserving formatting', () => { expect(appendHtmlSignature('
Hello
', { htmlSignature: 'Alice' })) .toBe('
Hello


--
Alice'); }); it('escapes and appends a text signature when no html signature exists', () => { expect(appendHtmlSignature('
Hello
', { textSignature: 'Alice\nEng' })) .toBe('
Hello


--
Alice
Eng'); }); it('omits the separator marker when disabled', () => { expect(appendHtmlSignature('
Hi
', { htmlSignature: 'A' }, { separator: false })) .toBe('
Hi


A'); }); it('leaves the body untouched when no signature exists', () => { expect(appendHtmlSignature('
Hi
', {})).toBe('
Hi
'); }); }); describe('hasMeaningfulHtmlBody', () => { it('prefers html bodies that preserve signature formatting', () => { expect(hasMeaningfulHtmlBody('
Hello

Alice

')).toBe(true); }); it('ignores minimal wrapper html with a single block', () => { expect(hasMeaningfulHtmlBody('
Hello world
')).toBe(false); }); }); });