import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { Header } from './header';
import React from 'react';
import { LayoutProvider } from '../../../contexts/LayoutContext';
// Mock useLayout
vi.mock('../../../contexts/LayoutContext', async () => {
const actual = await vi.importActual('../../../contexts/LayoutContext');
return {
...actual,
useLayout: vi.fn(() => ({
sidebarExpanded: true,
toggleSidebar: vi.fn(),
})),
};
});
// Mock DropdownMenu to render content directly for testing
vi.mock('../../ui/dropdown-menu', () => ({
DropdownMenu: ({ children }: any) =>
{children}
,
DropdownMenuTrigger: ({ children }: any) => (
),
DropdownMenuContent: ({ children }: any) => {children}
,
DropdownMenuItem: ({ children }: any) => {children}
,
DropdownMenuLabel: ({ children }: any) => {children}
,
DropdownMenuSeparator: () =>
,
DropdownMenuGroup: ({ children }: any) => {children}
,
DropdownMenuSub: ({ children }: any) => {children}
,
DropdownMenuSubTrigger: ({ children }: any) => {children}
,
DropdownMenuSubContent: ({ children }: any) => {children}
,
DropdownMenuPortal: ({ children }: any) => <>{children}>,
}));
describe('Header', () => {
it('renders without a LayoutProvider', () => {
render();
expect(screen.getByText('Standalone')).toBeInTheDocument();
});
it('renders correctly with title', () => {
render(
);
expect(screen.getByText('Dashboard')).toBeInTheDocument();
});
it('renders breadcrumbs correctly', () => {
const breadcrumbs = [{ label: 'Home', href: '/' }, { label: 'Settings' }];
render(
);
expect(screen.getByText('Home')).toBeInTheDocument();
expect(screen.getByText('Settings')).toBeInTheDocument();
});
it('shows user info when user prop is provided', () => {
const user = { name: 'John Doe', email: 'john@example.com' };
render(
);
// With the mock, content should be directly visible or easily triggered
expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.getByText('john@example.com')).toBeInTheDocument();
});
});