"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('Input', function () {
  it('renders correctly', function () {
    var _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "text"
    })),
        container = _render.container;

    expect(container).toMatchSnapshot();
  });
  it('renders correctly if type=text and props includes rows', function () {
    var _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "text",
      rows: 1
    })),
        container = _render2.container;

    expect(container).toMatchSnapshot();
  });
  it("renders correctly if type isn't valid", function () {
    var _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "xxx"
    })),
        container = _render3.container;

    expect(container).toMatchSnapshot();
  });
  it('renders onClear called correctly', function () {
    var onChange = jest.fn();

    var _render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      clearable: true,
      onChange: onChange
    })),
        container = _render4.container;

    var input = container.querySelector('input');

    _react.fireEvent.change(input, {
      target: {
        value: 'My new value'
      }
    });

    expect(input.value).toEqual('My new value');
    var clearBtn = container.querySelector('.za-input__clear');

    _react.fireEvent.click(clearBtn);

    expect(onChange).toHaveBeenCalled();
    expect(input.value).toEqual('');
  });
});
describe('Input.Base', function () {
  it('auto focus', function () {
    var _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      className: "text-input",
      autoFocus: true
    })),
        container = _render5.container;

    var input = container.querySelectorAll('.za-input--focus');
    expect(input.length).toBe(1);
  });
  it('renders onFocus onBlur called correctly', function () {
    var onFocus = jest.fn();
    var onBlur = jest.fn();

    var _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      onFocus: onFocus,
      onBlur: onBlur
    })),
        container = _render6.container;

    var input = container.querySelector('input');

    _react.fireEvent.focus(input);

    expect(onFocus).toBeCalled();
  });
  it('showLength', function () {
    var _render7 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      showLength: true,
      maxLength: 100,
      type: "text",
      rows: 4,
      defaultValue: "\u6D4B\u8BD5a"
    })),
        container = _render7.container;

    var content = container.querySelector('.za-input__length');
    expect(content === null || content === void 0 ? void 0 : content.textContent).toEqual('3/100');
  });
});
describe('Input.Textarea', function () {
  it('renders correctly', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "text",
      rows: 4
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('autoHeight', function () {
    var wrapper = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "text",
      rows: 4,
      autoHeight: true
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('renders onFocus called correctly', function () {
    var onFocus = jest.fn();

    var _render8 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_index.default, {
      type: "text",
      rows: 2,
      onFocus: onFocus
    })),
        container = _render8.container;

    var textarea = container.querySelector('textarea');

    _react.fireEvent.focus(textarea);

    expect(onFocus).toBeCalled(); // expect(toJson(wrapper)).toMatchSnapshot();
    //  wrapper.unmount();
  });
});