import {createRef} from 'react'
import {describe, expect, it} from 'vitest'
import {render, screen} from '../../test-utils'
import {ProductReviewStars} from './product-review-stars'
describe('ProductReviewStars', () => {
it('renders without crashing', () => {
const {container} = render(
)
// Component should render something
expect(container.firstChild).toBeInTheDocument()
})
describe('review count display', () => {
it('displays review count', () => {
render()
expect(screen.getByText('(42)')).toBeInTheDocument()
})
it('formats large numbers as K', () => {
render()
expect(screen.getByText('(1K)')).toBeInTheDocument()
})
it('formats millions as M', () => {
render()
expect(screen.getByText('(1.5M)')).toBeInTheDocument()
})
it('does not display review count when zero', () => {
render()
expect(screen.queryByText('(0)')).not.toBeInTheDocument()
})
it('does not display review count when null', () => {
render()
expect(screen.queryByText(/\(\d+\)/)).not.toBeInTheDocument()
})
})
describe('accessibility', () => {
it('forwards ref to container element', () => {
const ref = createRef()
render(
)
expect(ref.current).toBeInstanceOf(HTMLDivElement)
})
it('accepts aria-label for accessibility', () => {
render(
)
const element = screen.getByTestId('rating-stars')
expect(element).toHaveAttribute(
'aria-label',
'4.5 out of 5 stars, 100 reviews'
)
})
})
describe('edge cases', () => {
it('handles negative ratings gracefully', () => {
// Should not crash with invalid input
const {container} = render(
)
expect(container.firstChild).toBeInTheDocument()
})
it('handles very large ratings gracefully', () => {
// Should not crash with invalid input
const {container} = render(
)
expect(container.firstChild).toBeInTheDocument()
})
})
})