"use strict";

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

var _enzyme = require("enzyme");

var _IncrementSlider = _interopRequireDefault(require("../IncrementSlider"));

var _IncrementSliderModule = _interopRequireDefault(require("../IncrementSlider.module.css"));

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

var tap = function tap(node) {
  node.simulate('mousedown');
  node.simulate('mouseup');
};

var decrement = function decrement(slider) {
  return tap(slider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].decrementButton)));
};

var increment = function increment(slider) {
  return tap(slider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].incrementButton)));
};

describe('IncrementSlider Specs', function () {
  test('should decrement value', function () {
    var handleChange = jest.fn();
    var value = 50;
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      onChange: handleChange,
      value: value
    }));
    decrement(incrementSlider);
    var expected = value - 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should increment value', function () {
    var handleChange = jest.fn();
    var value = 50;
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      onChange: handleChange,
      value: value
    }));
    increment(incrementSlider);
    var expected = value + 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should only call onChange once', function () {
    var handleChange = jest.fn();
    var value = 50;
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      onChange: handleChange,
      value: value
    }));
    increment(incrementSlider);
    var expected = 1;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should not call onChange on prop change', function () {
    var handleChange = jest.fn();
    var value = 50;
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      onChange: handleChange,
      value: value
    }));
    incrementSlider.setProps({
      onChange: handleChange,
      value: value + 1
    });
    var expected = 0;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should disable decrement button when value === min', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 0,
      min: 0
    }));
    var expected = true;
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].decrementButton)).prop('disabled');
    expect(actual).toBe(expected);
  });
  test('should disable increment button when value === max', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 10,
      max: 10
    }));
    var expected = true;
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].incrementButton)).prop('disabled');
    expect(actual).toBe(expected);
  });
  test('should use custom incrementIcon', function () {
    var icon = 'plus';
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      incrementIcon: icon
    }));
    var expected = icon;
    var actual = incrementSlider.find(".".concat(_IncrementSliderModule["default"].incrementButton, " Icon")).prop('children');
    expect(actual).toBe(expected);
  });
  test('should use custom decrementIcon', function () {
    var icon = 'minus';
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      decrementIcon: icon
    }));
    var expected = icon;
    var actual = incrementSlider.find(".".concat(_IncrementSliderModule["default"].decrementButton, " Icon")).prop('children');
    expect(actual).toBe(expected);
  });
  test('should set decrementButton "aria-label" to value and hint string', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 10
    }));
    var expected = '10 press button to decrease the value';
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].decrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should set decrementButton "aria-label" to decrementAriaLabel', function () {
    var label = 'decrement aria label';
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 10,
      decrementAriaLabel: label
    }));
    var expected = "10 ".concat(label);
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].decrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should set decrementButton "aria-label" when decrementButton is disabled', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      disabled: true,
      value: 10
    }));
    var expected = '10 press button to decrease the value';
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].decrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should set incrementButton "aria-label" to value and hint string', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 10
    }));
    var expected = '10 press button to increase the value';
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].incrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should set incrementButton "aria-label" to incrementAriaLabel', function () {
    var label = 'increment aria label';
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      value: 10,
      incrementAriaLabel: label
    }));
    var expected = "10 ".concat(label);
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].incrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should set incrementButton "aria-label" when incrementButton is disabled', function () {
    var incrementSlider = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSlider["default"], {
      disabled: true,
      value: 10
    }));
    var expected = '10 press button to increase the value';
    var actual = incrementSlider.find("IncrementSliderButton.".concat(_IncrementSliderModule["default"].incrementButton)).prop('aria-label');
    expect(actual).toBe(expected);
  });
});