import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import Stepper from '../index';
describe('Stepper', function () {
  it('renders correctly', function () {
    var onChange = jest.fn();

    var _render = render( /*#__PURE__*/React.createElement(Stepper, {
      onChange: onChange
    })),
        container = _render.container;

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

    var _render2 = render( /*#__PURE__*/React.createElement(Stepper, {
      onChange: onChange,
      size: "lg"
    })),
        container = _render2.container;

    expect(container).toMatchSnapshot();
  });
  it('defaultValue', function () {
    var _render3 = render( /*#__PURE__*/React.createElement(Stepper, {
      defaultValue: 2
    })),
        container = _render3.container;

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

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

            fireEvent.click(container.querySelector('.za-stepper__sub'));
            _context.next = 5;
            return waitFor(function () {
              expect(container.querySelector('input').value).toBe("0");
            });

          case 5:
            // wrapper.setProps({ value: 2 });
            plus = container.querySelector('.za-stepper__plus');
            fireEvent.click(plus);
            fireEvent.click(plus);
            fireEvent.click(plus);
            fireEvent.click(plus);
            _context.next = 12;
            return 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 = render( /*#__PURE__*/React.createElement(Stepper, {
      min: undefined,
      max: undefined,
      onChange: onChange,
      onInputChange: onInputChange
    })),
        container = _render5.container;

    var input = container.querySelector('input');
    fireEvent.change(input, {
      target: {
        value: 10
      }
    });
    expect(onInputChange).toBeCalled();
  });
  it('onChange', function () {
    var onChange = jest.fn();

    var _render6 = render( /*#__PURE__*/React.createElement(Stepper, {
      onChange: onChange
    })),
        container = _render6.container;

    var plus = container.querySelector('.za-stepper__plus');
    fireEvent.click(plus);
    expect(onChange).toBeCalled();
  });
  it('decimal step', function () {
    var onChange = jest.fn();
    var onInputChange = jest.fn();

    var _render7 = render( /*#__PURE__*/React.createElement(Stepper, {
      onChange: onChange,
      onInputChange: onInputChange,
      step: 0.1,
      value: 1
    })),
        container = _render7.container;

    var sub = container.querySelector('.za-stepper__sub');
    fireEvent.click(sub);
    expect(container.querySelector('input').value).toBe('0.9');
    var plus = container.querySelector('.za-stepper__plus');
    fireEvent.click(plus);
    fireEvent.click(plus);
    expect(container.querySelector('input').value).toBe('1.1');
  });
  it('disable work', function () {
    var onChange = jest.fn();

    var _render8 = render( /*#__PURE__*/React.createElement(Stepper, {
      disabled: true,
      step: 0.1,
      value: 1
    })),
        container = _render8.container;

    var sub = container.querySelector('.za-stepper__sub');
    fireEvent.click(sub);
    var plus = container.querySelector('.za-stepper__plus');
    fireEvent.click(plus);
    expect(onChange).toHaveBeenCalledTimes(0);
  });
});