/** * Unit Tests - Markdown Utility * Tests markdown conversion, TOC extraction, front matter parsing, and slug generation */ const { markdownToHtml, extractTOC, extractFrontMatter, generateSlug } = require('../../src/utils/markdown.util'); describe('Markdown Utility', () => { describe('markdownToHtml', () => { test('should return empty string for null input', () => { expect(markdownToHtml(null)).toBe(''); }); test('should return empty string for undefined input', () => { expect(markdownToHtml(undefined)).toBe(''); }); test('should return empty string for empty string', () => { expect(markdownToHtml('')).toBe(''); }); test('should convert basic paragraph', () => { const markdown = 'This is a paragraph.'; const html = markdownToHtml(markdown); expect(html).toContain('
This is a paragraph.
'); }); test('should convert headings with IDs', () => { const markdown = '# Test Heading'; const html = markdownToHtml(markdown); expect(html).toContain('code snippet');
});
test('should convert code blocks with language', () => {
const markdown = '```javascript\nconst x = 1;\n```';
const html = markdownToHtml(markdown);
expect(html).toContain(' {
const markdown = '```\nplain code\n```';
const html = markdownToHtml(markdown);
expect(html).toContain(' {
const markdown = `- Item 1
- Item 2
- Item 3`;
const html = markdownToHtml(markdown);
expect(html).toContain(''); expect(html).toContain('This is a quote'); expect(html).toContain(''); }); test('should convert tables', () => { const markdown = `| Header 1 | Header 2 | |----------|----------| | Cell 1 | Cell 2 |`; const html = markdownToHtml(markdown); expect(html).toContain('
| Header 1 | '); expect(html).toContain('Cell 1 | '); }); test('should sanitize dangerous HTML (XSS protection)', () => { const markdown = ''; const html = markdownToHtml(markdown); // Script tags should be removed expect(html).not.toContain('
|---|