import { describe, it, expect } from 'vitest';
import { sanitizeHtml } from '../src/lib/sanitize';

describe('sanitizeHtml', () => {
  it('mantiene la formattazione consentita', () => {
    const html = '<h2>Titolo</h2><p>Testo <strong>forte</strong> ed <em>enfasi</em></p><ul><li>voce</li></ul><blockquote>citazione</blockquote>';
    expect(sanitizeHtml(html)).toBe(html);
  });
  it('rimuove script e handler', () => {
    expect(sanitizeHtml('<p onclick="x()">ciao</p><script>alert(1)</script>')).toBe('<p>ciao</p>');
  });
  it('consente immagini locali e https, blocca javascript:', () => {
    expect(sanitizeHtml('<img src="/uploads/a.jpg">')).toContain('/uploads/a.jpg');
    expect(sanitizeHtml('<a href="javascript:alert(1)">x</a>')).toBe('<a>x</a>');
  });
});
