|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import { Callout } from './Container'; |
| 3 | + |
| 4 | +describe('Callout Component', () => { |
| 5 | + describe('rendering', () => { |
| 6 | + it('should be visible', () => { |
| 7 | + render(<Callout>Test content</Callout>); |
| 8 | + expect(screen.getByText('Test content')).toBeVisible(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should render children correctly', () => { |
| 12 | + const testText = 'This is a test callout message'; |
| 13 | + render(<Callout>{testText}</Callout>); |
| 14 | + expect(screen.getByText(testText)).toBeInTheDocument(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should render complex children', () => { |
| 18 | + render( |
| 19 | + <Callout> |
| 20 | + <div> |
| 21 | + <span>Complex</span> content with <strong>HTML</strong> |
| 22 | + </div> |
| 23 | + </Callout>, |
| 24 | + ); |
| 25 | + expect(screen.getByText('Complex')).toBeInTheDocument(); |
| 26 | + expect(screen.getByText('HTML')).toBeInTheDocument(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('info callout', () => { |
| 31 | + it('should display info icon when info prop is true', () => { |
| 32 | + render(<Callout info>Info message</Callout>); |
| 33 | + expect(screen.getByText('ℹ️')).toBeInTheDocument(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should have correct info styling', () => { |
| 37 | + const { container } = render(<Callout info>Info message</Callout>); |
| 38 | + const calloutDiv = container.firstChild as HTMLElement; |
| 39 | + expect(calloutDiv).toHaveClass('bg-blue-100', 'text-blue-800'); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('warning callout', () => { |
| 44 | + it('should display warning icon when warning prop is true', () => { |
| 45 | + render(<Callout warning>Warning message</Callout>); |
| 46 | + expect(screen.getByText('⚠️')).toBeInTheDocument(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should have correct warning styling', () => { |
| 50 | + const { container } = render(<Callout warning>Warning message</Callout>); |
| 51 | + const calloutDiv = container.firstChild as HTMLElement; |
| 52 | + expect(calloutDiv).toHaveClass('bg-yellow-100', 'text-yellow-800'); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('error callout', () => { |
| 57 | + it('should display error icon when error prop is true', () => { |
| 58 | + render(<Callout error>Error message</Callout>); |
| 59 | + expect(screen.getByText('❗')).toBeInTheDocument(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should have correct error styling', () => { |
| 63 | + const { container } = render(<Callout error>Error message</Callout>); |
| 64 | + const calloutDiv = container.firstChild as HTMLElement; |
| 65 | + expect(calloutDiv).toHaveClass('bg-red-100', 'text-red-800'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should default to error when no type is specified', () => { |
| 69 | + render(<Callout>Default message</Callout>); |
| 70 | + expect(screen.getByText('❗')).toBeInTheDocument(); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('type priority', () => { |
| 75 | + it('should prioritize info over warning and error', () => { |
| 76 | + render( |
| 77 | + <Callout info warning error> |
| 78 | + Priority test |
| 79 | + </Callout>, |
| 80 | + ); |
| 81 | + expect(screen.getByText('ℹ️')).toBeInTheDocument(); |
| 82 | + expect(screen.queryByText('⚠️')).not.toBeInTheDocument(); |
| 83 | + expect(screen.queryByText('❗')).not.toBeInTheDocument(); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should prioritize warning over error when info is false', () => { |
| 87 | + render( |
| 88 | + <Callout warning error> |
| 89 | + Priority test |
| 90 | + </Callout>, |
| 91 | + ); |
| 92 | + expect(screen.getByText('⚠️')).toBeInTheDocument(); |
| 93 | + expect(screen.queryByText('❗')).not.toBeInTheDocument(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + describe('styling and classes', () => { |
| 98 | + it('should have base classes', () => { |
| 99 | + const { container } = render(<Callout>Test</Callout>); |
| 100 | + const calloutDiv = container.firstChild as HTMLElement; |
| 101 | + expect(calloutDiv).toHaveClass( |
| 102 | + 'flex', |
| 103 | + 'flex-row', |
| 104 | + 'gap-1.75', |
| 105 | + 'px-4', |
| 106 | + 'py-1', |
| 107 | + 'rounded-lg', |
| 108 | + ); |
| 109 | + }); |
| 110 | + |
| 111 | + it('should have correct text styling for content', () => { |
| 112 | + render(<Callout>Test content</Callout>); |
| 113 | + const contentDiv = screen.getByText('Test content'); |
| 114 | + expect(contentDiv).toHaveClass('text-[0.95rem]', 'pr-1'); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should have correct icon styling', () => { |
| 118 | + render(<Callout info>Test</Callout>); |
| 119 | + const iconDiv = screen.getByText('ℹ️'); |
| 120 | + expect(iconDiv).toHaveClass('text-2xl', 'pt-3.5'); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + describe('accessibility', () => { |
| 125 | + it('should be accessible with proper structure', () => { |
| 126 | + render(<Callout info>Accessible content</Callout>); |
| 127 | + const content = screen.getByText('Accessible content'); |
| 128 | + expect(content).toBeInTheDocument(); |
| 129 | + expect(content.closest('div')).toBeInTheDocument(); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should maintain semantic structure for screen readers', () => { |
| 133 | + const { container } = render( |
| 134 | + <Callout warning>Important warning message</Callout>, |
| 135 | + ); |
| 136 | + expect(container.firstChild).toHaveAttribute('class'); |
| 137 | + expect(screen.getByText('Important warning message')).toBeInTheDocument(); |
| 138 | + expect(screen.getByText('⚠️')).toBeInTheDocument(); |
| 139 | + }); |
| 140 | + }); |
| 141 | +}); |
0 commit comments