/**
 * @ai-summary Tests for ErrorState component
 */

import { render, screen, fireEvent } from '@testing-library/react';
import { ErrorState } from '../../components/ErrorState';

describe('ErrorState', () => {
  it('should render error message', () => {
    const error = new Error('Failed to load data');
    const { container } = render(<ErrorState error={error} />);

    expect(container).toMatchSnapshot();
    expect(screen.getByText('Failed to load data')).toBeInTheDocument();
  });

  it('should render retry button when onRetry provided', () => {
    const handleRetry = jest.fn();
    const error = new Error('Network error');

    render(<ErrorState error={error} onRetry={handleRetry} />);

    const retryButton = screen.getByText('Retry');
    expect(retryButton).toBeInTheDocument();

    fireEvent.click(retryButton);
    expect(handleRetry).toHaveBeenCalledTimes(1);
  });

  it('should not render retry button when onRetry not provided', () => {
    const error = new Error('Error occurred');

    render(<ErrorState error={error} />);

    expect(screen.queryByText('Retry')).not.toBeInTheDocument();
  });

  it('should show default message when error has no message', () => {
    const error = new Error();

    render(<ErrorState error={error} />);

    expect(screen.getByText('Something went wrong. Please try again.')).toBeInTheDocument();
  });
});
