import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render } from '@testing-library/react';
import { Field } from '.';
import { TextInput } from '../TextInput';
describe('Field', function () {
  var wrapper;
  describe('with `hintText` and `errors` props', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(Field, {
        hintText: "Example hint text.",
        errors: [{
          error: 'Required'
        }]
      }, /*#__PURE__*/React.createElement(TextInput, {
        label: "Example text input",
        name: "example"
      })));
    });
    it('renders the hint text', function () {
      expect(wrapper.queryByText('Example hint text.')).toBeInTheDocument();
    });
    it('renders the error message', function () {
      var errorMessages = wrapper.getAllByTestId('field-error-message');
      expect(errorMessages).toHaveLength(1);
      expect(errorMessages[0]).toHaveTextContent('Required');
    });
    it('adds the aria aria-invalid attribute', function () {
      expect(wrapper.getByTestId('example-component')).toHaveAttribute('aria-invalid', 'true');
    });
    it('adds the `aria-describedby` attribute', function () {
      expect(wrapper.getByTestId('example-component')).toHaveAttribute('aria-describedby', expect.stringMatching(/(?<=field-)(.*)(?!-errormessage)/));
    });
    it('sets the `aria-errormessage` attribute', function () {
      expect(wrapper.getByTestId('example-component')).toHaveAttribute('aria-errormessage', expect.stringMatching(/(?<=field-)(.*)(?=-errormessage)/));
    });
  });
});