// jshint esversion: 6
'use strict';

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

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

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

var _enzyme = require("../../../build/enzyme");

var _InputCounter = require("./InputCounter");

var _InputCounterControl = require("./InputCounterControl");

describe('InputCounter', function () {
  var opts = {
    minValue: 7,
    maxValue: 51
  };
  it('provide minValue in case of empty-string input', function () {
    var instance = (0, _enzyme.mount)(_react.default.createElement(_InputCounterControl.InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue('')).toBe(opts.minValue);
  });
  it('check value for lower boundary', function () {
    var instance = (0, _enzyme.mount)(_react.default.createElement(_InputCounterControl.InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue(-Infinity)).toBe(opts.minValue);
  });
  it('check value for upper boundary', function () {
    var instance = (0, _enzyme.mount)(_react.default.createElement(_InputCounterControl.InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue(Infinity)).toBe(opts.maxValue);
  });
  describe('ui', function () {
    it('check value for upper boundary', function () {
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_InputCounter.InputCounter, (0, _extends2.default)({
        value: opts.maxValue
      }, opts)));
      expect(wrapper.findByTestAutomation('incrementButton').get(0).props.disabled).toBe(true);
    });
    it('check value for lower boundary', function () {
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_InputCounter.InputCounter, (0, _extends2.default)({
        value: opts.minValue
      }, opts)));
      expect(wrapper.findByTestAutomation('decrementButton').get(0).props.disabled).toBe(true);
    });
    it('increase value by one', function (done) {
      var value = 9;

      var _opts = Object.assign({}, opts, {
        value: value,
        onChange: function onChange(v) {
          expect(v).toBe(value + 1);
          done();
        }
      });

      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_InputCounter.InputCounter, _opts));
      wrapper.findByTestAutomation('incrementButton').hostNodes().simulate('click');
    });
    it('decrease value by one', function (done) {
      var value = 22;

      var _opts = Object.assign({}, opts, {
        value: value,
        onChange: function onChange(v) {
          expect(v).toBe(value - 1);
          done();
        }
      });

      var wrapper = (0, _enzyme.mount)(_react.default.createElement(_InputCounter.InputCounter, _opts));
      wrapper.findByTestAutomation('decrementButton').hostNodes().simulate('click');
    });
  });
});