"use strict";

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

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

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

var _index = _interopRequireDefault(require("../index"));

describe('CustomInput', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "number"
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('renders readonly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "number",
      readOnly: true
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('auto focus', function () {
    var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      autoFocus: true,
      className: "custom-input"
    })),
        container = _render.container;

    var input = container.getElementsByClassName('za-custom-input--focus');
    expect(input).toHaveLength(1);
  });
  it('show clear', function () {
    var onChange = jest.fn();

    var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      clearable: true,
      className: "custom-input",
      defaultValue: "test",
      onChange: onChange,
      autoFocus: true
    })),
        container = _render2.container;

    var clear = container.querySelector('.za-custom-input__clear');

    _react.fireEvent.click(clear);

    var input = container.querySelectorAll('input[type="hidden"]')[0];
    expect(input.value).toEqual('');
  });
  it('focus', function () {
    var onFocus = jest.fn();

    var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      className: "custom-input",
      value: "test",
      onFocus: onFocus
    })),
        container = _render3.container;

    var input = container.querySelector('.za-custom-input');

    _react.fireEvent.click(input);

    expect(onFocus).toBeCalled();
  });
  it('disabled focus', function () {
    var onFocus = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      className: "custom-input",
      value: "test",
      onFocus: onFocus,
      disabled: true
    }));
    var input = document.body.querySelector('.za-custom-input');

    _react.fireEvent.click(input);

    expect(onFocus).toBeCalledTimes(0);
  });
  it('onBlur', function () {
    var onBlur = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "number",
      className: "custom-input",
      onBlur: onBlur,
      autoFocus: true
    }));

    _react.fireEvent.click(document.body);

    expect(onBlur).toBeCalledTimes(1);
  });
  it('onKeyClick', function () {
    var onBlur = jest.fn();
    var onChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "number",
      className: "custom-input",
      onBlur: onBlur,
      autoFocus: true,
      onChange: onChange
    }));
    var item = document.body.getElementsByClassName('za-keyboard__item');

    _react.fireEvent.click(item[10]);

    expect(onBlur).toBeCalledTimes(1);

    _react.fireEvent.click(item[1]);

    expect(onChange).toBeCalled();
  });
  it('maxLength', function () {
    var onChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "number",
      className: "custom-input",
      value: "1234",
      maxLength: 4,
      autoFocus: true,
      onChange: onChange
    }));
    var item = document.body.getElementsByClassName('za-keyboard__item');

    _react.fireEvent.click(item[1]);

    expect(onChange).toBeCalledTimes(0);
  });
});
describe('CustomInput.Number', function () {
  it('inputNumber value 0', function () {
    (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      clearable: true,
      type: "number",
      value: 0
    }));
    var input = document.body.querySelectorAll('input[type="hidden"]')[0];
    expect(input.value).toEqual('0');
  });
});
describe('CustomInput.Price', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "price"
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
});
describe('CustomInput.Idcard', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "idcard",
      maxLength: 18
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
});