import { describe, expect, it } from 'vitest';
import { render } from 'ink-testing-library';
import React from 'react';
import { ErrorDisplay } from '../../components/shared/ErrorDisplay.js';

describe('ErrorDisplay', () => {
  it('renders the error message', () => {
    const { lastFrame } = render(React.createElement(ErrorDisplay, { message: 'Test-Fehler' }));
    expect(lastFrame()).toContain('Test-Fehler');
  });

  it('renders without onDismiss without throwing', () => {
    expect(() => render(React.createElement(ErrorDisplay, { message: 'Fehler' }))).not.toThrow();
  });

  it('does not render dismiss hint when onDismiss is absent', () => {
    const { lastFrame } = render(React.createElement(ErrorDisplay, { message: 'Fehler' }));
    expect(lastFrame()).not.toContain('Schließen');
  });

  it('renders dismiss hint when onDismiss is provided', () => {
    const { lastFrame } = render(
      React.createElement(ErrorDisplay, { message: 'Fehler', onDismiss: () => undefined }),
    );
    expect(lastFrame()).toContain('Schließen');
  });
});
