import { render, screen } from '@testing-library/react'
import Badge from './badge'
describe('Badge', () => {
describe('Rendering', () => {
it('should render without crashing', () => {
render()
expect(screen.getByText(/beta/i)).toBeInTheDocument()
})
it('should render with children instead of text', () => {
render(child content)
expect(screen.getByText(/child content/i)).toBeInTheDocument()
})
it('should render with no text or children', () => {
const { container } = render()
expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveTextContent('')
})
})
describe('Props', () => {
it('should apply custom className', () => {
const { container } = render()
const badge = container.firstChild as HTMLElement
expect(badge).toHaveClass('my-custom')
})
it('should retain base classes when custom className is applied', () => {
const { container } = render()
const badge = container.firstChild as HTMLElement
expect(badge).toHaveClass('relative', 'inline-flex', 'h-5', 'items-center')
})
it('should apply uppercase class by default', () => {
const { container } = render()
const badge = container.firstChild as HTMLElement
expect(badge).toHaveClass('system-2xs-medium-uppercase')
})
it('should apply non-uppercase class when uppercase is false', () => {
const { container } = render()
const badge = container.firstChild as HTMLElement
expect(badge).toHaveClass('system-xs-medium')
expect(badge).not.toHaveClass('system-2xs-medium-uppercase')
})
it('should render red corner mark when hasRedCornerMark is true', () => {
const { container } = render()
const mark = container.querySelector('.bg-components-badge-status-light-error-bg')
expect(mark).toBeInTheDocument()
})
it('should not render red corner mark by default', () => {
const { container } = render()
const mark = container.querySelector('.bg-components-badge-status-light-error-bg')
expect(mark).not.toBeInTheDocument()
})
it('should prioritize children over text', () => {
render(child wins)
expect(screen.getByText(/child wins/i)).toBeInTheDocument()
expect(screen.queryByText(/text content/i)).not.toBeInTheDocument()
})
it('should render ReactNode as text prop', () => {
render(bold badge} />)
expect(screen.getByText(/bold badge/i)).toBeInTheDocument()
})
})
describe('Edge Cases', () => {
it('should render with empty string text', () => {
const { container } = render()
expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveTextContent('')
})
it('should render with hasRedCornerMark false explicitly', () => {
const { container } = render()
const mark = container.querySelector('.bg-components-badge-status-light-error-bg')
expect(mark).not.toBeInTheDocument()
})
})
})