diff --git a/src/components/shared/MarkdownRenderer.test.ts b/src/components/shared/MarkdownRenderer.test.ts new file mode 100644 index 00000000..7c1e02af --- /dev/null +++ b/src/components/shared/MarkdownRenderer.test.ts @@ -0,0 +1,147 @@ +import { describe, it, expect } from 'vitest'; +import { markdownToHtml } from './MarkdownRenderer'; + +// Tests cover the pure markdownToHtml function (no DOM/React needed). + +describe('markdownToHtml', () => { + it('returns empty string for empty input', () => { + expect(markdownToHtml('')).toBe(''); + }); + + // ── Headings ────────────────────────────────────────────────────────────── + + it('renders h1', () => { + expect(markdownToHtml('# Hello')).toContain('

Hello

'); + }); + + it('renders h2', () => { + expect(markdownToHtml('## Section')).toContain('

Section

'); + }); + + it('renders h3', () => { + expect(markdownToHtml('### Sub')).toContain('

Sub

'); + }); + + // ── Emphasis ────────────────────────────────────────────────────────────── + + it('renders bold with **', () => { + expect(markdownToHtml('This is **bold** text')).toContain('bold'); + }); + + it('renders bold with __', () => { + expect(markdownToHtml('This is __bold__ text')).toContain('bold'); + }); + + it('renders italic with *', () => { + expect(markdownToHtml('This is *italic* text')).toContain('italic'); + }); + + it('renders italic with _', () => { + expect(markdownToHtml('This is _italic_ text')).toContain('italic'); + }); + + // ── Inline code ─────────────────────────────────────────────────────────── + + it('renders inline code', () => { + expect(markdownToHtml('Use `console.log` here')).toContain('console.log'); + }); + + // ── Fenced code blocks ──────────────────────────────────────────────────── + + it('renders fenced code block', () => { + const md = '```js\nconsole.log("hi");\n```'; + const html = markdownToHtml(md); + expect(html).toContain('
 {
+    const md = '```typescript\nconst x = 1;\n```';
+    expect(markdownToHtml(md)).toContain('class="language-typescript"');
+  });
+
+  it('escapes HTML inside code blocks', () => {
+    const md = '```\n\n```';
+    expect(markdownToHtml(md)).not.toContain('\n```';
+    const html = markdownToHtml(md);
+    expect(html).not.toContain('