import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/StarsRatingBar/test/StarsRatingBar.spec.jsx",
  _this = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { act } from 'react';
import { createRendererWithUniDriver, cleanup } from '../../utils/test-utils/unit';
import StarsRatingBar from '../StarsRatingBar';
import { starsRatingBarPrivateDriverFactory } from './StarsRatingBar.private.uni.driver';
describe(StarsRatingBar.displayName, function () {
  var render = createRendererWithUniDriver(starsRatingBarPrivateDriverFactory);
  afterEach(cleanup);
  it('should render stars rating bar', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var _render, driver;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _render = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
            value: 1,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 19,
              columnNumber: 31
            }
          })), driver = _render.driver;
          _context.t0 = expect;
          _context.next = 4;
          return driver.exists();
        case 4:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  it('should show correct value on interactive mode', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var ratingValue, _render2, driver;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          ratingValue = 2;
          _render2 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
            value: ratingValue,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 26,
              columnNumber: 31
            }
          })), driver = _render2.driver;
          _context2.t0 = expect;
          _context2.next = 5;
          return driver.getSelectedRating();
        case 5:
          _context2.t1 = _context2.sent;
          (0, _context2.t0)(_context2.t1).toEqual(ratingValue);
        case 7:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('should show correct value on readOnly mode', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var ratingValue, _render3, driver;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          ratingValue = 2;
          _render3 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
            value: ratingValue,
            readOnly: true,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 33,
              columnNumber: 31
            }
          })), driver = _render3.driver;
          _context3.t0 = expect;
          _context3.next = 5;
          return driver.getSelectedRating();
        case 5:
          _context3.t1 = _context3.sent;
          (0, _context3.t0)(_context3.t1).toEqual(ratingValue);
        case 7:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  describe('rate caption', function () {
    it.each([{
      index: 1,
      text: 'bad'
    }, {
      index: 2,
      text: 'not good'
    }, {
      index: 3,
      text: 'ok'
    }, {
      index: 4,
      text: 'good'
    }, {
      index: 5,
      text: 'excellent'
    }])('should display the correct rate caption', /*#__PURE__*/function () {
      var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(rateCaption) {
        var descriptionValues, _render4, driver;
        return _regeneratorRuntime.wrap(function _callee4$(_context4) {
          while (1) switch (_context4.prev = _context4.next) {
            case 0:
              descriptionValues = ['bad', 'not good', 'ok', 'good', 'excellent'];
              _render4 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
                value: rateCaption.index,
                descriptionValues: descriptionValues,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 48,
                  columnNumber: 9
                }
              })), driver = _render4.driver;
              _context4.t0 = expect;
              _context4.next = 5;
              return driver.getDisplayedRateCaptionLabel();
            case 5:
              _context4.t1 = _context4.sent;
              (0, _context4.t0)(_context4.t1).toEqual(rateCaption.text);
            case 7:
            case "end":
              return _context4.stop();
          }
        }, _callee4);
      }));
      return function (_x) {
        return _ref4.apply(this, arguments);
      };
    }());
    it('should not display a rate caption', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
      var _render5, driver;
      return _regeneratorRuntime.wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _render5 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
              value: 2,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 60,
                columnNumber: 33
              }
            })), driver = _render5.driver;
            _context5.t0 = expect;
            _context5.next = 4;
            return driver.isRatingCaptionExists();
          case 4:
            _context5.t1 = _context5.sent;
            (0, _context5.t0)(_context5.t1).toBe(false);
          case 6:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
  });
  it('expect onChange to be called after selecting a rating', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var onChange, _render6, driver;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          onChange = vi.fn();
          _render6 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
            value: 0,
            onChange: onChange,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 68,
              columnNumber: 31
            }
          })), driver = _render6.driver;
          _context6.t0 = expect;
          _context6.next = 5;
          return driver.getSelectedRating();
        case 5:
          _context6.t1 = _context6.sent;
          (0, _context6.t0)(_context6.t1).toEqual(0);
          _context6.next = 9;
          return driver.selectRating(4);
        case 9:
          expect(onChange).toHaveBeenCalledTimes(1);
          expect(onChange).toHaveBeenCalledWith(4);
        case 11:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })));
  describe('hover', function () {
    it('should show correct value on hover', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
      var _render7, driver;
      return _regeneratorRuntime.wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            _render7 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
              value: 0,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 79,
                columnNumber: 33
              }
            })), driver = _render7.driver;
            _context7.t0 = expect;
            _context7.next = 4;
            return driver.getSelectedRating();
          case 4:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toEqual(0);
            _context7.next = 8;
            return driver.hoverOnStar(3);
          case 8:
            _context7.t2 = expect;
            _context7.next = 11;
            return driver.getSelectedRating();
          case 11:
            _context7.t3 = _context7.sent;
            (0, _context7.t2)(_context7.t3).toEqual(3);
          case 13:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    var descriptionEntries = [{
      index: 1,
      text: 'bad'
    }, {
      index: 2,
      text: 'not good'
    }, {
      index: 3,
      text: 'ok'
    }, {
      index: 4,
      text: 'good'
    }, {
      index: 5,
      text: 'excellent'
    }];
    var descriptionTexts = descriptionEntries.map(function (_ref8) {
      var text = _ref8.text;
      return text;
    });
    it.each(descriptionEntries)('should display the rate caption of the hovered star', /*#__PURE__*/function () {
      var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(rateCaption) {
        var _render8, driver;
        return _regeneratorRuntime.wrap(function _callee8$(_context8) {
          while (1) switch (_context8.prev = _context8.next) {
            case 0:
              _render8 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
                value: 3,
                descriptionValues: descriptionTexts,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 101,
                  columnNumber: 11
                }
              })), driver = _render8.driver;
              _context8.t0 = expect;
              _context8.next = 4;
              return driver.getSelectedRating();
            case 4:
              _context8.t1 = _context8.sent;
              (0, _context8.t0)(_context8.t1).toEqual(3);
              _context8.next = 8;
              return driver.hoverOnStar(rateCaption.index);
            case 8:
              _context8.t2 = expect;
              _context8.next = 11;
              return driver.getDisplayedRateCaptionLabel();
            case 11:
              _context8.t3 = _context8.sent;
              (0, _context8.t2)(_context8.t3).toEqual(rateCaption.text);
            case 13:
            case "end":
              return _context8.stop();
          }
        }, _callee8);
      }));
      return function (_x2) {
        return _ref9.apply(this, arguments);
      };
    }());
  });
  describe('labels', function () {
    var labelEntries = [{
      index: 1,
      text: 'one star'
    }, {
      index: 2,
      text: 'two stars'
    }, {
      index: 3,
      text: 'three stars'
    }, {
      index: 4,
      text: 'four stars'
    }, {
      index: 5,
      text: 'five stars'
    }];
    var labelTexts = labelEntries.map(function (_ref0) {
      var text = _ref0.text;
      return text;
    });
    it.each(labelEntries)('should have the correct label text', /*#__PURE__*/function () {
      var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(labelEntry) {
        var _render9, driver;
        return _regeneratorRuntime.wrap(function _callee9$(_context9) {
          while (1) switch (_context9.prev = _context9.next) {
            case 0:
              _render9 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
                value: 3,
                labelValues: labelTexts,
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 129,
                  columnNumber: 11
                }
              })), driver = _render9.driver;
              _context9.t0 = expect;
              _context9.next = 4;
              return driver.getOptionLabel(labelEntry.index);
            case 4:
              _context9.t1 = _context9.sent;
              (0, _context9.t0)(_context9.t1).toEqual(labelEntry.text);
            case 6:
            case "end":
              return _context9.stop();
          }
        }, _callee9);
      }));
      return function (_x3) {
        return _ref1.apply(this, arguments);
      };
    }());
  });
  describe('focus', function () {
    it('should focus first star through ref, when value is 0', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() {
      var ref, _render0, driver;
      return _regeneratorRuntime.wrap(function _callee1$(_context1) {
        while (1) switch (_context1.prev = _context1.next) {
          case 0:
            ref = /*#__PURE__*/React.createRef();
            _render0 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
              ref: ref,
              value: 0,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 142,
                columnNumber: 33
              }
            })), driver = _render0.driver;
            expect(ref.current).toBeTruthy();
            _context1.t0 = expect;
            _context1.next = 6;
            return driver.isInputFocused(1);
          case 6:
            _context1.t1 = _context1.sent;
            (0, _context1.t0)(_context1.t1).toBe(false);
            _context1.next = 10;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() {
              return _regeneratorRuntime.wrap(function _callee0$(_context0) {
                while (1) switch (_context0.prev = _context0.next) {
                  case 0:
                    ref.current.focus();
                  case 1:
                  case "end":
                    return _context0.stop();
                }
              }, _callee0);
            })));
          case 10:
            _context1.t2 = expect;
            _context1.next = 13;
            return driver.isInputFocused(1);
          case 13:
            _context1.t3 = _context1.sent;
            (0, _context1.t2)(_context1.t3).toBe(true);
          case 15:
          case "end":
            return _context1.stop();
        }
      }, _callee1);
    })));
    it('should focus selected star through ref, when value is set', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
      var ref, randomValue, _render1, driver;
      return _regeneratorRuntime.wrap(function _callee11$(_context11) {
        while (1) switch (_context11.prev = _context11.next) {
          case 0:
            ref = /*#__PURE__*/React.createRef();
            randomValue = Math.floor(Math.random() * 5) + 1;
            _render1 = render(/*#__PURE__*/React.createElement(StarsRatingBar, {
              ref: ref,
              value: randomValue,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 157,
                columnNumber: 9
              }
            })), driver = _render1.driver;
            expect(ref.current).toBeTruthy();
            _context11.t0 = expect;
            _context11.next = 7;
            return driver.isInputFocused(randomValue);
          case 7:
            _context11.t1 = _context11.sent;
            (0, _context11.t0)(_context11.t1).toBe(false);
            _context11.next = 11;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
              return _regeneratorRuntime.wrap(function _callee10$(_context10) {
                while (1) switch (_context10.prev = _context10.next) {
                  case 0:
                    ref.current.focus();
                  case 1:
                  case "end":
                    return _context10.stop();
                }
              }, _callee10);
            })));
          case 11:
            _context11.t2 = expect;
            _context11.next = 14;
            return driver.isInputFocused(randomValue);
          case 14:
            _context11.t3 = _context11.sent;
            (0, _context11.t2)(_context11.t3).toBe(true);
          case 16:
          case "end":
            return _context11.stop();
        }
      }, _callee11);
    })));
    it('should call onFocus callback', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
      var focusableOnFocus, ref;
      return _regeneratorRuntime.wrap(function _callee13$(_context13) {
        while (1) switch (_context13.prev = _context13.next) {
          case 0:
            focusableOnFocus = vi.fn();
            ref = /*#__PURE__*/React.createRef();
            render(/*#__PURE__*/React.createElement(StarsRatingBar, {
              ref: ref,
              value: 0,
              onFocus: focusableOnFocus,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 173,
                columnNumber: 14
              }
            }));
            _context13.next = 5;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
              return _regeneratorRuntime.wrap(function _callee12$(_context12) {
                while (1) switch (_context12.prev = _context12.next) {
                  case 0:
                    ref.current.focus();
                  case 1:
                  case "end":
                    return _context12.stop();
                }
              }, _callee12);
            })));
          case 5:
            expect(focusableOnFocus).toHaveBeenCalled();
          case 6:
          case "end":
            return _context13.stop();
        }
      }, _callee13);
    })));
  });
});