"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _react = _interopRequireDefault(require("react"));

var _Slider = _interopRequireDefault(require("../Slider"));

var _Slider2 = _interopRequireDefault(require("../Slider/Slider.Skeleton"));

var _enzyme = require("enzyme");

require("requestanimationframe");

describe('Slider', function () {
  describe('Renders as expected', function () {
    var mockFn = jest.fn();
    var wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(_Slider.default, {
      id: "slider",
      className: "extra-class",
      value: 50,
      min: 0,
      max: 100,
      step: 1,
      onChange: mockFn
    }));
    it('renders children as expected', function () {
      expect(wrapper.length).toBe(1);
    });
    it('has the expected classes', function () {
      expect(wrapper.find('.wfp--slider').length).toBe(1);
    });
    it('renders extra classes passed in via className', function () {
      expect(wrapper.find('.wfp--slider').hasClass('extra-class')).toEqual(true);
    });
    it('can be disabled', function () {
      wrapper.setProps({
        disabled: true
      });
      expect(wrapper.props().disabled).toEqual(true);
    });
    it('can set value via props', function () {
      wrapper.setProps({
        value: 55
      });
      expect(wrapper.props().value).toEqual(55);
    });
  });
  describe('Supporting label', function () {
    it('concatenates the value and the label by default', function () {
      var wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(_Slider.default, {
        id: "slider-1",
        min: 0,
        minLabel: "min",
        max: 100,
        maxLabel: "max",
        value: 0
      }));
      expect(wrapper.find('.wfp--slider__range-label').first().text()).toBe('0min');
      expect(wrapper.find('.wfp--slider__range-label').last().text()).toBe('100max');
    });
    it('supports custom formatting of the label', function () {
      var wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(_Slider.default, {
        id: "slider-2",
        min: 0,
        minLabel: "min",
        max: 100,
        maxLabel: "max",
        formatLabel: function formatLabel(value, label) {
          return "".concat(value, "-").concat(label);
        },
        value: 0
      }));
      expect(wrapper.find('.wfp--slider__range-label').first().text()).toBe('0-min');
      expect(wrapper.find('.wfp--slider__range-label').last().text()).toBe('100-max');
    });
  });
  describe('updatePosition method', function () {
    var mockFn = jest.fn();
    var wrapper = (0, _enzyme.mount)( /*#__PURE__*/_react.default.createElement(_Slider.default, {
      id: "slider",
      className: "extra-class",
      value: 50,
      min: 0,
      max: 100,
      step: 1,
      onChange: mockFn
    })); // it('sets correct state from event with a right/up keydown', () => {
    //   const evt = {
    //     type: 'keydown',
    //     which: '38',
    //   };
    //   console.log(wrapper.instance())
    //   wrapper.update(evt);
    //   expect(mockFn).lastCalledWith(51);
    //   expect(wrapper.state().value).toEqual(51);
    // });
    // it('sets correct state from event with a left/down keydown', () => {
    //   const evt = {
    //     type: 'keydown',
    //     which: '40',
    //   };
    //   wrapper.instance().updatePosition(evt);
    //   expect(mockFn).lastCalledWith(50);
    //   expect(wrapper.state().value).toEqual(50);
    // });
    // it('sets correct state from event with a clientX', () => {
    //   const evt = {
    //     type: 'click',
    //     clientX: '1000',
    //   };
    //   wrapper.instance().updatePosition(evt);
    //   expect(mockFn).lastCalledWith(100);
    //   expect(wrapper.state().value).toEqual(100);
    // });
  });
});
describe('SliderSkeleton', function () {
  describe('Renders as expected', function () {
    var wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Slider2.default, null));
    var slider = wrapper.find('.wfp--slider-container');
    it('Has the expected classes', function () {
      expect(slider.hasClass('wfp--skeleton')).toEqual(true);
    });
  });
});