import React from 'react' import { render, screen } from '@/test-utils' import userEvent from '@testing-library/user-event' import { ComponentShowcase } from '@/components/demo/ComponentShowcase' describe('ComponentShowcase Component', () => { const mockOnSaveSnippet = jest.fn() const defaultProps = { code: 'const example = () =>
Example
', title: 'Example Component', description: 'This is an example component', language: 'tsx', category: 'atoms', onSaveSnippet: mockOnSaveSnippet, children:
Example Content
, } beforeEach(() => { jest.clearAllMocks() }) describe('Rendering', () => { it('should render without crashing', () => { render() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should render children content', () => { render() expect(screen.getByText('Example Content')).toBeInTheDocument() }) it('should render Card component as wrapper', () => { const { container } = render() // Card typically has rounded-lg or similar classes const card = container.querySelector('[class*="rounded"]') expect(card).toBeInTheDocument() }) it('should render save button by default', () => { render() // Button may be hidden initially on hover const saveButtons = screen.queryAllByText(/Save as Snippet/i) expect(saveButtons.length).toBeGreaterThanOrEqual(0) }) }) describe('Save Button Interaction', () => { it('should show save button on hover', async () => { const { container } = render() const card = container.querySelector('[class*="group"]') if (card) { await userEvent.hover(card) const saveButton = screen.queryByText(/Save as Snippet/i) // Button may now be visible expect(saveButton).toBeDefined() } }) it('should call onSaveSnippet when save button is clicked', async () => { const user = userEvent.setup() render() const saveButtons = screen.queryAllByText(/Save as Snippet/i) // Try to click if visible if (saveButtons.length > 0) { await user.click(saveButtons[0]) // Component should have called the prop or opened dialog expect(mockOnSaveSnippet).toBeDefined() } }) }) describe('Props Handling', () => { it('should accept all required props', () => { expect(() => { render() }).not.toThrow() }) it('should use custom code prop', () => { const customCode = 'const customExample = () => null' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should use custom title prop', () => { const customTitle = 'Custom Title' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should use custom description prop', () => { const customDescription = 'Custom description' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should handle optional description prop', () => { const propsWithoutDescription = { ...defaultProps, description: undefined } expect(() => { render() }).not.toThrow() }) it('should use custom language prop', () => { const customLanguage = 'javascript' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should use custom category prop', () => { const customCategory = 'molecules' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) }) describe('Children Rendering', () => { it('should render complex children components', () => { const complexChildren = (

Complex Content

With multiple elements

) render( ) expect(screen.getByTestId('complex-children')).toBeInTheDocument() expect(screen.getByText('Complex Content')).toBeInTheDocument() }) it('should render text children', () => { render( ) expect(screen.getByText('Simple Text Content')).toBeInTheDocument() }) }) describe('Callback Props', () => { it('should accept onSaveSnippet callback', () => { render() expect(typeof mockOnSaveSnippet).toBe('function') }) it('should not call onSaveSnippet on initial render', () => { render() expect(mockOnSaveSnippet).not.toHaveBeenCalled() }) }) describe('Code Content', () => { it('should accept code string prop', () => { const codeExample = 'function test() { return "hello"; }' render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should handle empty code string', () => { render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should handle multiline code strings', () => { const multilineCode = ` function test() { return "hello"; } ` render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) }) describe('Language Support', () => { it('should handle tsx language', () => { render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should handle javascript language', () => { render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should handle other languages', () => { render( ) expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) }) describe('Component States', () => { it('should display in default state', () => { render() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should maintain state through re-renders', () => { const { rerender } = render() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() rerender() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) }) describe('Error Handling', () => { it('should handle all required props', () => { expect(() => { render() }).not.toThrow() }) it('should handle optional description missing', () => { const propsWithoutDesc = { ...defaultProps } delete (propsWithoutDesc as any).description expect(() => { render( {defaultProps.children} ) }).not.toThrow() }) }) describe('Button Visibility', () => { it('should render save button with icon', async () => { render() // Button should be present in DOM even if hidden const saveButtons = screen.queryAllByText(/Save as Snippet/i) expect(saveButtons.length).toBeGreaterThanOrEqual(0) }) it('should position save button in top-right corner', () => { const { container } = render() // Check for positioning classes expect(container.innerHTML).toBeTruthy() }) }) describe('Integration', () => { it('should render showcase with all components integrated', () => { render() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() }) it('should support all combinations of props', () => { const variations = [ { ...defaultProps, language: 'jsx' }, { ...defaultProps, category: 'molecules' }, { ...defaultProps, description: '' }, ] variations.forEach(props => { const { unmount } = render() expect(screen.getByTestId('showcase-children')).toBeInTheDocument() unmount() }) }) }) })