import { fireEvent, render, screen } from '@testing-library/react' import { EffectColor } from './chunk-structure/types' import OptionCard from './option-card' // Note: react-i18next is globally mocked in vitest.setup.ts describe('OptionCard', () => { const defaultProps = { id: 'test-id', title: 'Test Title', } beforeEach(() => { vi.clearAllMocks() }) describe('Rendering', () => { it('should render without crashing', () => { render() expect(screen.getByText('Test Title')).toBeInTheDocument() }) it('should render title', () => { render() expect(screen.getByText('Custom Title')).toBeInTheDocument() }) it('should render description when provided', () => { render() expect(screen.getByText('Test Description')).toBeInTheDocument() }) it('should not render description when not provided', () => { render() expect(screen.queryByText(/description/i)).not.toBeInTheDocument() }) it('should render icon when provided', () => { render(Icon} />) expect(screen.getByTestId('test-icon')).toBeInTheDocument() }) it('should not render icon container when icon is not provided', () => { const { container } = render() const iconContainers = container.querySelectorAll('.size-6') expect(iconContainers).toHaveLength(0) }) }) describe('Active State', () => { it('should apply active styles when isActive is true', () => { const { container } = render() const card = container.firstChild expect(card).toHaveClass('ring-[1px]') }) it('should not apply active styles when isActive is false', () => { const { container } = render() const card = container.firstChild expect(card).not.toHaveClass('ring-[1px]') }) it('should apply iconActiveColor when isActive is true and icon is present', () => { const { container } = render( Icon} iconActiveColor="text-red-500" />, ) const iconContainer = container.querySelector('.text-red-500') expect(iconContainer).toBeInTheDocument() }) }) describe('Disabled State', () => { it('should apply disabled styles when disabled is true', () => { const { container } = render() const card = container.firstChild expect(card).toHaveClass('cursor-not-allowed') expect(card).toHaveClass('opacity-50') }) it('should not call onClick when disabled', () => { const handleClick = vi.fn() render() const card = screen.getByText('Test Title').closest('div')?.parentElement?.parentElement fireEvent.click(card!) expect(handleClick).not.toHaveBeenCalled() }) it('should not call onClick when isActive', () => { const handleClick = vi.fn() render() const card = screen.getByText('Test Title').closest('div')?.parentElement?.parentElement fireEvent.click(card!) expect(handleClick).not.toHaveBeenCalled() }) }) describe('Recommended Badge', () => { it('should render recommended badge when isRecommended is true', () => { render() // Badge uses translation key expect(screen.getByText(/stepTwo\.recommend/)).toBeInTheDocument() }) it('should not render recommended badge when isRecommended is false', () => { render() expect(screen.queryByText(/stepTwo\.recommend/)).not.toBeInTheDocument() }) }) describe('Effect Color', () => { it('should render effect color when effectColor and showEffectColor are provided', () => { const { container } = render( , ) const effectElement = container.querySelector('.blur-\\[80px\\]') expect(effectElement).toBeInTheDocument() }) it('should not render effect color when showEffectColor is false', () => { const { container } = render( , ) const effectElement = container.querySelector('.blur-\\[80px\\]') expect(effectElement).not.toBeInTheDocument() }) it('should not render effect color when effectColor is not provided', () => { const { container } = render( , ) const effectElement = container.querySelector('.blur-\\[80px\\]') expect(effectElement).not.toBeInTheDocument() }) it('should apply indigo effect color class', () => { const { container } = render( , ) const effectElement = container.querySelector('.bg-util-colors-indigo-indigo-600') expect(effectElement).toBeInTheDocument() }) it('should apply blueLight effect color class', () => { const { container } = render( , ) const effectElement = container.querySelector('.bg-util-colors-blue-light-blue-light-600') expect(effectElement).toBeInTheDocument() }) it('should apply orange effect color class', () => { const { container } = render( , ) const effectElement = container.querySelector('.bg-util-colors-orange-orange-500') expect(effectElement).toBeInTheDocument() }) it('should apply purple effect color class', () => { const { container } = render( , ) const effectElement = container.querySelector('.bg-util-colors-purple-purple-600') expect(effectElement).toBeInTheDocument() }) }) describe('Children', () => { it('should render children when children and showChildren are provided', () => { render(
Child Content
, ) expect(screen.getByTestId('child-content')).toBeInTheDocument() }) it('should not render children when showChildren is false', () => { render(
Child Content
, ) expect(screen.queryByTestId('child-content')).not.toBeInTheDocument() }) it('should not render children container when children is not provided', () => { const { container } = render( , ) const childContainer = container.querySelector('.bg-components-panel-bg') expect(childContainer).not.toBeInTheDocument() }) it('should render arrow shape when children are shown', () => { const { container } = render(
Child
, ) // ArrowShape renders an SVG const childSection = container.querySelector('.bg-components-panel-bg') expect(childSection).toBeInTheDocument() }) }) describe('User Interactions', () => { it('should call onClick with id when clicked', () => { const handleClick = vi.fn() render() const card = screen.getByText('Test Title').closest('div')?.parentElement?.parentElement fireEvent.click(card!) expect(handleClick).toHaveBeenCalledWith('my-id') }) it('should have cursor-pointer class', () => { const { container } = render() const card = container.firstChild expect(card).toHaveClass('cursor-pointer') }) }) describe('Props', () => { it('should apply custom className', () => { const { container } = render() const innerContainer = container.querySelector('.custom-class') expect(innerContainer).toBeInTheDocument() }) it('should forward ref', () => { const ref = vi.fn() render() expect(ref).toHaveBeenCalled() }) }) describe('Edge Cases', () => { it('should handle empty title', () => { render() // Component should still render const { container } = render() expect(container.firstChild).toBeInTheDocument() }) it('should handle complex id types', () => { const handleClick = vi.fn() const complexId = { key: 'value' } render() const card = screen.getByText('Test Title').closest('div')?.parentElement?.parentElement fireEvent.click(card!) expect(handleClick).toHaveBeenCalledWith(complexId) }) it('should handle numeric id', () => { const handleClick = vi.fn() render() const card = screen.getByText('Test Title').closest('div')?.parentElement?.parentElement fireEvent.click(card!) expect(handleClick).toHaveBeenCalledWith(123) }) it('should handle long title', () => { const longTitle = 'A'.repeat(200) render() expect(screen.getByText(longTitle)).toBeInTheDocument() }) it('should handle long description', () => { const longDesc = 'B'.repeat(500) render() expect(screen.getByText(longDesc)).toBeInTheDocument() }) it('should handle all props together', () => { const handleClick = vi.fn() render( Icon} iconActiveColor="text-blue-500" isActive={true} isRecommended={true} effectColor={EffectColor.indigo} showEffectColor={true} disabled={false} onClick={handleClick} className="full-class" showChildren={true} >
Children
, ) expect(screen.getByText('Full Test')).toBeInTheDocument() expect(screen.getByText('Full Description')).toBeInTheDocument() expect(screen.getByTestId('full-icon')).toBeInTheDocument() expect(screen.getByTestId('full-children')).toBeInTheDocument() }) }) })