Inline <span> component supporting success, warning, error, running, and muted variants with optional bold styling. Includes 7 unit tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { render, screen } from '@testing-library/react'
|
|
import { StatusText } from './StatusText'
|
|
|
|
describe('StatusText', () => {
|
|
it('renders children text', () => {
|
|
render(<StatusText variant="success">Online</StatusText>)
|
|
expect(screen.getByText('Online')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders as a span element', () => {
|
|
render(<StatusText variant="success">Status</StatusText>)
|
|
const el = screen.getByText('Status')
|
|
expect(el.tagName).toBe('SPAN')
|
|
})
|
|
|
|
it('applies variant class', () => {
|
|
render(<StatusText variant="error">Failed</StatusText>)
|
|
expect(screen.getByText('Failed')).toHaveClass('error')
|
|
})
|
|
|
|
it('applies bold class when bold=true', () => {
|
|
render(<StatusText variant="success" bold>OK</StatusText>)
|
|
expect(screen.getByText('OK')).toHaveClass('bold')
|
|
})
|
|
|
|
it('does not apply bold class by default', () => {
|
|
render(<StatusText variant="success">OK</StatusText>)
|
|
expect(screen.getByText('OK')).not.toHaveClass('bold')
|
|
})
|
|
|
|
it('accepts custom className', () => {
|
|
render(<StatusText variant="muted" className="custom">Text</StatusText>)
|
|
expect(screen.getByText('Text')).toHaveClass('custom')
|
|
})
|
|
|
|
it('renders all 5 variant classes correctly', () => {
|
|
const variants = ['success', 'warning', 'error', 'running', 'muted'] as const
|
|
for (const variant of variants) {
|
|
const { unmount } = render(
|
|
<StatusText variant={variant}>{variant}</StatusText>
|
|
)
|
|
expect(screen.getByText(variant)).toHaveClass(variant)
|
|
unmount()
|
|
}
|
|
})
|
|
})
|