import React from 'react'
import {render, screen} from '@testing-library/react'
import {TextInput} from '../TextInput'

describe('TextInput', () => {
  it('should include an error icon when there is an error message', () => {
    render(
      <TextInput
        renderLabel="Test Input"
        messages={[{type: 'error', text: 'Test error message'}]}
      />,
    )

    // This component enhances error messages to include an icon, so we check if an SVG exists
    expect(
      screen
        .getAllByRole('presentation', {hidden: true})
        .find(el => el.tagName === 'svg' && el.getAttribute('name') === 'IconWarning'),
    ).toBeDefined()
    expect(screen.getByText(/test error message/i)).toBeInTheDocument()
  })
})
