import { _ as _asyncToGenerator, r as regenerator } from '../../index-81a9bdac.js';
import { _ as _extends } from '../../extends-e61fd370.js';
import React__default from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import TextField from '../../text-field/index.js';
import { B as Button } from '../../index-4e01772f.js';
import useForm, { Form } from '../index.js';
import { n as node, r as rest } from '../../index-52fa8259.js';
import '../../typeof-6c6d8d7a.js';
import '../../label/index.js';
import '../../objectWithoutProperties-72d23964.js';
import 'prop-types';
import '@reach/visually-hidden';
import 'classnames';
import '../../input/index.js';
import '../../defineProperty-18999f8e.js';
import '../../stack/index.js';
import '../../inline-validation/index.js';
import '../../slicedToArray-5b664d46.js';
import '../../toConsumableArray-f2f53597.js';
import 'react-dom';
import '../../icon/assets/icon-map/index.js';
import '../../social-icon/index.js';
import '@fortawesome/react-fontawesome';
import '../../social-icon/icons.js';
import '../../social-icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/free-solid-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../../tooltip/index.js';
import '../../auto-id.esm-2b54f757.js';
import '../../utils.esm-514fad91.js';
import '../../warning-ed2bf294.js';
import '../../portal.esm-613949dc.js';
import '../../portal/index.js';
import '../../use-rerender-once/index.js';
import '../../use-force-update/index.js';
import '../../button/button-group.js';
import '../../_commonjsHelpers-57e89916.js';
import '../../use-progress/index.js';
import '../../use-trailing-debounce/index.js';
import '../../createClass-f72139d4.js';
import '../../setPrototypeOf-38804714.js';
import 'http';
import 'https';
import 'util';
import 'tty';
import 'os';
import 'timers';
import 'stream';
import 'url';
import 'zlib';

var server = node.setupServer();
beforeAll(function () {
  return server.listen();
}); // reset any request handlers that are declared as a part of our tests
// (i.e. for testing one-time error scenarios)

afterEach(function () {
  return server.resetHandlers();
}); // clean up once the tests are done

afterAll(function () {
  return server.close();
});

var ExampleForm = function ExampleForm(props) {
  var form = useForm({
    initialData: {
      name: "",
      email: ""
    }
  });
  return /*#__PURE__*/React__default.createElement(Form, _extends({
    form: form
  }, props), /*#__PURE__*/React__default.createElement(TextField, {
    label: "Name",
    name: "name"
  }), /*#__PURE__*/React__default.createElement(TextField, {
    label: "Email",
    name: "email"
  }), /*#__PURE__*/React__default.createElement(Button, null, "Submit"));
};

jest.useFakeTimers();
describe("Form validations", function () {
  test("should validate async", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
    var error;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            server.use(rest.post("/validations", function (req, res, ctx) {
              return res(ctx.json([{
                field: "name",
                message: "name is invalid"
              }]));
            }));
            render( /*#__PURE__*/React__default.createElement(ExampleForm, {
              validation: "demo_validation"
            }));
            userEvent.type(screen.getByLabelText("Name"), "Brendan");
            userEvent.type(screen.getByLabelText("Email"), "brendan@convertkit.com");
            jest.advanceTimersByTime(8000);
            _context.next = 7;
            return screen.findByText("name is invalid");

          case 7:
            error = _context.sent;
            expect(error).toBeInTheDocument();

          case 9:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
});
