import { render, screen } from '@testing-library/react'; import { describe, it, expect } from 'vitest'; import { Alert, AlertTitle, AlertDescription } from './alert'; import React from 'react'; describe('Alert', () => { it('renders correctly with default props', () => { render( Heads up! You can add components to your app using the cli. ); expect(screen.getByRole('alert')).toBeInTheDocument(); expect(screen.getByText('Heads up!')).toBeInTheDocument(); expect( screen.getByText('You can add components to your app using the cli.') ).toBeInTheDocument(); }); it('renders correctly with different variants', () => { const { rerender } = render(Success); expect(screen.getByRole('alert')).toHaveClass('border-l-[color:var(--success)]'); rerender(Destructive); expect(screen.getByRole('alert')).toHaveClass('border-l-[color:var(--destructive)]'); }); it('renders a custom icon', () => { render(Icon}>Message); expect(screen.getByTestId('custom-icon')).toBeInTheDocument(); }); it('hides icon when icon prop is null', () => { const { container } = render(No icon); // The default icon shouldn't be there expect(container.querySelector('svg')).not.toBeInTheDocument(); }); it('has correct data-slot attributes', () => { const { container } = render( Title Description ); expect(container.querySelector('[data-slot="alert"]')).toBeInTheDocument(); expect(container.querySelector('[data-slot="alert-title"]')).toBeInTheDocument(); expect(container.querySelector('[data-slot="alert-description"]')).toBeInTheDocument(); }); });