"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.render = render;
exports.shallow = shallow;
exports.mount = mount;

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _enzyme = require("enzyme");

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

var _ReactWrapper2 = _interopRequireDefault(require("enzyme/build/ReactWrapper"));

var _ShallowWrapper = _interopRequireDefault(require("enzyme/build/ShallowWrapper"));

var _server = _interopRequireDefault(require("react-dom/server"));

var _cheerio = _interopRequireDefault(require("cheerio"));

// react-addons-shallow-compare and react-addons-test-utils are required for enzyme
// jshint esversion: 6
(0, _enzyme.configure)({
  adapter: new _enzymeAdapterReact.default()
});
var TEST_ID_DELIMITER = '.';
var TEST_ID_ATTRIBUTE = 'data-test-automation-id';

var ReactWrapperWMU =
/*#__PURE__*/
function (_ReactWrapper) {
  (0, _inheritsLoose2.default)(ReactWrapperWMU, _ReactWrapper);

  function ReactWrapperWMU() {
    return _ReactWrapper.apply(this, arguments) || this;
  }

  var _proto = ReactWrapperWMU.prototype;

  _proto.findByTestAutomation = function findByTestAutomation(path) {
    var w = this;
    path = path.split(TEST_ID_DELIMITER);

    while (path.length && w) {
      var _w$find;

      w = w.find((_w$find = {}, _w$find[TEST_ID_ATTRIBUTE] = path.shift(), _w$find));
    }

    return w;
  };

  return ReactWrapperWMU;
}(_ReactWrapper2.default);

function render(node) {
  var html = _server.default.renderToStaticMarkup(node);

  return _cheerio.default.load(html).root();
}

function shallow(node, options) {
  return new _ShallowWrapper.default(node, null, options);
}

function mount(node, options) {
  return new ReactWrapperWMU(node, null, options);
}