import { describe, expect, it } from 'vitest';
import { renderMarkdown } from './render';

describe('renderMarkdown', () => {
  it('rendert Überschriften aller Ebenen', () => {
    const html = renderMarkdown('# H1\n\n## H2\n\n### H3');
    expect(html).toContain('<h1>H1</h1>');
    expect(html).toContain('<h2>H2</h2>');
    expect(html).toContain('<h3>H3</h3>');
  });

  it('rendert Tabellen mit Kopfzeile', () => {
    const html = renderMarkdown('| Pflicht | Frist |\n|---|---|\n| QMS | 2027 |');
    expect(html).toContain('<th>Pflicht</th>');
    expect(html).toContain('<td>QMS</td>');
    expect(html).not.toContain('---');
  });

  it('rendert Meta-Tabellen mit leerer Kopfzeile', () => {
    const html = renderMarkdown('| | |\n|---|---|\n| **KI-System** | Chatbot |');
    expect(html).toContain('<strong>KI-System</strong>');
    expect(html).toContain('<td>Chatbot</td>');
  });

  it('rendert Listen und Blockquotes', () => {
    const html = renderMarkdown('- Punkt eins\n- Punkt zwei\n\n> Hinweis');
    expect(html).toContain('<li>Punkt eins</li>');
    expect(html).toContain('<blockquote>Hinweis</blockquote>');
  });

  it('rendert Inline-Formatierung', () => {
    const html = renderMarkdown('Das ist **wichtig** und _offen_.');
    expect(html).toContain('<strong>wichtig</strong>');
    expect(html).toContain('<em>offen</em>');
  });

  it('maskiert HTML in Eingaben (kein Injection über Systemnamen)', () => {
    const html = renderMarkdown('# <script>alert(1)</script>');
    expect(html).not.toContain('<script>');
    expect(html).toContain('&lt;script&gt;');
  });
});
