"use strict";

require("core-js/modules/es.promise.js");

var _react = require("@testing-library/react");

var _react2 = _interopRequireDefault(require("react"));

var _SignupForm = _interopRequireDefault(require("./SignupForm"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const mockedUsedNavigate = jest.fn();
jest.mock('react-router-dom', () => _objectSpread(_objectSpread({}, jest.requireActual('react-router-dom')), {}, {
  useNavigate: () => mockedUsedNavigate
}));
it('Should render the title, form, and submit button', () => {
  const {
    getByRole,
    getByTestId,
    getByLabelText,
    getByText
  } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SignupForm.default, null));
  const title = getByRole('heading', {
    name: 'Great to have you here'
  });
  const firstNameLabel = getByText(/First Name/i);
  const lastNameLabel = getByText(/Last Name/i);
  const emailNameLabel = getByText(/Email/i);
  const passwordNameLabel = getByText(/Password/i);

  const signUpBtn = _react.screen.getByTestId('sign-up-btn');

  expect(title).toBeInTheDocument();
  expect(firstNameLabel).toBeInTheDocument();
  expect(lastNameLabel).toBeInTheDocument();
  expect(emailNameLabel).toBeInTheDocument();
  expect(passwordNameLabel).toBeInTheDocument();
  expect(signUpBtn).toBeInTheDocument();
});
it('Should render the footer content', () => {
  (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SignupForm.default, null));
  expect(_react.screen.getByTestId('footer')).toBeInTheDocument();
});
/**
 * Temporary skipping this test case which is causing "Call retries were exceeded"
 */

test.skip("Should show client side validations", async () => {
  const {
    getByPlaceholderText,
    getByText
  } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SignupForm.default, null));
  const firstNameInput = getByPlaceholderText(/input first name/i);
  const emailInput = getByPlaceholderText(/example@gmail.com/i);
  const passwordInput = getByPlaceholderText(/Password/i);

  _react.fireEvent.change(emailInput, {
    target: {
      value: "realmadmin"
    }
  });

  _react.fireEvent.change(passwordInput, {
    target: {
      value: "real"
    }
  });

  _react.fireEvent.click(getByText(/Sign Up/i));

  await (0, _react.waitFor)(() => {
    expect(getByText("First name required")).toBeInTheDocument();
    expect(getByText("Invalid email address format")).toBeInTheDocument();
    expect(getByText("Password should be atleast 6 characters long and should contain a special symbol!")).toBeInTheDocument();
  });

  _react.fireEvent.change(firstNameInput, {
    target: {
      value: "hdhd"
    }
  });

  _react.fireEvent.click(getByText(/Sign Up/i));

  await (0, _react.waitFor)(() => {
    (0, _react.waitForElementToBeRemoved)(() => getByText("First name required"));
  });
});