"use strict";

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

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

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

var _SigninForm = _interopRequireDefault(require("./SigninForm"));

var _db = require("./db");

var _reactRouterDom = require("react-router-dom");

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("It should mount", () => {
  const {
    queryByTestId
  } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react2.default.createElement(_SigninForm.default, null)));
  expect(queryByTestId("sign-in-form")).toBeTruthy();
});
it.skip("Should show error message when signin credentials are worng", async () => {
  const {
    getByPlaceholderText,
    getByText
  } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react2.default.createElement(_SigninForm.default, null)));
  const userNameInput = getByPlaceholderText(/example@gmail.com/i);
  const passwordInput = getByPlaceholderText(/Password/i);

  _react.fireEvent.change(userNameInput, {
    target: {
      value: "test@gmail.com"
    }
  });

  _react.fireEvent.change(passwordInput, {
    target: {
      value: "test@123"
    }
  });

  _react.fireEvent.click(getByText(/Login/i));

  await (0, _react.waitFor)(() => {
    expect(getByText("Couldn’t find a HCInbox account associated with this credentials. Please try again.")).toBeInTheDocument();
  });
});
test('We can store and retrieve intialData from the IndexedDb', function (done) {
  (0, _db.setupDB)('FORWARD_TEST', function () {
    const mockInitialData = {
      email: "realmadmin@gmail.com",
      id: "0x27ad",
      organization: {
        id: "0x27ab"
      }
    };
    (0, _db.adduserDetails)(mockInitialData, function () {
      // Now userDetails is been added, we retrieve it from
      // IndexedDB and check that we got them back in the right order.
      (0, _db.getUserDetails)(false, function (userDetails) {
        expect(userDetails.email).toBe("realmadmin@gmail.com");
        expect(userDetails.id).toBe("0x27ad");
        expect(userDetails.organization.id).toBe("0x27ab");
        done();
      });
    });
  });
});
test("Should show client side validations", async () => {
  const {
    getByPlaceholderText,
    getByText
  } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react2.default.createElement(_SigninForm.default, null)));
  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(/Login/i));

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