import { render, screen } from '@testing-library/react' import { describe, test, expect, vi } from 'vitest' import { MainLayout } from '@/components/layouts/MainLayout' import { BrowserRouter } from 'react-router-dom' // Mock the child components vi.mock('@/components/layouts/SideNavigation', () => ({ SideNavigation: () => })) vi.mock('@/components/DisconnectScreenOverlay', () => ({ DisconnectScreenOverlay: () => null // Usually hidden })) // Mock contexts vi.mock('@/contexts/SettingsContext', () => ({ useSettings: () => ({ settings: { enableProjects: true, theme: 'dark' }, updateSettings: vi.fn() }) })) describe('MainLayout Component', () => { const renderWithRouter = (children: React.ReactNode) => { return render( {children} ) } test('renders children correctly', () => { renderWithRouter(
Page content
) expect(screen.getByText('Page content')).toBeInTheDocument() }) test('renders side navigation', () => { renderWithRouter(
Content
) expect(screen.getByTestId('side-navigation')).toBeInTheDocument() }) test('applies layout structure classes', () => { const { container } = renderWithRouter(
Content
) // Check for flex layout const layoutContainer = container.querySelector('.flex') expect(layoutContainer).toBeInTheDocument() // Check for main content area const mainContent = container.querySelector('main') expect(mainContent).toBeInTheDocument() expect(mainContent?.className).toContain('flex-1') }) test('renders multiple children', () => { renderWithRouter(
First child
Second child
Third child
) expect(screen.getByText('First child')).toBeInTheDocument() expect(screen.getByText('Second child')).toBeInTheDocument() expect(screen.getByText('Third child')).toBeInTheDocument() }) test('maintains responsive layout', () => { const { container } = renderWithRouter(
Responsive content
) const mainContent = container.querySelector('main') expect(mainContent?.className).toContain('overflow-x-hidden') expect(mainContent?.className).toContain('overflow-y-auto') }) test('applies dark mode background classes', () => { const { container } = renderWithRouter(
Dark mode content
) const layoutContainer = container.firstChild as HTMLElement expect(layoutContainer.className).toContain('bg-gray-50') expect(layoutContainer.className).toContain('dark:bg-black') }) test('renders empty children gracefully', () => { const { container } = renderWithRouter( {null} {undefined} {false} ) // Should still render the layout structure expect(container.querySelector('.flex')).toBeInTheDocument() expect(screen.getByTestId('side-navigation')).toBeInTheDocument() }) test('handles complex nested components', () => { renderWithRouter(

Page Title

Article content

) expect(screen.getByText('Page Title')).toBeInTheDocument() expect(screen.getByText('Article content')).toBeInTheDocument() expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument() }) test('preserves child component props', () => { renderWithRouter(
Custom content
) const customDiv = screen.getByTestId('custom-content') expect(customDiv).toHaveAttribute('id', 'test-id') expect(customDiv).toHaveClass('custom-class') expect(customDiv).toHaveTextContent('Custom content') }) })