"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _react2 = require("../../utils/test-utils/react");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _SegmentedToggle = _interopRequireDefault(require("../SegmentedToggle"));
var _SegmentedToggleUni = require("../SegmentedToggle.uni.driver");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/SegmentedToggle/test/SegmentedToggle.spec.jsx",
  _this = void 0;
describe('SegmentedToggle', function () {
  var dataHook1 = 'clicked-button1';
  var dataHook2 = 'clicked-button2';
  var render = (0, _react2.createRendererWithUniDriver)(_SegmentedToggleUni.segmentedToggleDriverFactory);
  var SegmentedButton = function SegmentedButton(props) {
    return /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"], (0, _extends2["default"])({}, props, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 18,
        columnNumber: 5
      }
    }), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
      dataHook: dataHook1,
      value: "short",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 19,
        columnNumber: 7
      }
    }, "Short"), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
      dataHook: dataHook2,
      value: "long",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 22,
        columnNumber: 7
      }
    }, "Long"));
  };
  var SegmentedIcon = function SegmentedIcon(props) {
    return /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"], (0, _extends2["default"])({}, props, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 29,
        columnNumber: 5
      }
    }), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Icon, {
      dataHook: dataHook1,
      value: "short",
      title: "Locked",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 30,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react["default"].createElement(_wixUiIconsCommon.LockLocked, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 31,
        columnNumber: 9
      }
    })), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Icon, {
      dataHook: dataHook2,
      value: "long",
      title: "Locked",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 33,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react["default"].createElement(_wixUiIconsCommon.LockLocked, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 34,
        columnNumber: 9
      }
    })));
  };
  it('`onClick` handler should return selected value for Button ', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
    var onClick, _render, driver;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          onClick = vi.fn();
          _render = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            onClick: onClick,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 42,
              columnNumber: 31
            }
          })), driver = _render.driver;
          _context.next = 4;
          return driver.selectChild(2);
        case 4:
          expect(onClick).toHaveBeenCalledTimes(1);
          expect(onClick.mock.calls[0][1]).toBe('long');
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  it('`onClick` handler should return selected value for Icon ', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
    var onClick, _render2, driver;
    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          onClick = vi.fn();
          _render2 = render(/*#__PURE__*/_react["default"].createElement(SegmentedIcon, {
            onClick: onClick,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 52,
              columnNumber: 31
            }
          })), driver = _render2.driver;
          _context2.next = 4;
          return driver.selectChild(2);
        case 4:
          expect(onClick).toHaveBeenCalledTimes(1);
          expect(onClick.mock.calls[0][1]).toBe('long');
        case 6:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('`selected` prop should disallow selecting other items', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
    var selected, _render3, driver;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          selected = 'short';
          _render3 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            selected: selected,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 62,
              columnNumber: 31
            }
          })), driver = _render3.driver;
          _context3.next = 4;
          return driver.selectChild(2);
        case 4:
          _context3.t0 = expect;
          _context3.next = 7;
          return driver.isSelected(dataHook1);
        case 7:
          _context3.t1 = _context3.sent;
          (0, _context3.t0)(_context3.t1).toBe(true);
        case 9:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  it('`size` prop should allow setting size `small`', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
    var _render4, driver;
    return _regenerator["default"].wrap(function _callee4$(_context4) {
      while (1) switch (_context4.prev = _context4.next) {
        case 0:
          _render4 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            size: "small",
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 69,
              columnNumber: 31
            }
          })), driver = _render4.driver;
          _context4.t0 = expect;
          _context4.next = 4;
          return driver.getSize();
        case 4:
          _context4.t1 = _context4.sent;
          (0, _context4.t0)(_context4.t1).toBe('small');
        case 6:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })));
  it('should have `medium` size by default', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
    var _render5, driver;
    return _regenerator["default"].wrap(function _callee5$(_context5) {
      while (1) switch (_context5.prev = _context5.next) {
        case 0:
          _render5 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 75,
              columnNumber: 31
            }
          })), driver = _render5.driver;
          _context5.t0 = expect;
          _context5.next = 4;
          return driver.getSize();
        case 4:
          _context5.t1 = _context5.sent;
          (0, _context5.t0)(_context5.t1).toBe('medium');
        case 6:
        case "end":
          return _context5.stop();
      }
    }, _callee5);
  })));
  it('should be enabled by default (button)', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
    var _render6, driver;
    return _regenerator["default"].wrap(function _callee6$(_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          _render6 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 81,
              columnNumber: 31
            }
          })), driver = _render6.driver;
          _context6.t0 = expect;
          _context6.next = 4;
          return driver.isDisabled();
        case 4:
          _context6.t1 = _context6.sent;
          (0, _context6.t0)(_context6.t1).toBe(false);
        case 6:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })));
  it('should be enabled by default (icon)', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
    var _render7, driver;
    return _regenerator["default"].wrap(function _callee7$(_context7) {
      while (1) switch (_context7.prev = _context7.next) {
        case 0:
          _render7 = render(/*#__PURE__*/_react["default"].createElement(SegmentedIcon, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 87,
              columnNumber: 31
            }
          })), driver = _render7.driver;
          _context7.t0 = expect;
          _context7.next = 4;
          return driver.isDisabled();
        case 4:
          _context7.t1 = _context7.sent;
          (0, _context7.t0)(_context7.t1).toBe(false);
        case 6:
        case "end":
          return _context7.stop();
      }
    }, _callee7);
  })));
  it('should be disabled when `disabled` prop is set (button)', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
    var _render8, driver;
    return _regenerator["default"].wrap(function _callee8$(_context8) {
      while (1) switch (_context8.prev = _context8.next) {
        case 0:
          _render8 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            disabled: true,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 93,
              columnNumber: 31
            }
          })), driver = _render8.driver;
          _context8.t0 = expect;
          _context8.next = 4;
          return driver.isDisabled();
        case 4:
          _context8.t1 = _context8.sent;
          (0, _context8.t0)(_context8.t1).toBe(true);
        case 6:
        case "end":
          return _context8.stop();
      }
    }, _callee8);
  })));
  it('should be disabled when `disabled` prop is set (icon)', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9() {
    var _render9, driver;
    return _regenerator["default"].wrap(function _callee9$(_context9) {
      while (1) switch (_context9.prev = _context9.next) {
        case 0:
          _render9 = render(/*#__PURE__*/_react["default"].createElement(SegmentedIcon, {
            disabled: true,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 99,
              columnNumber: 31
            }
          })), driver = _render9.driver;
          _context9.t0 = expect;
          _context9.next = 4;
          return driver.isDisabled();
        case 4:
          _context9.t1 = _context9.sent;
          (0, _context9.t0)(_context9.t1).toBe(true);
        case 6:
        case "end":
          return _context9.stop();
      }
    }, _callee9);
  })));
  it('has `radiogroup` role', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0() {
    return _regenerator["default"].wrap(function _callee0$(_context0) {
      while (1) switch (_context0.prev = _context0.next) {
        case 0:
          render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 105,
              columnNumber: 12
            }
          }));
          expect(_react2.screen.getByRole('radiogroup')).toBeTruthy();
          expect(_react2.screen.getAllByRole('radio')).toHaveLength(2);
        case 3:
        case "end":
          return _context0.stop();
      }
    }, _callee0);
  })));
  it('sets `aria-label`', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1() {
    return _regenerator["default"].wrap(function _callee1$(_context1) {
      while (1) switch (_context1.prev = _context1.next) {
        case 0:
          render(/*#__PURE__*/_react["default"].createElement(SegmentedButton, {
            ariaLabel: "Choose length",
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 112,
              columnNumber: 12
            }
          }));
          expect(_react2.screen.getByRole('radiogroup').getAttribute('aria-label')).toBe('Choose length');
        case 2:
        case "end":
          return _context1.stop();
      }
    }, _callee1);
  })));
  it('should allow individual buttons to be disabled', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10() {
    var SegmentedButtonWithDisabled, _render0, driver;
    return _regenerator["default"].wrap(function _callee10$(_context10) {
      while (1) switch (_context10.prev = _context10.next) {
        case 0:
          SegmentedButtonWithDisabled = function SegmentedButtonWithDisabled() {
            return /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"], {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 121,
                columnNumber: 7
              }
            }, /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook1,
              value: "short",
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 122,
                columnNumber: 9
              }
            }, "Short"), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook2,
              value: "long",
              disabled: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 125,
                columnNumber: 9
              }
            }, "Long (Disabled)"));
          };
          _render0 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButtonWithDisabled, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 131,
              columnNumber: 31
            }
          })), driver = _render0.driver;
          _context10.t0 = expect;
          _context10.next = 5;
          return driver.isChildDisabled(dataHook1);
        case 5:
          _context10.t1 = _context10.sent;
          (0, _context10.t0)(_context10.t1).toBe(false);
          _context10.t2 = expect;
          _context10.next = 10;
          return driver.isChildDisabled(dataHook2);
        case 10:
          _context10.t3 = _context10.sent;
          (0, _context10.t2)(_context10.t3).toBe(true);
        case 12:
        case "end":
          return _context10.stop();
      }
    }, _callee10);
  })));
  it('should not trigger onClick for individually disabled buttons', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11() {
    var onClick, SegmentedButtonWithDisabled, _render1, driver;
    return _regenerator["default"].wrap(function _callee11$(_context11) {
      while (1) switch (_context11.prev = _context11.next) {
        case 0:
          onClick = vi.fn();
          SegmentedButtonWithDisabled = function SegmentedButtonWithDisabled() {
            return /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"], {
              onClick: onClick,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 141,
                columnNumber: 7
              }
            }, /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook1,
              value: "short",
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 142,
                columnNumber: 9
              }
            }, "Short"), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook2,
              value: "long",
              disabled: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 145,
                columnNumber: 9
              }
            }, "Long (Disabled)"));
          };
          _render1 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButtonWithDisabled, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 151,
              columnNumber: 31
            }
          })), driver = _render1.driver; // Try to click disabled button - should not trigger onClick
          _context11.next = 5;
          return driver.selectChild(dataHook2);
        case 5:
          expect(onClick).not.toHaveBeenCalled();

          // Click enabled button - should trigger onClick
          _context11.next = 8;
          return driver.selectChild(dataHook1);
        case 8:
          expect(onClick).toHaveBeenCalledTimes(1);
          expect(onClick.mock.calls[0][1]).toBe('short');
        case 10:
        case "end":
          return _context11.stop();
      }
    }, _callee11);
  })));
  it('should disable individual buttons when both global and individual disabled are set', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12() {
    var SegmentedButtonWithBothDisabled, _render10, driver;
    return _regenerator["default"].wrap(function _callee12$(_context12) {
      while (1) switch (_context12.prev = _context12.next) {
        case 0:
          SegmentedButtonWithBothDisabled = function SegmentedButtonWithBothDisabled() {
            return /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"], {
              disabled: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 165,
                columnNumber: 7
              }
            }, /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook1,
              value: "short",
              disabled: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 166,
                columnNumber: 9
              }
            }, "Short (Individual + Global Disabled)"), /*#__PURE__*/_react["default"].createElement(_SegmentedToggle["default"].Button, {
              dataHook: dataHook2,
              value: "long",
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 169,
                columnNumber: 9
              }
            }, "Long (Global Disabled)"));
          };
          _render10 = render(/*#__PURE__*/_react["default"].createElement(SegmentedButtonWithBothDisabled, {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 175,
              columnNumber: 31
            }
          })), driver = _render10.driver;
          _context12.t0 = expect;
          _context12.next = 5;
          return driver.isChildDisabled(dataHook1);
        case 5:
          _context12.t1 = _context12.sent;
          (0, _context12.t0)(_context12.t1).toBe(true);
          _context12.t2 = expect;
          _context12.next = 10;
          return driver.isChildDisabled(dataHook2);
        case 10:
          _context12.t3 = _context12.sent;
          (0, _context12.t2)(_context12.t3).toBe(true);
        case 12:
        case "end":
          return _context12.stop();
      }
    }, _callee12);
  })));
});