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

describe('<ErrorState/>', () => {
  const wrap = (ui: React.ReactNode) => render(<ThemeProvider>{ui}</ThemeProvider>);

  it('renders the message and calls onRetry on click', () => {
    const onRetry = jest.fn();
    wrap(<ErrorState message="Couldn't load" retryLabel="Retry" onRetry={onRetry} />);
    expect(screen.getByText("Couldn't load")).toBeInTheDocument();
    fireEvent.click(screen.getByRole('button'));
    expect(onRetry).toHaveBeenCalledTimes(1);
  });

  it('renders the caller-supplied retry label', () => {
    wrap(<ErrorState message="Failed" retryLabel="Try again" onRetry={jest.fn()} />);
    expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument();
  });
});
