"use strict";

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

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

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

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

describe('Stepper', function () {
  it('renders correctly', function () {
    var onChange = jest.fn();

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

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

    var _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      onChange: onChange,
      size: "lg"
    })),
        container = _render2.container;

    expect(container).toMatchSnapshot();
  });
  it('defaultValue', function () {
    var _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      defaultValue: 2
    })),
        container = _render3.container;

    expect(container).toMatchSnapshot();
  });
  it('disabled sub or plus click', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var onChange, _render4, container, plus;

    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onChange = jest.fn();
            _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              max: 2,
              min: 0,
              onChange: onChange
            })), container = _render4.container; // wrapper.setProps({ value: 0 });

            _react2.fireEvent.click(container.querySelector('.za-stepper__sub'));

            _context.next = 5;
            return (0, _react2.waitFor)(function () {
              expect(container.querySelector('input').value).toBe("0");
            });

          case 5:
            // wrapper.setProps({ value: 2 });
            plus = container.querySelector('.za-stepper__plus');

            _react2.fireEvent.click(plus);

            _react2.fireEvent.click(plus);

            _react2.fireEvent.click(plus);

            _react2.fireEvent.click(plus);

            _context.next = 12;
            return (0, _react2.waitFor)(function () {
              expect(container.querySelector('input').value).toBe("2");
            });

          case 12:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it('onInputChange', function () {
    var onChange = jest.fn();
    var onInputChange = jest.fn();

    var _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      min: undefined,
      max: undefined,
      onChange: onChange,
      onInputChange: onInputChange
    })),
        container = _render5.container;

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

    _react2.fireEvent.change(input, {
      target: {
        value: 10
      }
    });

    expect(onInputChange).toBeCalled();
  });
  it('onChange', function () {
    var onChange = jest.fn();

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

    var plus = container.querySelector('.za-stepper__plus');

    _react2.fireEvent.click(plus);

    expect(onChange).toBeCalled();
  });
  it('decimal step', function () {
    var onChange = jest.fn();
    var onInputChange = jest.fn();

    var _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      onChange: onChange,
      onInputChange: onInputChange,
      step: 0.1,
      value: 1
    })),
        container = _render7.container;

    var sub = container.querySelector('.za-stepper__sub');

    _react2.fireEvent.click(sub);

    expect(container.querySelector('input').value).toBe('0.9');
    var plus = container.querySelector('.za-stepper__plus');

    _react2.fireEvent.click(plus);

    _react2.fireEvent.click(plus);

    expect(container.querySelector('input').value).toBe('1.1');
  });
  it('disable work', function () {
    var onChange = jest.fn();

    var _render8 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      disabled: true,
      step: 0.1,
      value: 1
    })),
        container = _render8.container;

    var sub = container.querySelector('.za-stepper__sub');

    _react2.fireEvent.click(sub);

    var plus = container.querySelector('.za-stepper__plus');

    _react2.fireEvent.click(plus);

    expect(onChange).toHaveBeenCalledTimes(0);
  });
});