"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _ilib = _interopRequireDefault(require("ilib"));
var _TemperatureControl = _interopRequireDefault(require("../TemperatureControl"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var focus = function focus(temperatureControl) {
  return _react.fireEvent.focus(temperatureControl);
};
var keyDown = function keyDown(keyCode) {
  return function (temperatureControl) {
    return _react.fireEvent.keyDown(temperatureControl, {
      keyCode: keyCode
    });
  };
};
var downKeyDown = keyDown(40);
var upKeyDown = keyDown(38);
describe('TemperatureControl', function () {
  test('should reflect disabled state to `aria-disabled`', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      disabled: true
    }));
    var temperatureControl = _react.screen.getByRole('slider');
    var expected = 'true';
    expect(temperatureControl).toHaveAttribute('aria-disabled', expected);
  });
  test('should call `onChange` when value is increased', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      onChange: handleChange
    }));
    var temperatureControl = _react.screen.getByRole('slider');
    focus(temperatureControl);
    upKeyDown(temperatureControl);
    var actual = handleChange.mock.calls.length && handleChange.mock.calls[0][0];
    var expected = {
      type: 'onChange',
      value: 16
    };
    expect(actual).toMatchObject(expected);
  });
  test('should call `onChange` when value is decreased', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      onChange: handleChange
    }));
    var temperatureControl = _react.screen.getByRole('slider');
    focus(temperatureControl);
    downKeyDown(temperatureControl);
    var actual = handleChange.mock.calls.length && handleChange.mock.calls[0][0];
    var expected = {
      type: 'onChange',
      value: 14
    };
    expect(actual).toMatchObject(expected);
  });
  test('should not call `onChange` when disabled', function () {
    var handleChange = jest.fn();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      disabled: true,
      onChange: handleChange
    }));
    var temperatureControl = _react.screen.getByRole('slider');
    focus(temperatureControl);
    downKeyDown(temperatureControl);
    expect(handleChange).not.toHaveBeenCalled();
  });
  test('should have `#007aff` foreground color when knob is positioned on the left side', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      value: 10
    }));
    var foregroundColor = _react.screen.getByRole('slider').children.item(1).children.item(0);
    var expected = '#007aff';
    expect(foregroundColor).toHaveAttribute('stroke', expected);
  });
  test('should have `#f24949` foreground color when knob is positioned on the right side', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {
      value: 25
    }));
    var foregroundColor = _react.screen.getByRole('slider').children.item(1).children.item(0);
    var expected = '#f24949';
    expect(foregroundColor).toHaveAttribute('stroke', expected);
  });
  describe('locale', function () {
    test('should convert unit to `Fahrenheit` with default `un-US` locale', function () {
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {}));
      var temperatureControl = _react.screen.getByRole('slider').children.item(2).children.item(0);
      var expected = '59°F';
      expect(temperatureControl).toHaveTextContent(expected);
    });
    test('should convert unit to `Celsius` with `ko-KR` locale', function () {
      _ilib["default"].setLocale('ko-KR');
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_TemperatureControl["default"], {}));
      var temperatureControl = _react.screen.getByRole('slider').children.item(2).children.item(0);
      var expected = '15°C';
      expect(temperatureControl).toHaveTextContent(expected);
    });
  });
});