"use strict";

var _react = _interopRequireDefault(require("react"));
var _noop = _interopRequireDefault(require("lodash/noop"));
var _mount = _interopRequireDefault(require("enzyme/mount"));
var _render = _interopRequireDefault(require("enzyme/render"));
var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
var _index = _interopRequireDefault(require("./index"));
var _ServiceLocator = _interopRequireDefault(require("../../../../ServiceLocator"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-env jest */
var mockedFontsList = [{
  identifier: 'Calibri',
  title: 'Calibri',
  value: 'Calibri'
}, {
  identifier: 'Arial',
  title: 'Arial',
  value: 'Arial'
}, {
  identifier: 'Helvetica',
  title: 'Helvetica',
  value: 'Helvetica'
}, {
  identifier: 'Times New Roman',
  title: 'Times New Roman',
  value: 'Times New Roman'
}, {
  identifier: 'Roboto',
  title: 'Roboto',
  value: 'Roboto'
}, {
  identifier: 'Verdana',
  title: 'Verdana',
  value: 'Verdana'
}];
var popupArea = {};
it('renders correctly', function () {
  var tree = (0, _render["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    width: "lg",
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: _noop["default"],
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    handleChangeFont: _noop["default"],
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: _noop["default"],
    popupArea: popupArea
  }));
  expect(tree).toMatchSnapshot();
});
it('renders a boxed component with the boxed prop', function () {
  var tree = (0, _render["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    width: "lg",
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: _noop["default"],
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    handleChangeFont: _noop["default"],
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: _noop["default"],
    boxed: true
  }));
  expect(tree).toMatchSnapshot();
});
it('calls the handleChangeText callback when the user changes the TextControlbox textfield', function () {
  var onChangeHandler = jest.fn();
  var tree = (0, _mount["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: onChangeHandler,
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    width: "lg",
    handleChangeFont: _noop["default"],
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: onChangeHandler
  }));
  var textarea = tree.find('textarea').at(0);
  textarea.simulate('change', {
    target: {
      value: 'Lorem'
    }
  });
  expect(onChangeHandler).toHaveBeenCalled();
});
it('calls the handleChangeFont callback when the user changes the TextControlbox fontFamily', function () {
  var _class;
  var analyticsSrvc = new (_class = /*#__PURE__*/_createClass(function _class() {
    _classCallCheck(this, _class);
    _defineProperty(this, "triggerEvent", jest.fn());
  }), _defineProperty(_class, "serviceName", 'AnalyticsService'), _class)();
  _ServiceLocator["default"].provide(analyticsSrvc);
  var onChangeHandler = jest.fn();
  var tree = (0, _mount["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    width: "lg",
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: _noop["default"],
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    handleChangeFont: onChangeHandler,
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: _noop["default"]
  }));
  var button = tree.find('[role="button"]');
  button.simulate('mousedown', {
    button: 0
  });
  var option = tree.find(_MenuItem["default"]).at(1);
  option.simulate('click');
  expect(onChangeHandler).toHaveBeenCalled();
});
it('calls the toggleIsBulkName callback on checkbox click', function () {
  var onChangeHandler = jest.fn();
  var tree = (0, _mount["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    width: "lg",
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: _noop["default"],
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    handleChangeFont: _noop["default"],
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: _noop["default"],
    isBulkName: false,
    toggleIsBulkName: onChangeHandler,
    isActiveBulkName: true
  }));
  var checkbox = tree.find('input[type="checkbox"]');
  checkbox.simulate('change', {});
  expect(onChangeHandler).toHaveBeenCalled();
});
it('checkbox should be checked if property isBulkName is true', function () {
  var tree = (0, _mount["default"])( /*#__PURE__*/_react["default"].createElement(_index["default"], {
    width: "lg",
    textValue: "Lorem ipsum dolor sit amet, cosectetur adipiscing elit",
    handleChangeText: _noop["default"],
    fontValue: mockedFontsList[0],
    fonts: mockedFontsList,
    handleChangeFont: _noop["default"],
    minSize: 8,
    maxSize: 12,
    fontSizeValue: 10,
    onChangeFontSize: _noop["default"],
    isBulkName: true,
    toggleIsBulkName: _noop["default"],
    isActiveBulkName: true
  }));
  var checkbox = tree.find('input[type="checkbox"]');
  expect(checkbox.props().checked).toBeTruthy();
});