import { describe, expect, it } from 'vitest'
import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
describe('markdownRendererUtil', () => {
describe('renderMarkdownToHtml', () => {
it('should render basic markdown to HTML', () => {
const markdown = '# Hello\n\nThis is a test.'
const html = renderMarkdownToHtml(markdown)
expect(html).toContain('
')
expect(html).toContain('This is a test.')
})
it('should render links with target="_blank" and rel="noopener noreferrer"', () => {
const markdown = '[Click here](https://example.com)'
const html = renderMarkdownToHtml(markdown)
expect(html).toContain('target="_blank"')
expect(html).toContain('rel="noopener noreferrer"')
expect(html).toContain('href="https://example.com"')
expect(html).toContain('Click here')
})
it('should render multiple links with target="_blank"', () => {
const markdown =
'[Link 1](https://example.com) and [Link 2](https://test.com)'
const html = renderMarkdownToHtml(markdown)
const targetBlankMatches = html.match(/target="_blank"/g)
expect(targetBlankMatches).toHaveLength(2)
const relMatches = html.match(/rel="noopener noreferrer"/g)
expect(relMatches).toHaveLength(2)
})
it('should handle relative image paths with baseUrl', () => {
const markdown = ''
const baseUrl = 'https://cdn.example.com'
const html = renderMarkdownToHtml(markdown, baseUrl)
expect(html).toContain(`src="${baseUrl}/image.png"`)
expect(html).toContain('alt="Alt text"')
})
it('should not modify absolute image URLs', () => {
const markdown = ''
const baseUrl = 'https://cdn.example.com'
const html = renderMarkdownToHtml(markdown, baseUrl)
expect(html).toContain('src="https://example.com/image.png"')
expect(html).not.toContain(baseUrl)
})
it('should handle empty markdown', () => {
const html = renderMarkdownToHtml('')
expect(html).toBe('')
})
it('should sanitize potentially dangerous HTML', () => {
const markdown = ''
const html = renderMarkdownToHtml(markdown)
expect(html).not.toContain('