import { render, screen } from '@testing-library/react'; import { describe, it, expect } from 'vitest'; import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, } from './card'; describe('Card Component', () => { it('renders Card component correctly', () => { render(
Card content
, ); expect(screen.getByText('Card content')).toBeInTheDocument(); }); it('applies default variant styles', () => { const { container } = render(
Content
, ); const card = container.querySelector('.rounded-lg.border.bg-card'); expect(card).toBeInTheDocument(); expect(card?.classList.contains('shadow-card')).toBe(true); expect(card?.classList.contains('shadow-lg')).toBe(false); }); it('applies outlined variant styles', () => { const { container } = render(
Content
, ); const card = container.querySelector('.rounded-lg'); expect(card?.classList.contains('bg-transparent')).toBe(true); }); it('applies elevated variant styles', () => { const { container } = render(
Content
, ); const card = container.querySelector('.rounded-lg'); expect(card?.classList.contains('shadow-lg')).toBe(true); }); it('applies custom className', () => { const { container } = render(
Content
, ); const card = container.querySelector('.custom-class'); expect(card).toBeInTheDocument(); }); it('renders CardHeader correctly', () => { render(
Header content
, ); expect(screen.getByText('Header content')).toBeInTheDocument(); }); it('renders CardTitle correctly', () => { render( Card Title , ); const title = screen.getByText('Card Title'); expect(title).toBeInTheDocument(); expect(title.tagName).toBe('H3'); }); it('renders CardDescription correctly', () => { render( Card description , ); expect(screen.getByText('Card description')).toBeInTheDocument(); }); it('renders CardContent correctly', () => { render(
Content area
, ); expect(screen.getByText('Content area')).toBeInTheDocument(); }); it('renders CardFooter correctly', () => { render(
Footer content
, ); expect(screen.getByText('Footer content')).toBeInTheDocument(); }); it('renders complete Card structure', () => { render( Title Description
Content
Footer
, ); expect(screen.getByText('Title')).toBeInTheDocument(); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Content')).toBeInTheDocument(); expect(screen.getByText('Footer')).toBeInTheDocument(); }); it('supports dark mode through Tailwind classes', () => { const { container } = render(
Content
, ); const card = container.querySelector('.bg-card.text-card-foreground'); expect(card).toBeInTheDocument(); }); it('passes through HTML attributes', () => { render(
Content
, ); const card = screen.getByTestId('card'); expect(card).toBeInTheDocument(); expect(card.getAttribute('aria-label')).toBe('Test card'); }); });