import { describe, test, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { Title } from './title'
describe('Title', () => {
test('renders with string children', () => {
render(
Test Title)
expect(screen.getByText('Test Title')).toBeTruthy()
})
test('renders with ReactNode children', () => {
render(
Complex Title
,
)
expect(screen.getByText('Complex')).toBeTruthy()
expect(screen.getByText('Title')).toBeTruthy()
})
test('renders with custom label', () => {
render(Display Text)
// The component should render the children
expect(screen.getByText('Display Text')).toBeTruthy()
})
test('uses children as tooltip when children is string and no label', () => {
render(String Title)
expect(screen.getByText('String Title')).toBeTruthy()
})
test('uses empty string tooltip when children is not string and no label', () => {
render(
Complex Title
,
)
expect(screen.getByText('Complex Title')).toBeTruthy()
})
test('applies correct typography variant', () => {
render(Test Title)
const typography = screen.getByText('Test Title')
expect(typography.tagName).toBe('H6') // subtitle1 renders as h6
})
test('wraps content in SmartTooltip', () => {
render(Tooltip Title)
expect(screen.getByText('Tooltip Title')).toBeTruthy()
})
test('handles empty string children', () => {
render({''})
// Should render but be empty
const { container } = render({''})
expect(container).toBeTruthy()
})
test('handles numeric children', () => {
render({123})
expect(screen.getByText('123')).toBeTruthy()
})
test('renders with multiple children', () => {
render(
Part 1
Part 2
Part 3
,
)
expect(screen.getByText('Part 1')).toBeTruthy()
expect(screen.getByText('Part 2')).toBeTruthy()
expect(screen.getByText('Part 3')).toBeTruthy()
})
test('prefers label over string children for tooltip', () => {
render(Display Text)
expect(screen.getByText('Display Text')).toBeTruthy()
})
test('renders with undefined label and string children', () => {
render(String Children)
expect(screen.getByText('String Children')).toBeTruthy()
})
test('handles complex nested structure', () => {
render(
,
)
expect(screen.getByText('Nested')).toBeTruthy()
expect(screen.getByText('Content')).toBeTruthy()
})
test('ref is passed to Typography component', () => {
const { container } = render(Title with Ref)
expect(screen.getByText('Title with Ref')).toBeTruthy()
// The Typography component should be in the DOM
const typography = container.querySelector('[class*="MuiTypography"]')
expect(typography).toBeTruthy()
})
test('renders with textTransform none', () => {
render(Title Text)
expect(screen.getByText('Title Text')).toBeTruthy()
})
test('handles boolean children', () => {
render({true})
// Boolean children don't render text
const { container } = render({false})
expect(container).toBeTruthy()
})
test('handles null children', () => {
render({null})
// Null children don't render
const { container } = render({null})
expect(container).toBeTruthy()
})
})