import { render, screen, fireEvent } from '@testing-library/react' import { SettingsLayout } from '../SettingsLayout' import { SettingsNav } from '../SettingsNav' import { SettingsCard } from '../SettingsCard' const TestIcon = () => // --------------------------------------------------------------------------- // SettingsLayout // --------------------------------------------------------------------------- describe('SettingsLayout', () => { it('renders children', () => { render(
Child content
) expect(screen.getByText('Child content')).toBeInTheDocument() }) it('renders title when provided', () => { render(
) expect(screen.getByText('Settings')).toBeInTheDocument() }) it('does not render title element when title is not provided', () => { render(
) expect(screen.queryByRole('heading')).not.toBeInTheDocument() }) it('renders description when both title and description are provided', () => { render(
) expect(screen.getByText('Manage your preferences')).toBeInTheDocument() }) it('does not render description when description is not provided', () => { render(
) expect(screen.queryByText(/manage/i)).not.toBeInTheDocument() }) }) // --------------------------------------------------------------------------- // SettingsNav // --------------------------------------------------------------------------- const navItems = [ { id: 'account', label: 'Account', href: '/settings/account' }, { id: 'billing', label: 'Billing', href: '/settings/billing', icon: TestIcon }, { id: 'integrations', label: 'Integrations', href: '/settings/integrations' }, ] describe('SettingsNav', () => { it('renders all nav items', () => { render( ) expect(screen.getByText('Account')).toBeInTheDocument() expect(screen.getByText('Billing')).toBeInTheDocument() expect(screen.getByText('Integrations')).toBeInTheDocument() }) it('renders icons for items that have icons', () => { render( ) expect(screen.getByTestId('settings-icon')).toBeInTheDocument() }) it('marks active item with active styles', () => { render( ) const accountBtn = screen.getByRole('button', { name: 'Account' }) expect(accountBtn).toHaveClass('bg-gray-100', 'text-gray-900') }) it('inactive items do not have active styles', () => { render( ) const billingBtn = screen.getByRole('button', { name: 'Billing' }) expect(billingBtn).not.toHaveClass('bg-gray-100') expect(billingBtn).toHaveClass('text-gray-600') }) it('calls onNavigate with the correct href on click', () => { const onNavigate = jest.fn() render( ) fireEvent.click(screen.getByRole('button', { name: 'Billing' })) expect(onNavigate).toHaveBeenCalledWith('/settings/billing') }) it('renders all items as buttons', () => { render( ) expect(screen.getAllByRole('button')).toHaveLength(navItems.length) }) it('renders inside a nav element', () => { render( ) expect(screen.getByRole('navigation')).toBeInTheDocument() }) }) // --------------------------------------------------------------------------- // SettingsCard // --------------------------------------------------------------------------- describe('SettingsCard', () => { it('renders the title', () => { render() expect(screen.getByText('API Keys')).toBeInTheDocument() }) it('renders description when provided', () => { render() expect(screen.getByText('Manage your API tokens.')).toBeInTheDocument() }) it('does not render description when not provided', () => { render() expect(screen.queryByText(/manage/i)).not.toBeInTheDocument() }) it('renders icon when provided', () => { render() expect(screen.getByTestId('settings-icon')).toBeInTheDocument() }) it('does not render icon when not provided', () => { render() expect(screen.queryByTestId('settings-icon')).not.toBeInTheDocument() }) it('renders action node when provided', () => { render( Add Key} /> ) expect(screen.getByRole('button', { name: 'Add Key' })).toBeInTheDocument() }) it('renders children content', () => { render(

Card body content

) expect(screen.getByText('Card body content')).toBeInTheDocument() }) it('does not render children section when children is not provided', () => { const { container } = render() // The children container (px-6 pb-6 pt-0) should not be present expect(container.querySelector('.px-6.pb-6.pt-0')).not.toBeInTheDocument() }) })