"use strict";

var _jsxRuntime = require("react/jsx-runtime");

var _enzyme = require("enzyme");

var _Picker = _interopRequireDefault(require("../Picker"));

var _PickerModule = _interopRequireDefault(require("../Picker.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var decrement = function decrement(picker) {
  return picker.find(".".concat(_PickerModule["default"].itemDecrement)).first().simulate('click');
};

var increment = function increment(picker) {
  return picker.find(".".concat(_PickerModule["default"].itemIncrement)).first().simulate('click');
};

describe('Picker Specs', function () {
  test('should have a default \'value\' of 0', function () {
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 0,
      min: 0
    }));
    var expected = 0;
    var actual = picker.find('Picker').prop('value');
    expect(actual).toBe(expected);
  });
  test('should return an object {value: Number} that represents the next value of the Picker component when pressing the increment <div>', function () {
    var handleChange = jest.fn();
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 5,
      min: 0,
      value: 0,
      onChange: handleChange
    }));
    increment(picker);
    var expected = 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should return an object {value: Number} that represents the next value of the Picker component when pressing the decrement <div>', function () {
    var handleChange = jest.fn();
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 1,
      min: -1,
      value: 0,
      onChange: handleChange
    }));
    decrement(picker);
    var expected = -1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should not run the onChange handler when disabled', function () {
    var handleChange = jest.fn();
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      disabled: true,
      index: 0,
      max: 0,
      min: 0,
      onChange: handleChange,
      value: 0
    }));
    increment(picker);
    var expected = 0;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should increment by \'step\' value', function () {
    var handleChange = jest.fn();
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 6,
      min: 0,
      onChange: handleChange,
      step: 3,
      value: 0
    }));
    increment(picker);
    var expected = 3;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should decrement by \'step\' value', function () {
    var handleChange = jest.fn();
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 3,
      min: 0,
      onChange: handleChange,
      step: 3,
      value: 3
    }));
    decrement(picker);
    var expected = 0;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should disable the increment button when there is no value to increment', function () {
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 2,
      min: 0,
      value: 2
    }));
    var expected = true;
    var actual = picker.find(".".concat(_PickerModule["default"].itemIncrement)).first().prop('disabled');
    expect(actual).toBe(expected);
  });
  test('should disable the decrement button when there is no value to decrement', function () {
    var picker = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 2,
      min: 0,
      value: 0
    }));
    var expected = true;
    var actual = picker.find(".".concat(_PickerModule["default"].itemDecrement)).first().prop('disabled');
    expect(actual).toBe(expected);
  });
});