test: add comprehensive unit tests for all components, API routes, and lib functions

This commit is contained in:
achmad
2026-05-31 17:20:01 +07:00
parent 963ff5affc
commit c62ac1da0b
10 changed files with 1062 additions and 0 deletions
+33
View File
@@ -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()
})
})