import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import Input from '../index';
describe('Input', function () {
  it('renders correctly', function () {
    var _render = render( /*#__PURE__*/React.createElement(Input, {
      type: "text"
    })),
        container = _render.container;

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

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

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

    var _render4 = render( /*#__PURE__*/React.createElement(Input, {
      clearable: true,
      onChange: onChange
    })),
        container = _render4.container;

    var input = container.querySelector('input');
    fireEvent.change(input, {
      target: {
        value: 'My new value'
      }
    });
    expect(input.value).toEqual('My new value');
    var clearBtn = container.querySelector('.za-input__clear');
    fireEvent.click(clearBtn);
    expect(onChange).toHaveBeenCalled();
    expect(input.value).toEqual('');
  });
});
describe('Input.Base', function () {
  it('auto focus', function () {
    var _render5 = render( /*#__PURE__*/React.createElement(Input, {
      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 = render( /*#__PURE__*/React.createElement(Input, {
      onFocus: onFocus,
      onBlur: onBlur
    })),
        container = _render6.container;

    var input = container.querySelector('input');
    fireEvent.focus(input);
    expect(onFocus).toBeCalled();
  });
  it('showLength', function () {
    var _render7 = render( /*#__PURE__*/React.createElement(Input, {
      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 = render( /*#__PURE__*/React.createElement(Input, {
      type: "text",
      rows: 4
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('autoHeight', function () {
    var wrapper = render( /*#__PURE__*/React.createElement(Input, {
      type: "text",
      rows: 4,
      autoHeight: true
    }));
    expect(wrapper.asFragment()).toMatchSnapshot();
  });
  it('renders onFocus called correctly', function () {
    var onFocus = jest.fn();

    var _render8 = render( /*#__PURE__*/React.createElement(Input, {
      type: "text",
      rows: 2,
      onFocus: onFocus
    })),
        container = _render8.container;

    var textarea = container.querySelector('textarea');
    fireEvent.focus(textarea);
    expect(onFocus).toBeCalled(); // expect(toJson(wrapper)).toMatchSnapshot();
    //  wrapper.unmount();
  });
});