import { describe, test, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { Item } from './item'
describe('Item', () => {
test('renders string children', () => {
render(- Test Content
)
expect(screen.getByText('Test Content')).toBeTruthy()
})
test('renders numeric children', () => {
render(- {123}
)
expect(screen.getByText('123')).toBeTruthy()
})
test('renders ReactNode children', () => {
render(
-
Complex Content
,
)
expect(screen.getByText('Complex')).toBeTruthy()
expect(screen.getByText('Content')).toBeTruthy()
})
test('renders as Typography with h5 variant', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.tagName).toBe('H5')
})
test('applies medium font weight', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.classList.contains('MuiTypography-root')).toBe(true)
})
test('applies default color', () => {
render(- Content
)
const element = screen.getByText('Content')
// Color is passed as a prop to Typography, not an HTML attribute
expect(element).toBeTruthy()
})
test('sets data-disabled attribute when disabled is true', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.getAttribute('data-disabled')).toBe('true')
})
test('does not set data-disabled attribute when disabled is false', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.getAttribute('data-disabled')).toBe('false')
})
test('does not set data-disabled attribute when disabled is undefined', () => {
render(- Content
)
const element = screen.getByText('Content')
// When undefined, data-disabled is not set or set to null/false
expect(element.getAttribute('data-disabled')).toBeFalsy()
})
test('accepts custom TypographyProps color', () => {
render(- Content
)
const element = screen.getByText('Content')
// Color is passed as a prop, not an HTML attribute
expect(element).toBeTruthy()
})
test('accepts custom TypographyProps variant', () => {
render(- Content
)
const element = screen.getByText('Content')
// Custom variant should override default h5
expect(element.tagName).toBe('H6')
})
test('accepts custom TypographyProps className', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.classList.contains('custom-class')).toBe(true)
})
test('accepts custom TypographyProps sx', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element).toBeTruthy()
})
test('accepts custom TypographyProps fontWeight', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element).toBeTruthy()
})
test('handles empty string children', () => {
const { container } = render(- {''}
)
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
})
test('handles zero as children', () => {
render(- {0}
)
expect(screen.getByText('0')).toBeTruthy()
})
test('handles negative numbers as children', () => {
render(- {-100}
)
expect(screen.getByText('-100')).toBeTruthy()
})
test('handles decimal numbers as children', () => {
render(- {123.456}
)
expect(screen.getByText('123.456')).toBeTruthy()
})
test('handles large numbers as children', () => {
render(- {1000000}
)
expect(screen.getByText('1000000')).toBeTruthy()
})
test('combines disabled and custom TypographyProps', () => {
render(
-
Content
,
)
const element = screen.getByText('Content')
expect(element.getAttribute('data-disabled')).toBe('true')
// Color is passed as a prop, not an HTML attribute
expect(element).toBeTruthy()
})
test('applies Typography classes', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element.classList.contains('MuiTypography-root')).toBe(true)
expect(element.classList.contains('MuiTypography-h5')).toBe(true)
})
test('handles null children', () => {
const { container } = render(- {null}
)
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
})
test('handles undefined children', () => {
const { container } = render(- {undefined}
)
expect(container.querySelector('.MuiTypography-root')).toBeTruthy()
})
test('handles multiple children elements', () => {
render(
-
First
Second
Third
,
)
expect(screen.getByText('First')).toBeTruthy()
expect(screen.getByText('Second')).toBeTruthy()
expect(screen.getByText('Third')).toBeTruthy()
})
test('handles mixed children types', () => {
render(
-
Text Element {123}
,
)
expect(screen.getByText(/Text/)).toBeTruthy()
expect(screen.getByText('Element')).toBeTruthy()
expect(screen.getByText(/123/)).toBeTruthy()
})
test('handles deeply nested children', () => {
render(
-
Nested
,
)
expect(screen.getByText('Nested')).toBeTruthy()
})
test('handles special characters in children', () => {
render(- Special: @#$%^&*()
)
expect(screen.getByText(/Special: @#\$%\^&\*\(\)/)).toBeTruthy()
})
test('handles long text content', () => {
const longText = 'A'.repeat(1000)
render(- {longText}
)
expect(screen.getByText(longText)).toBeTruthy()
})
test('handles unicode characters', () => {
render(- Unicode: 你好 🌍
)
expect(screen.getByText(/Unicode: 你好 🌍/)).toBeTruthy()
})
test('merges custom TypographyProps with default props', () => {
render(
-
Content
,
)
const element = screen.getByText('Content')
// Color is passed as a prop, not an HTML attribute
expect(element.classList.contains('custom')).toBe(true)
// variant body1 uses p tag
expect(element.tagName).toBe('P')
})
test('TypographyProps can override fontWeight', () => {
render(- Content
)
const element = screen.getByText('Content')
expect(element).toBeTruthy()
})
test('renders with all props combined', () => {
render(
-
Full Test
,
)
const element = screen.getByText('Full Test')
expect(element.getAttribute('data-disabled')).toBe('true')
// Color is passed as a prop, not an HTML attribute
expect(element.tagName).toBe('H6')
expect(element.classList.contains('test-class')).toBe(true)
})
})