import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { LoadingState } from '@/components/LoadingState';
import { ErrorState } from '@/components/ErrorState';
import { EmptyState } from '@/components/EmptyState';
describe('LoadingState', () => {
it('shows the default label', () => {
render();
expect(screen.getByTestId('loading-state')).toHaveTextContent('Loading');
});
it('shows a custom label', () => {
render();
expect(screen.getByTestId('loading-state')).toHaveTextContent('Fetching things…');
});
});
describe('ErrorState', () => {
it('renders message and triggers retry', async () => {
const onRetry = vi.fn();
render();
expect(screen.getByTestId('error-state')).toHaveTextContent('Boom');
await userEvent.click(screen.getByRole('button', { name: /retry/i }));
expect(onRetry).toHaveBeenCalledTimes(1);
});
it('omits retry button when no handler given', () => {
render();
expect(screen.queryByRole('button', { name: /retry/i })).toBeNull();
});
});
describe('EmptyState', () => {
it('renders title, description and action', () => {
render(Create} />);
const node = screen.getByTestId('empty-state');
expect(node).toHaveTextContent('Nothing here');
expect(node).toHaveTextContent('Add one');
expect(screen.getByRole('button', { name: /create/i })).toBeInTheDocument();
});
});