/**
* UnifiedTypography Component Tests
*
* Tests for typography components in components/admin/UnifiedTypography
*/
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { UnifiedTitle, UnifiedText, UnifiedPageHeader } from '@/components/admin/UnifiedTypography';
import { MantineProvider, createTheme } from '@mantine/core';
// Create a wrapper component with Mantine Provider
function renderWithMantine(ui: React.ReactElement) {
const theme = createTheme();
return render(ui, {
wrapper: ({ children }) => (
{children}
),
});
}
describe('UnifiedTitle', () => {
it('should render title with correct children', () => {
renderWithMantine(
Test Title
);
expect(screen.getByText('Test Title')).toBeInTheDocument();
});
it('should render with default order 1', () => {
renderWithMantine(
Heading 1
);
const heading = screen.getByRole('heading', { level: 1 });
expect(heading).toBeInTheDocument();
expect(heading).toHaveTextContent('Heading 1');
});
it('should render with custom order', () => {
const { rerender } = renderWithMantine(
Heading 2
);
expect(screen.getByRole('heading', { level: 2 })).toBeInTheDocument();
rerender(
Heading 3
);
expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument();
});
it('should render with custom alignment', () => {
renderWithMantine(
Centered Title
);
const title = screen.getByText('Centered Title');
expect(title).toHaveStyle('text-align: center');
});
it('should render with primary color by default', () => {
renderWithMantine(
Default Color
);
expect(screen.getByText('Default Color')).toBeInTheDocument();
});
it('should render with secondary color', () => {
renderWithMantine(
Secondary Color
);
expect(screen.getByText('Secondary Color')).toBeInTheDocument();
});
it('should render with brand color', () => {
renderWithMantine(
Brand Color
);
expect(screen.getByText('Brand Color')).toBeInTheDocument();
});
it('should accept custom margin props', () => {
renderWithMantine(
With Margins
);
const title = screen.getByText('With Margins');
expect(title).toBeInTheDocument();
});
it('should accept custom style prop', () => {
renderWithMantine(
Custom Style
);
const title = screen.getByText('Custom Style');
expect(title).toBeInTheDocument();
});
it('should render with order 4', () => {
renderWithMantine(
Heading 4
);
expect(screen.getByRole('heading', { level: 4 })).toBeInTheDocument();
});
it('should render with order 5', () => {
renderWithMantine(
Heading 5
);
expect(screen.getByRole('heading', { level: 5 })).toBeInTheDocument();
});
it('should render with order 6', () => {
renderWithMantine(
Heading 6
);
expect(screen.getByRole('heading', { level: 6 })).toBeInTheDocument();
});
});
describe('UnifiedText', () => {
it('should render text with correct children', () => {
renderWithMantine(
Test Text
);
expect(screen.getByText('Test Text')).toBeInTheDocument();
});
it('should render with body size by default', () => {
renderWithMantine(
Body Text
);
expect(screen.getByText('Body Text')).toBeInTheDocument();
});
it('should render with small size', () => {
renderWithMantine(
Small Text
);
expect(screen.getByText('Small Text')).toBeInTheDocument();
});
it('should render with label size', () => {
renderWithMantine(
Label Text
);
expect(screen.getByText('Label Text')).toBeInTheDocument();
});
it('should render with normal weight by default', () => {
renderWithMantine(
Normal Weight
);
expect(screen.getByText('Normal Weight')).toBeInTheDocument();
});
it('should render with medium weight', () => {
renderWithMantine(
Medium Weight
);
expect(screen.getByText('Medium Weight')).toBeInTheDocument();
});
it('should render with bold weight', () => {
renderWithMantine(
Bold Text
);
expect(screen.getByText('Bold Text')).toBeInTheDocument();
});
it('should render with custom alignment', () => {
renderWithMantine(
Right Aligned
);
const text = screen.getByText('Right Aligned');
expect(text).toHaveStyle('text-align: right');
});
it('should render with primary color by default', () => {
renderWithMantine(
Primary Color
);
expect(screen.getByText('Primary Color')).toBeInTheDocument();
});
it('should render with secondary color', () => {
renderWithMantine(
Secondary Text
);
expect(screen.getByText('Secondary Text')).toBeInTheDocument();
});
it('should render with tertiary color', () => {
renderWithMantine(
Tertiary Text
);
expect(screen.getByText('Tertiary Text')).toBeInTheDocument();
});
it('should render with muted color', () => {
renderWithMantine(
Muted Text
);
expect(screen.getByText('Muted Text')).toBeInTheDocument();
});
it('should render with brand color', () => {
renderWithMantine(
Brand Text
);
expect(screen.getByText('Brand Text')).toBeInTheDocument();
});
it('should render with link color', () => {
renderWithMantine(
Link Text
);
expect(screen.getByText('Link Text')).toBeInTheDocument();
});
it('should render as span when span prop is true', () => {
renderWithMantine(
Span Text
);
expect(screen.getByText('Span Text')).toBeInTheDocument();
});
it('should accept custom margin props', () => {
renderWithMantine(
With Margins
);
expect(screen.getByText('With Margins')).toBeInTheDocument();
});
it('should accept custom style prop', () => {
renderWithMantine(
Custom Style
);
expect(screen.getByText('Custom Style')).toBeInTheDocument();
});
});
describe('UnifiedPageHeader', () => {
it('should render with title', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
it('should render with optional subtitle', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
expect(screen.getByText('Page Subtitle')).toBeInTheDocument();
});
it('should render without subtitle when not provided', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
it('should render with action', () => {
renderWithMantine(
Action Button}
/>
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
expect(screen.getByText('Action Button')).toBeInTheDocument();
});
it('should show border by default', () => {
renderWithMantine(
);
// The border is applied via style, checking if component renders
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
it('should hide border when showBorder is false', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
it('should render with custom style', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
it('should render title as order 3 heading', () => {
renderWithMantine(
);
// The title should be rendered with UnifiedTitle order={3}
expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument();
});
it('should render subtitle with small size and secondary color', () => {
renderWithMantine(
);
expect(screen.getByText('Page Subtitle')).toBeInTheDocument();
});
it('should accept additional Mantine Box props', () => {
renderWithMantine(
);
expect(screen.getByText('Page Title')).toBeInTheDocument();
});
});