veza/apps/web/src/components/ui/badge.test.tsx
senke 7c69474cf9 aesthetic-improvements: align spacing to 8px grid (Action 11.2.1.3)
- Created automated script (scripts/align-8px-grid.py) to align all spacing to 8px grid
- Replaced non-8px-aligned spacing: gap-3/p-3/m-3 (12px) → gap-4/p-4/m-4 (16px), gap-5/p-5/m-5 (20px) → gap-6/p-6/m-6 (24px), gap-10/p-10/m-10 (40px) → gap-12/p-12/m-12 (48px), gap-20/p-20/m-20 (80px) → gap-24/p-24/m-24 (96px)
- Preserved: 4px values (gap-1, p-1, m-1) as they may be intentional fine-tuning, responsive breakpoints (sm:, md:, lg:), test files, documentation
- Modified files across all components to ensure consistent 8px grid alignment
- Action 11.2.1.3: Align all elements to 8px grid - COMPLETE
2026-01-16 11:50:46 +01:00

187 lines
5.4 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { Badge } from './badge';
describe('Badge Component', () => {
describe('Rendering', () => {
it('renders badge with children', () => {
render(<Badge>Badge text</Badge>);
expect(screen.getByText('Badge text')).toBeInTheDocument();
});
it('renders badge with ReactNode children', () => {
render(
<Badge>
<span>Custom content</span>
</Badge>,
);
expect(screen.getByText('Custom content')).toBeInTheDocument();
});
});
describe('Variants', () => {
it('renders default variant', () => {
const { container } = render(<Badge>Default</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-muted');
});
it('renders primary variant', () => {
const { container } = render(<Badge variant="primary">Primary</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-blue-100');
});
it('renders success variant', () => {
const { container } = render(<Badge variant="success">Success</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-green-100');
});
it('renders warning variant', () => {
const { container } = render(<Badge variant="warning">Warning</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-yellow-100');
});
it('renders error variant', () => {
const { container } = render(<Badge variant="error">Error</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-red-100');
});
});
describe('Sizes', () => {
it('renders small size', () => {
const { container } = render(<Badge size="sm">Small</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('px-2', 'py-0.5', 'text-xs');
});
it('renders medium size by default', () => {
const { container } = render(<Badge>Medium</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('px-2.5', 'py-0.5', 'text-sm');
});
it('renders large size', () => {
const { container } = render(<Badge size="lg">Large</Badge>);
const badge = container.firstChild;
expect(badge).toHaveClass('px-4', 'py-1', 'text-base');
});
});
describe('Dot', () => {
it('does not show dot by default', () => {
const { container } = render(<Badge>No dot</Badge>);
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).not.toBeInTheDocument();
});
it('shows dot when dot prop is true', () => {
const { container } = render(<Badge dot>With dot</Badge>);
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).toBeInTheDocument();
});
it('renders dot with correct size for small badge', () => {
const { container } = render(
<Badge dot size="sm">
Small with dot
</Badge>,
);
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).toHaveClass('w-1.5', 'h-1.5');
});
it('renders dot with correct size for large badge', () => {
const { container } = render(
<Badge dot size="lg">
Large with dot
</Badge>,
);
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).toHaveClass('w-2.5', 'h-2.5');
});
});
describe('Count', () => {
it('does not show count when count is undefined', () => {
render(<Badge>No count</Badge>);
expect(screen.queryByText(/\(\d+\)/)).not.toBeInTheDocument();
});
it('shows count when count is provided', () => {
render(<Badge count={5}>With count</Badge>);
expect(screen.getByText('(5)')).toBeInTheDocument();
});
it('shows count of 0', () => {
render(<Badge count={0}>Zero count</Badge>);
expect(screen.getByText('(0)')).toBeInTheDocument();
});
it('shows large count', () => {
render(<Badge count={999}>Large count</Badge>);
expect(screen.getByText('(999)')).toBeInTheDocument();
});
it('shows count with dot', () => {
const { container } = render(
<Badge dot count={3}>
With dot and count
</Badge>,
);
expect(screen.getByText('(3)')).toBeInTheDocument();
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).toBeInTheDocument();
});
});
describe('Combinations', () => {
it('renders badge with variant, size, dot, and count', () => {
const { container } = render(
<Badge variant="success" size="lg" dot count={10}>
Complete badge
</Badge>,
);
const badge = container.firstChild;
expect(badge).toHaveClass('bg-green-100', 'px-4', 'py-1', 'text-base');
expect(screen.getByText('Complete badge')).toBeInTheDocument();
expect(screen.getByText('(10)')).toBeInTheDocument();
const dot = container.querySelector('.rounded-full.bg-current');
expect(dot).toBeInTheDocument();
});
});
describe('Custom className', () => {
it('applies custom className', () => {
const { container } = render(
<Badge className="custom-badge">Custom</Badge>,
);
const badge = container.firstChild;
expect(badge).toHaveClass('custom-badge');
});
});
});