import { describe, test, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { ChatErrorMessage } from './chat-error-message'

describe('ChatErrorMessage', () => {
  test('renders error messages', () => {
    render(<ChatErrorMessage errors={['Something went wrong']} />)
    expect(screen.getByText('Something went wrong')).toBeTruthy()
  })

  test('renders multiple error messages', () => {
    render(<ChatErrorMessage errors={['Error 1', 'Error 2']} />)
    expect(screen.getByText('Error 1')).toBeTruthy()
    expect(screen.getByText('Error 2')).toBeTruthy()
  })

  test('renders action links', () => {
    const onRetry = vi.fn()
    render(
      <ChatErrorMessage
        errors={['Failed']}
        actions={[{ label: 'Retry', onClick: onRetry }]}
      />,
    )
    const retryLink = screen.getByText('Retry')
    expect(retryLink).toBeTruthy()
    fireEvent.click(retryLink)
    expect(onRetry).toHaveBeenCalledTimes(1)
  })

  test('renders custom icon', () => {
    render(
      <ChatErrorMessage
        errors={['Error']}
        icon={<span data-testid='custom-icon'>!</span>}
      />,
    )
    expect(screen.getByTestId('custom-icon')).toBeTruthy()
  })
})
