"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _SliderButton = _interopRequireDefault(require("../SliderButton"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var children = ['Light Speed', 'Ridiculous Speed', 'Ludicrous Speed'];
var activate = function activate(slider) {
  return _react.fireEvent.keyUp(slider, {
    keyCode: 13
  });
};
var keyDown = function keyDown(keyCode) {
  return function (slider) {
    return _react.fireEvent.keyDown(slider, {
      keyCode: keyCode
    });
  };
};
var leftKeyDown = keyDown(37);
var rightKeyDown = keyDown(39);
describe('SliderButton Specs', function () {
  test('should emit an onChange event when changing to value 1', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    activate(sliderButton);
    rightKeyDown(sliderButton);
    var expected = 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should set "aria-valueText" to text when value is changed to the 2nd item', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    activate(sliderButton);
    rightKeyDown(sliderButton);
    expect(sliderButton).toHaveAttribute('aria-valuetext', 'Ridiculous Speed');
  });
  test('should set "aria-valueText" to text when value is changed to the 3rd item', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    activate(sliderButton);
    rightKeyDown(sliderButton);
    rightKeyDown(sliderButton);
    expect(sliderButton).toHaveAttribute('aria-valuetext', 'Ludicrous Speed');
  });
  test('should set "aria-valueText" to text when value is changed to the 1st item', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    activate(sliderButton);
    expect(sliderButton).toHaveAttribute('aria-valuetext', 'Light Speed');
  });
  test('should not emit onChange event when disabled', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      disabled: true,
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    activate(sliderButton);
    rightKeyDown(sliderButton);
    expect(handleChange).not.toHaveBeenCalled();
  });
  test('should change value on arrow right key press', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    rightKeyDown(sliderButton);
    var expected = 1;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should change value on arrow left press', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_SliderButton["default"], {
      onChange: handleChange,
      children: children
    }));
    var sliderButton = _react.screen.getByRole('slider');
    leftKeyDown(sliderButton);
    var expected = 0;
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
});