import { cleanup, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it } from 'vitest';
import * as React from 'react';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from './alert-dialog';
import { Alert, AlertDescription, AlertTitle } from './alert';
import { Avatar, AvatarFallback, AvatarImage } from './avatar';
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from './breadcrumb';
import { Button } from './button';
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from './card';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from './dialog';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from './dropdown-menu';
import { Input } from './input';
import { Label } from './label';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from './select';
import { Separator } from './separator';
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from './sheet';
import { Skeleton } from './skeleton';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from './table';
import { Textarea } from './textarea';
describe('UI Components', () => {
beforeEach(() => {
cleanup();
});
describe('AlertDialog', () => {
it('renders alert dialog trigger', () => {
render(
Click me
Are you sure?
This action cannot be undone.
Cancel
Continue
,
);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
});
describe('Alert', () => {
it('renders alert with title and description', () => {
render(
Heads up!
You can add components to your app using the cli.
,
);
expect(screen.getByText('Heads up!')).toBeInTheDocument();
expect(
screen.getByText('You can add components to your app using the cli.'),
).toBeInTheDocument();
});
});
describe('Avatar', () => {
it('renders avatar with image and fallback', () => {
render(
CN
,
);
expect(screen.getByText('CN')).toBeInTheDocument();
});
});
describe('Breadcrumb', () => {
it('renders breadcrumb list', () => {
render(
Home
Components
,
);
expect(screen.getByText('Home')).toBeInTheDocument();
expect(screen.getByText('Components')).toBeInTheDocument();
});
});
describe('Button', () => {
it('renders button with text', () => {
render();
expect(
screen.getByRole('button', { name: /click me/i }),
).toBeInTheDocument();
});
it('applies variant and size classes', () => {
const { rerender } = render(
,
);
expect(screen.getByRole('button')).toHaveClass('bg-destructive');
rerender(
,
);
expect(screen.getByRole('button')).toHaveClass('border');
expect(screen.getByRole('button')).toHaveClass('border-border');
});
});
describe('Card', () => {
it('renders card with all sections', () => {
render(
Card Title
Card Description
Card Content
Card Footer
,
);
expect(screen.getByText('Card Title')).toBeInTheDocument();
expect(screen.getByText('Card Description')).toBeInTheDocument();
expect(screen.getByText('Card Content')).toBeInTheDocument();
expect(screen.getByText('Card Footer')).toBeInTheDocument();
});
});
describe('Dialog', () => {
it('renders dialog trigger', () => {
render(
,
);
expect(screen.getByText('Open Dialog')).toBeInTheDocument();
});
});
describe('DropdownMenu', () => {
it('renders dropdown menu trigger', () => {
render(
Open Menu
My Account
Profile
,
);
expect(screen.getByText('Open Menu')).toBeInTheDocument();
});
});
describe('Input', () => {
it('renders input with placeholder', () => {
render();
expect(screen.getByPlaceholderText('Email')).toBeInTheDocument();
});
it('is disabled when the disabled prop is passed', () => {
render();
expect(screen.getByPlaceholderText('Disabled Input')).toBeDisabled();
});
});
describe('Label', () => {
it('renders label text', () => {
render();
expect(screen.getByText('Email address')).toBeInTheDocument();
});
});
describe('Select', () => {
it('renders select trigger', () => {
render(
,
);
expect(screen.getByText('Select a fruit')).toBeInTheDocument();
});
});
describe('Separator', () => {
it('renders separator', () => {
const { container } = render();
expect(container.firstChild).toHaveClass('shrink-0 bg-border');
});
});
describe('Sheet', () => {
it('renders sheet trigger', () => {
render(
Open Sheet
Sheet Title
Sheet Description
,
);
expect(screen.getByText('Open Sheet')).toBeInTheDocument();
});
});
describe('Skeleton', () => {
it('renders skeleton with classes', () => {
const { container } = render();
expect(container.firstChild).toHaveClass('animate-pulse');
expect(container.firstChild).toHaveClass('rounded-md');
expect(container.firstChild).toHaveClass('bg-muted');
});
});
describe('Table', () => {
it('renders table with content', () => {
render(
,
);
expect(screen.getByText('Invoice')).toBeInTheDocument();
expect(screen.getByText('INV001')).toBeInTheDocument();
});
});
describe('Textarea', () => {
it('renders textarea with placeholder', () => {
render();
expect(
screen.getByPlaceholderText('Type your message here.'),
).toBeInTheDocument();
});
});
});