import { render, screen } from '@testing-library/react' import { describe, expect, it } from 'vitest' import Field from './field' describe('Field', () => { describe('Rendering', () => { it('should render without crashing', () => { render(Content) expect(screen.getByText('Test Label')).toBeInTheDocument() expect(screen.getByText('Content')).toBeInTheDocument() }) it('should render label with correct styling', () => { render(Content) const labelElement = screen.getByText('My Label') expect(labelElement).toHaveClass('system-xs-medium', 'w-[128px]', 'shrink-0', 'truncate', 'py-1', 'text-text-tertiary') }) it('should render children in correct container', () => { const { container } = render(Child Content) // The children are wrapped in a div with w-[244px] class const contentWrapper = container.querySelector('.w-\\[244px\\]') expect(contentWrapper).toBeInTheDocument() expect(contentWrapper).toHaveClass('shrink-0') }) }) describe('Props', () => { it('should render with string children', () => { render(Simple Text) expect(screen.getByText('Simple Text')).toBeInTheDocument() }) it('should render with complex children', () => { render(
Nested Content
, ) expect(screen.getByTestId('complex-child')).toBeInTheDocument() expect(screen.getByText('Nested Content')).toBeInTheDocument() }) it('should render with multiple children', () => { render( First Second , ) expect(screen.getByText('First')).toBeInTheDocument() expect(screen.getByText('Second')).toBeInTheDocument() }) it('should render different labels correctly', () => { const { rerender } = render(Content) expect(screen.getByText('First Label')).toBeInTheDocument() rerender(Content) expect(screen.getByText('Second Label')).toBeInTheDocument() }) }) describe('Layout', () => { it('should have flex layout with space between elements', () => { const { container } = render(Content) const wrapper = container.firstChild expect(wrapper).toHaveClass('flex', 'items-start', 'space-x-2') }) it('should render label and content side by side', () => { const { container } = render(Content) const wrapper = container.firstChild as HTMLElement expect(wrapper?.children).toHaveLength(2) }) }) describe('Edge Cases', () => { it('should render with empty label', () => { render(Content) expect(screen.getByText('Content')).toBeInTheDocument() }) it('should render with long label (truncation)', () => { const longLabel = 'This is a very long label that should be truncated' render(Content) const labelElement = screen.getByText(longLabel) expect(labelElement).toHaveClass('truncate') }) it('should render with empty children', () => { const { container } = render() expect(container.firstChild).toBeInTheDocument() }) it('should render with null children', () => { const { container } = render({null}) expect(container.firstChild).toBeInTheDocument() }) it('should render with number as children', () => { render({42}) expect(screen.getByText('42')).toBeInTheDocument() }) it('should handle special characters in label', () => { render(Content) expect(screen.getByText('Label & "chars"')).toBeInTheDocument() }) }) })