test: add comprehensive unit tests for all components, API routes, and lib functions
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import ArticleBody from '@/components/article/ArticleBody'
|
||||
|
||||
describe('ArticleBody', () => {
|
||||
it('renders HTML content', () => {
|
||||
render(<ArticleBody html="<p>Hello world</p>" />)
|
||||
expect(screen.getByText('Hello world')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders multiple HTML elements', () => {
|
||||
render(<ArticleBody html="<h1>Title</h1><p>Paragraph</p>" />)
|
||||
expect(screen.getByText('Title')).toBeInTheDocument()
|
||||
expect(screen.getByText('Paragraph')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies the article-body class', () => {
|
||||
const { container } = render(<ArticleBody html="<p>Test</p>" />)
|
||||
expect(container.firstChild).toHaveClass('article-body')
|
||||
})
|
||||
|
||||
it('renders complex HTML including images and links', () => {
|
||||
const html = '<p>Text with <a href="/test">a link</a> and <img src="img.jpg" alt="pic" /></p>'
|
||||
render(<ArticleBody html={html} />)
|
||||
expect(screen.getByText('a link')).toBeInTheDocument()
|
||||
expect(screen.getByAltText('pic')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders empty string without crashing', () => {
|
||||
const { container } = render(<ArticleBody html="" />)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user