/** * AdminHeaderPanel Component Tests * * Tests for the AdminHeaderPanel component that provides a semantic header * for admin pages with title, description, actions, and loading state. */ import React from 'react'; import { render, screen } from '@testing-library/react'; import { AdminHeaderPanel } from './AdminHeaderPanel'; import { describe, it, expect, vi } from 'vitest'; // Mock the ProgressLine component vi.mock('@/components/shared/ProgressLine', () => ({ ProgressLine: ({ isLoading }: { isLoading: boolean }) => (
{isLoading ? 'Loading...' : 'Ready'}
), })); // Mock the SectionHeader component vi.mock('@/ui/SectionHeader', () => ({ SectionHeader: ({ title, description, actions, loading }: any) => (

{title}

{description &&

{description}

} {actions &&
{actions}
} {loading}
), })); describe('AdminHeaderPanel', () => { it('should render with title only', () => { render( ); expect(screen.getByText('Admin Dashboard')).toBeTruthy(); }); it('should render with title and description', () => { render( ); expect(screen.getByText('User Management')).toBeTruthy(); expect(screen.getByText('Manage all user accounts and permissions')).toBeTruthy(); }); it('should render with title, description, and actions', () => { const actions = ; render( ); expect(screen.getByText('User Management')).toBeTruthy(); expect(screen.getByText('Manage all user accounts')).toBeTruthy(); expect(screen.getByTestId('action-btn')).toBeTruthy(); expect(screen.getByText('Create User')).toBeTruthy(); }); it('should render with loading state', () => { render( ); expect(screen.getByText('Loading Data')).toBeTruthy(); expect(screen.getByTestId('progress-line')).toBeTruthy(); }); it('should render without loading state by default', () => { render( ); expect(screen.getByText('Ready State')).toBeTruthy(); expect(screen.getByTestId('progress-line')).toBeTruthy(); }); it('should render with multiple action buttons', () => { const actions = (
); render( ); expect(screen.getByText('Edit User')).toBeTruthy(); expect(screen.getByText('Make changes to user profile')).toBeTruthy(); expect(screen.getByText('Save')).toBeTruthy(); expect(screen.getByText('Cancel')).toBeTruthy(); expect(screen.getByText('Delete')).toBeTruthy(); }); it('should render with complex actions component', () => { const ComplexActions = () => (
); render( } /> ); expect(screen.getByText('Complex Header')).toBeTruthy(); expect(screen.getByText('With multiple actions')).toBeTruthy(); expect(screen.getByText('Primary Action')).toBeTruthy(); expect(screen.getByText('Secondary Action')).toBeTruthy(); expect(screen.getByText('Tertiary Action')).toBeTruthy(); }); it('should render with long title and description', () => { render( ); expect(screen.getByText(/This is a very long header title/)).toBeTruthy(); expect(screen.getByText(/This is an even longer description/)).toBeTruthy(); }); it('should render with special characters in text', () => { render( ); expect(screen.getByText(/Special & Characters/)).toBeTruthy(); expect(screen.getByText(/Quotes/)).toBeTruthy(); }); });