import React from 'react' import { render, screen } from '@/test-utils' import userEvent from '@testing-library/user-event' import { ButtonsSection } from '@/components/atoms/ButtonsSection' import { Snippet } from '@/lib/types' describe('ButtonsSection Component', () => { const mockOnSaveSnippet = jest.fn() beforeEach(() => { jest.clearAllMocks() }) describe('Rendering', () => { it('should render without crashing', () => { render() expect(screen.getByText('Buttons')).toBeInTheDocument() }) it('should display the section title', () => { render() expect(screen.getByRole('heading', { name: 'Buttons', level: 2 })).toBeInTheDocument() }) it('should display the section description', () => { render() expect(screen.getByText(/Interactive controls with multiple variants and states/i)).toBeInTheDocument() }) it('should render ComponentShowcase with correct title', () => { render() const heading = screen.getByRole('heading', { level: 2 }) expect(heading.textContent).toContain('Button') }) }) describe('Button Variants Section', () => { it('should display Variants heading', () => { render() const headers = screen.getAllByText(/Variants/i) expect(headers.length).toBeGreaterThan(0) }) it('should render all button variants', () => { render() expect(screen.getAllByText('Default').length).toBeGreaterThan(0) expect(screen.getByText('Secondary')).toBeInTheDocument() expect(screen.getByText('Destructive')).toBeInTheDocument() expect(screen.getByText('Outline')).toBeInTheDocument() expect(screen.getByText('Ghost')).toBeInTheDocument() expect(screen.getByText('Link')).toBeInTheDocument() }) }) describe('Button Sizes Section', () => { it('should display Sizes heading', () => { render() const headers = screen.getAllByText(/Sizes/i) expect(headers.length).toBeGreaterThan(0) }) it('should render all button sizes', () => { render() expect(screen.getByText('Small')).toBeInTheDocument() expect(screen.getByText('Large')).toBeInTheDocument() }) }) describe('Button with Icons Section', () => { it('should display With Icons heading', () => { render() const headers = screen.getAllByText(/With Icons/i) expect(headers.length).toBeGreaterThan(0) }) it('should render buttons with icon combinations', () => { render() expect(screen.getByText('Favorite')).toBeInTheDocument() expect(screen.getByText('Add Item')).toBeInTheDocument() expect(screen.getByText('Quick Action')).toBeInTheDocument() }) }) describe('Button States Section', () => { it('should display States heading', () => { render() const headers = screen.getAllByText(/States/i) expect(headers.length).toBeGreaterThan(0) }) it('should render disabled buttons', () => { render() const disabledButtons = screen.getAllByRole('button', { disabled: true }) expect(disabledButtons.length).toBeGreaterThan(0) }) }) describe('Props Handling', () => { it('should accept onSaveSnippet prop', () => { render() expect(typeof mockOnSaveSnippet).toBe('function') }) it('should pass callback to ComponentShowcase', async () => { const user = userEvent.setup() render() const saveButtons = screen.queryAllByText(/Save as Snippet/i) if (saveButtons.length > 0) { await user.click(saveButtons[0]) } expect(typeof mockOnSaveSnippet).toBe('function') }) }) describe('Conditional Rendering', () => { it('should always render the section element', () => { render() const section = document.querySelector('section') expect(section).toBeInTheDocument() }) it('should render all button variation groups', () => { render() expect(screen.getAllByText('Default').length).toBeGreaterThan(0) expect(screen.getByText('Secondary')).toBeInTheDocument() }) }) describe('Accessibility', () => { it('should have proper semantic HTML', () => { render() expect(screen.getByRole('heading', { level: 2 })).toBeInTheDocument() }) it('should have descriptive text', () => { render() expect(screen.getByText(/Interactive controls with multiple variants and states/i)).toBeInTheDocument() }) it('should render section with proper structure', () => { const { container } = render() const section = container.querySelector('section') expect(section).toHaveClass('space-y-6') }) }) describe('Component Integration', () => { it('should render ComponentShowcase with atoms category', () => { render() const headings = screen.getAllByRole('heading', { level: 3 }) expect(headings.some(h => h.textContent?.includes('Icons'))).toBe(true) }) }) describe('Error States', () => { it('should not crash with valid props', () => { expect(() => { render() }).not.toThrow() }) }) })