"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
var _Picker = _interopRequireDefault(require("../Picker"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
describe('Picker Specs', function () {
  test('should have a default `value` of 0', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 0,
      min: 0
    }));
    var picker = _react.screen.getByRole('spinbutton');
    var expectedAttribute = 'aria-valuetext';
    var expectedValue = '0';
    expect(picker).toHaveAttribute(expectedAttribute, expectedValue);
  });
  test('should return an object {value: Number} of the next value when incrementing', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 5,
      min: 0,
      onChange: handleChange,
      value: 0
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " next item")));
    var expected = 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  }));
  test('should return an object {value: Number} of the next value when decrementing', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 1,
      min: -1,
      onChange: handleChange,
      value: 0
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " previous item")));
    var expected = -1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  }));
  test('should wrap to the beginning of the value range if \'wrap\' is true', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 0,
      min: -1,
      onChange: handleChange,
      value: 0,
      wrap: true
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " next item")));
    var expected = -1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  }));
  test('should wrap to the end of the value range if \'wrap\' is true', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 1,
      min: 0,
      onChange: handleChange,
      value: 0,
      wrap: true
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " previous item")));
    var expected = 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  }));
  test('should not run the onChange handler when disabled', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      disabled: true,
      index: 0,
      max: 0,
      min: 0,
      onChange: handleChange,
      value: 0
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " next item")));
    expect(handleChange).not.toHaveBeenCalled();
  }));
  test('should increment by `step` value', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 6,
      min: 0,
      onChange: handleChange,
      step: 3,
      value: 0
    }));
    yield user.click(_react.screen.getByLabelText("".concat(0, " next item")));
    var expected = 3;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  }));
  test('should decrement by `step` value', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 3,
      min: 0,
      onChange: handleChange,
      step: 3,
      value: 3
    }));
    yield user.click(_react.screen.getByLabelText("".concat(3, " previous item")));
    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 () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 2,
      min: 0,
      value: 2
    }));
    var picker = _react.screen.getByLabelText('2 next item');
    var expected = 'disabled';
    expect(picker).toHaveAttribute(expected);
  });
  test('should disable the decrement button when there is no value to decrement', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      index: 0,
      max: 2,
      min: 0,
      value: 0
    }));
    var picker = _react.screen.getByLabelText('0 previous item');
    var expected = 'disabled';
    expect(picker).toHaveAttribute(expected);
  });
  test('should set custom decrement aria label', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      decrementAriaLabel: "Custom decrement aria label",
      index: 0,
      max: 2,
      min: 0,
      value: 0
    }));
    var itemDecrement = _react.screen.queryByLabelText('0 Custom decrement aria label');
    expect(itemDecrement).toBeInTheDocument();
  });
  test('should set custom increment aria label', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker["default"], {
      incrementAriaLabel: "Custom increment aria label",
      index: 0,
      max: 2,
      min: 0,
      value: 0
    }));
    var itemIncrement = _react.screen.queryByLabelText('0 Custom increment aria label');
    expect(itemIncrement).toBeInTheDocument();
  });
});