// jshint esversion: 6
'use strict';

import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import { mount } from '../../../build/enzyme';
import { InputCounter } from './InputCounter';
import { InputCounterControl } from './InputCounterControl';
describe('InputCounter', function () {
  var opts = {
    minValue: 7,
    maxValue: 51
  };
  it('provide minValue in case of empty-string input', function () {
    var instance = mount(React.createElement(InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue('')).toBe(opts.minValue);
  });
  it('check value for lower boundary', function () {
    var instance = mount(React.createElement(InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue(-Infinity)).toBe(opts.minValue);
  });
  it('check value for upper boundary', function () {
    var instance = mount(React.createElement(InputCounterControl, opts)).instance();
    expect(instance.getValidatedValue(Infinity)).toBe(opts.maxValue);
  });
  describe('ui', function () {
    it('check value for upper boundary', function () {
      var wrapper = mount(React.createElement(InputCounter, _extends({
        value: opts.maxValue
      }, opts)));
      expect(wrapper.findByTestAutomation('incrementButton').get(0).props.disabled).toBe(true);
    });
    it('check value for lower boundary', function () {
      var wrapper = mount(React.createElement(InputCounter, _extends({
        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 = mount(React.createElement(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 = mount(React.createElement(InputCounter, _opts));
      wrapper.findByTestAutomation('decrementButton').hostNodes().simulate('click');
    });
  });
});