import { describe, expect, it } from 'vitest';
import { cleanHtml, fromVisual, safeUrl, textToHtml, toVisual } from '../src/mailHtml';
describe( 'mail HTML', () => {
it( 'keeps formatting, links and placeholders and drops what could run', () => {
expect( cleanHtml( '
Hallo
fett Seite Mail
' ) ).toBe( 'Hallo
fett Seite Mail
' );
expect( cleanHtml( 'ab
' ) ).toBe( 'ab![]()
' );
} );
it( 'tells safe addresses from script addresses', () => {
expect( [ 'https://a.de', '/pfad', '#oben', 'tel:+49', '{{field:web}}', 'bild.png', '' ].every( safeUrl ) ).toBe( true );
expect( [ 'javascript:alert(1)', 'java\nscript:x', 'data:image/png;base64,x', 'vbscript:x' ].some( safeUrl ) ).toBe( false );
} );
it( 'shows line breaks as
and stores none when they are kept', () => {
expect( toVisual( 'Hallo\n\n{{answers}}', true ) ).toBe( 'Hallo
{{answers}}' );
expect( toVisual( 'a\nb
', false ) ).toBe( 'a\nb
' );
expect( fromVisual( 'Hallo
\nWelt
', true ) ).toBe( 'Hallo
Welt' );
expect( textToHtml( ' & \n' ) ).toBe( '<b> &
' );
} );
} );