"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _react = _interopRequireDefault(require("react"));
var _Slider = _interopRequireDefault(require("../Slider"));
var _unit = require("../../utils/test-utils/unit");
var _SliderUni = require("../Slider.uni.driver");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Slider/test/Slider.spec.jsx";
describe('Slider', function () {
  describe('[async]', function () {
    runTests((0, _unit.createRendererWithUniDriver)(_SliderUni.sliderUniDriverFactory));
  });
  function runTests(render) {
    var _this = this;
    afterEach(function () {
      return (0, _unit.cleanup)();
    });
    it('should render slider', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
      var onChange, props, _render, driver;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            onChange = vi.fn(function (value) {
              return _this.setState({
                value: value
              });
            });
            props = {
              value: [3],
              min: 1,
              max: 10,
              onChange: onChange
            };
            _render = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 21,
                columnNumber: 33
              }
            }))), driver = _render.driver;
            _context.t0 = expect;
            _context.next = 6;
            return driver.numOfSliderDots();
          case 6:
            _context.t1 = _context.sent;
            (0, _context.t0)(_context.t1).toBe(10);
            _context.t2 = expect;
            _context.next = 11;
            return driver.numOfSliderHandles();
          case 11:
            _context.t3 = _context.sent;
            (0, _context.t2)(_context.t3).toBe(1);
            _context.t4 = expect;
            _context.next = 16;
            return driver.isDotSelected(3);
          case 16:
            _context.t5 = _context.sent;
            (0, _context.t4)(_context.t5).toBe(true);
            _context.t6 = expect;
            _context.next = 21;
            return driver.isDisabled();
          case 21:
            _context.t7 = _context.sent;
            (0, _context.t6)(_context.t7).toBe(false);
          case 23:
          case "end":
            return _context.stop();
        }
      }, _callee);
    })));
    it('should return value', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      var onChange, props, _render2, driver;
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            onChange = vi.fn();
            props = {
              value: 10,
              min: 1,
              max: 10,
              onChange: onChange
            };
            _render2 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 32,
                columnNumber: 33
              }
            }))), driver = _render2.driver;
            _context2.t0 = expect;
            _context2.next = 6;
            return driver.getValue();
          case 6:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).toBe('10');
          case 8:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it('should decrease value by 1 step', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      var onChange, props, _render3, driver;
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            onChange = vi.fn();
            props = {
              value: 10,
              min: 1,
              max: 10,
              onChange: onChange
            };
            _render3 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 40,
                columnNumber: 33
              }
            }))), driver = _render3.driver;
            _context3.next = 5;
            return driver.decreaseValueOnce();
          case 5:
            expect(onChange).toHaveBeenCalledTimes(1);
            expect(onChange).toHaveBeenCalledWith(props.value - 1);
          case 7:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should increase value by 1 step', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      var onChange, props, _render4, driver;
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            onChange = vi.fn();
            props = {
              value: 1,
              min: 1,
              max: 10,
              onChange: onChange
            };
            _render4 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 51,
                columnNumber: 33
              }
            }))), driver = _render4.driver;
            _context4.next = 5;
            return driver.increaseValueOnce();
          case 5:
            expect(onChange).toHaveBeenCalledTimes(1);
            expect(onChange).toHaveBeenCalledWith(props.value + 1);
          case 7:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
    it('should show correct value on hover', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var onChange, props, _render5, driver;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            onChange = vi.fn(function (value) {
              return _this.setState({
                value: value
              });
            });
            props = {
              value: [3, 5, 7],
              min: 1,
              max: 10,
              onChange: onChange
            };
            _render5 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 63,
                columnNumber: 33
              }
            }))), driver = _render5.driver;
            _context5.t0 = expect;
            _context5.next = 6;
            return driver.getToolTipValue(0);
          case 6:
            _context5.t1 = _context5.sent;
            (0, _context5.t0)(_context5.t1).toBe("".concat(props.value[0]));
            _context5.t2 = expect;
            _context5.next = 11;
            return driver.getToolTipValue(1);
          case 11:
            _context5.t3 = _context5.sent;
            (0, _context5.t2)(_context5.t3).toBe("".concat(props.value[1]));
          case 13:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should not display tooltip if `displayTooltip` is set to false', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var onChange, props, _render6, driver;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            onChange = vi.fn(function (value) {
              return _this.setState({
                value: value
              });
            });
            props = {
              value: [4],
              displayTooltip: false,
              onChange: onChange
            };
            _render6 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 73,
                columnNumber: 33
              }
            }))), driver = _render6.driver;
            _context6.t0 = expect;
            _context6.next = 6;
            return driver.getToolTipValue(0);
          case 6:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toBeFalsy();
          case 8:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should display a disabled slider', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      var onChange, props, _render7, driver;
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            onChange = vi.fn(function (value) {
              return _this.setState({
                value: value
              });
            });
            props = {
              value: 3,
              onChange: onChange,
              disabled: true
            };
            _render7 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 81,
                columnNumber: 33
              }
            }))), driver = _render7.driver;
            _context7.t0 = expect;
            _context7.next = 6;
            return driver.isDisabled();
          case 6:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toBe(true);
          case 8:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    describe('custom marks', function () {
      var marks = {
        0: '$0',
        2: '$79',
        4: '$129',
        6: '$199',
        8: '$349',
        10: '$499'
      };
      var commonProps = {
        marks: marks,
        min: 0,
        max: 10,
        value: 2
      };
      it('should render marks when given a "marks" object', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
        var onChange, _render8, driver;
        return _regenerator["default"].wrap(function _callee8$(_context8) {
          while (1) switch (_context8.prev = _context8.next) {
            case 0:
              onChange = vi.fn(function (value) {
                return _this.setState({
                  value: value
                });
              });
              _render8 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, commonProps, {
                onChange: onChange,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 101,
                  columnNumber: 11
                }
              }))), driver = _render8.driver;
              _context8.t0 = expect;
              _context8.next = 5;
              return driver.numOfSliderMarksLabels();
            case 5:
              _context8.t1 = _context8.sent;
              (0, _context8.t0)(_context8.t1).toBe(Object.values(marks).length);
            case 7:
            case "end":
              return _context8.stop();
          }
        }, _callee8);
      })));
      it('should display the mark label when hovering the slider handle', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9() {
        var onChange, _render9, driver;
        return _regenerator["default"].wrap(function _callee9$(_context9) {
          while (1) switch (_context9.prev = _context9.next) {
            case 0:
              onChange = vi.fn(function (value) {
                return _this.setState({
                  value: value
                });
              });
              _render9 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, commonProps, {
                onChange: onChange,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 111,
                  columnNumber: 11
                }
              }))), driver = _render9.driver;
              _context9.t0 = expect;
              _context9.next = 5;
              return driver.getToolTipValue(0);
            case 5:
              _context9.t1 = _context9.sent;
              (0, _context9.t0)(_context9.t1).toBe(marks[2]);
            case 7:
            case "end":
              return _context9.stop();
          }
        }, _callee9);
      })));
      it('should not display tooltip if the handler has value with no mark label', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0() {
        var onChange, _render0, driver;
        return _regenerator["default"].wrap(function _callee0$(_context0) {
          while (1) switch (_context0.prev = _context0.next) {
            case 0:
              onChange = vi.fn(function (value) {
                return _this.setState({
                  value: value
                });
              });
              _render0 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, commonProps, {
                value: 1,
                onChange: onChange,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 120,
                  columnNumber: 11
                }
              }))), driver = _render0.driver;
              _context0.t0 = expect;
              _context0.next = 5;
              return driver.getToolTipValue(0);
            case 5:
              _context0.t1 = _context0.sent;
              (0, _context0.t0)(_context0.t1).toBeFalsy();
            case 7:
            case "end":
              return _context0.stop();
          }
        }, _callee0);
      })));
      it('should display tooltip with the string "0" when label is the number zero', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1() {
        var customMarks, onChange, props, _render1, driver;
        return _regenerator["default"].wrap(function _callee1$(_context1) {
          while (1) switch (_context1.prev = _context1.next) {
            case 0:
              customMarks = {
                0: 0,
                1: 5,
                2: 10,
                3: 15
              };
              onChange = vi.fn(function (value) {
                return _this.setState({
                  value: value
                });
              });
              props = {
                marks: customMarks,
                onChange: onChange,
                value: 0,
                min: 0,
                max: 3
              };
              _render1 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 142,
                  columnNumber: 35
                }
              }))), driver = _render1.driver;
              _context1.t0 = expect;
              _context1.next = 7;
              return driver.getToolTipValue(0);
            case 7:
              _context1.t1 = _context1.sent;
              (0, _context1.t0)(_context1.t1).toBe('0');
            case 9:
            case "end":
              return _context1.stop();
          }
        }, _callee1);
      })));
    });
    describe('Range mode', function () {
      var multiRangeValue = [3, 5, 7];
      it('should render slider with multi-range', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11() {
        var onChange, props, _render10, driver;
        return _regenerator["default"].wrap(function _callee11$(_context11) {
          while (1) switch (_context11.prev = _context11.next) {
            case 0:
              onChange = vi.fn(function (value) {
                return _this.setState({
                  value: value
                });
              });
              props = {
                value: multiRangeValue,
                min: 1,
                max: 10,
                onChange: onChange
              };
              _render10 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 155,
                  columnNumber: 35
                }
              }))), driver = _render10.driver;
              _context11.t0 = expect;
              _context11.next = 6;
              return driver.numOfSliderDots();
            case 6:
              _context11.t1 = _context11.sent;
              (0, _context11.t0)(_context11.t1).toBe(10);
              _context11.t2 = expect;
              _context11.next = 11;
              return driver.numOfSliderHandles();
            case 11:
              _context11.t3 = _context11.sent;
              (0, _context11.t2)(_context11.t3).toBe(3);
              props.value.forEach(/*#__PURE__*/function () {
                var _ref11 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10(selectedValue) {
                  return _regenerator["default"].wrap(function _callee10$(_context10) {
                    while (1) switch (_context10.prev = _context10.next) {
                      case 0:
                        _context10.t0 = expect;
                        _context10.next = 3;
                        return driver.isDotSelected(selectedValue);
                      case 3:
                        _context10.t1 = _context10.sent;
                        (0, _context10.t0)(_context10.t1).toBe(true);
                      case 5:
                      case "end":
                        return _context10.stop();
                    }
                  }, _callee10);
                }));
                return function (_x) {
                  return _ref11.apply(this, arguments);
                };
              }());
            case 14:
            case "end":
              return _context11.stop();
          }
        }, _callee11);
      })));
      it('should be enabled when array is given to value prop', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12() {
        var onChange, props, _render11, driver;
        return _regenerator["default"].wrap(function _callee12$(_context12) {
          while (1) switch (_context12.prev = _context12.next) {
            case 0:
              onChange = vi.fn();
              props = {
                value: multiRangeValue,
                displayTooltip: false,
                onChange: onChange
              };
              _render11 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 172,
                  columnNumber: 35
                }
              }))), driver = _render11.driver;
              _context12.t0 = expect;
              _context12.next = 6;
              return driver.numOfSliderHandles();
            case 6:
              _context12.t1 = _context12.sent;
              (0, _context12.t0)(_context12.t1).toBe(props.value.length);
            case 8:
            case "end":
              return _context12.stop();
          }
        }, _callee12);
      })));
    });
    describe('Slide mode', function () {
      it('should be enabled when number is given to value prop', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee13() {
        var onChange, props, _render12, driver;
        return _regenerator["default"].wrap(function _callee13$(_context13) {
          while (1) switch (_context13.prev = _context13.next) {
            case 0:
              onChange = vi.fn();
              props = {
                value: 2,
                displayTooltip: false,
                onChange: onChange
              };
              _render12 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 181,
                  columnNumber: 35
                }
              }))), driver = _render12.driver;
              _context13.t0 = expect;
              _context13.next = 6;
              return driver.numOfSliderHandles();
            case 6:
              _context13.t1 = _context13.sent;
              (0, _context13.t0)(_context13.t1).toBe(1);
            case 8:
            case "end":
              return _context13.stop();
          }
        }, _callee13);
      })));
      it('should be enabled when array with 1 item given to value', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee14() {
        var onChange, props, _render13, driver;
        return _regenerator["default"].wrap(function _callee14$(_context14) {
          while (1) switch (_context14.prev = _context14.next) {
            case 0:
              onChange = vi.fn();
              props = {
                value: [2],
                displayTooltip: false,
                onChange: onChange
              };
              _render13 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 188,
                  columnNumber: 35
                }
              }))), driver = _render13.driver;
              _context14.t0 = expect;
              _context14.next = 6;
              return driver.numOfSliderHandles();
            case 6:
              _context14.t1 = _context14.sent;
              (0, _context14.t0)(_context14.t1).toBe(1);
            case 8:
            case "end":
              return _context14.stop();
          }
        }, _callee14);
      })));
    });
    describe('formatValue prop', function () {
      it('should display formatted value in tooltip when formatValue is provided', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee15() {
        var onChange, formatPercentage, props, _render14, driver;
        return _regenerator["default"].wrap(function _callee15$(_context15) {
          while (1) switch (_context15.prev = _context15.next) {
            case 0:
              onChange = vi.fn();
              formatPercentage = function formatPercentage(value) {
                return "".concat(value, "%");
              };
              props = {
                value: 50,
                min: 0,
                max: 100,
                onChange: onChange,
                formatValue: formatPercentage
              };
              _render14 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 206,
                  columnNumber: 35
                }
              }))), driver = _render14.driver;
              _context15.t0 = expect;
              _context15.next = 7;
              return driver.getToolTipValue(0);
            case 7:
              _context15.t1 = _context15.sent;
              (0, _context15.t0)(_context15.t1).toBe('50%');
            case 9:
            case "end":
              return _context15.stop();
          }
        }, _callee15);
      })));
      it('should prioritize custom marks label over formatValue', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16() {
        var onChange, formatPercentage, marks, props, _render15, driver;
        return _regenerator["default"].wrap(function _callee16$(_context16) {
          while (1) switch (_context16.prev = _context16.next) {
            case 0:
              onChange = vi.fn();
              formatPercentage = function formatPercentage(value) {
                return "".concat(value, "%");
              };
              marks = {
                10: 'Special Price!',
                20: '$20'
              };
              props = {
                value: 10,
                min: 0,
                max: 100,
                onChange: onChange,
                marks: marks,
                formatValue: formatPercentage
              };
              _render15 = render(/*#__PURE__*/_react["default"].createElement(_Slider["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 228,
                  columnNumber: 35
                }
              }))), driver = _render15.driver;
              _context16.t0 = expect;
              _context16.next = 8;
              return driver.getToolTipValue(0);
            case 8:
              _context16.t1 = _context16.sent;
              (0, _context16.t0)(_context16.t1).toBe('Special Price!');
              _context16.t2 = expect;
              _context16.next = 13;
              return driver.getToolTipValue(0);
            case 13:
              _context16.t3 = _context16.sent;
              (0, _context16.t2)(_context16.t3).not.toBe('10%');
            case 15:
            case "end":
              return _context16.stop();
          }
        }, _callee16);
      })));
    });
  }
});