"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 _unit = require("../../utils/test-utils/unit");
var _SelectableAccordion = _interopRequireDefault(require("../SelectableAccordion"));
var _SelectableAccordionPrivateUni = require("./SelectableAccordion.private.uni.driver");
var _constants = require("../constants");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/SelectableAccordion/test/SelectableAccordion.spec.jsx",
  _this = void 0;
describe(_SelectableAccordion["default"].displayName, function () {
  var render = (0, _unit.createRendererWithUniDriver)(_SelectableAccordionPrivateUni.selectableAccordionPrivateDriverFactory);
  var items = [{
    title: 'Title1',
    content: 'Content1'
  }, {
    title: 'Title2',
    content: 'Content2'
  }, {
    title: 'Title3',
    content: 'Content3'
  }];
  afterEach(_unit.cleanup);
  it('should render', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
    var _render, driver;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _render = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 26,
              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 render all items', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
    var _render2, driver;
    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          _render2 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            items: items,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 32,
              columnNumber: 31
            }
          })), driver = _render2.driver;
          _context2.t0 = expect;
          _context2.next = 4;
          return driver.getItemsCount();
        case 4:
          _context2.t1 = _context2.sent;
          (0, _context2.t0)(_context2.t1).toBe(3);
        case 6:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('should dynamically rerender items', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
    var _render3, driver, rerender;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) switch (_context3.prev = _context3.next) {
        case 0:
          _render3 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            items: items,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 38,
              columnNumber: 41
            }
          })), driver = _render3.driver, rerender = _render3.rerender;
          _context3.t0 = expect;
          _context3.next = 4;
          return driver.getItemsCount();
        case 4:
          _context3.t1 = _context3.sent;
          (0, _context3.t0)(_context3.t1).toBe(3);
          rerender(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            items: [{
              title: 'Title1',
              content: 'Content1'
            }, {
              title: 'Title2',
              content: 'Content2'
            }],
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 43,
              columnNumber: 7
            }
          }));
          _context3.t2 = expect;
          _context3.next = 10;
          return driver.getItemsCount();
        case 10:
          _context3.t3 = _context3.sent;
          (0, _context3.t2)(_context3.t3).toBe(2);
        case 12:
        case "end":
          return _context3.stop();
      }
    }, _callee3);
  })));
  it('should initially open relevant items', /*#__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(_SelectableAccordion["default"], {
            items: [{
              title: 'Title1',
              content: 'Content1'
            }, {
              title: 'Title2',
              content: 'Content2',
              initiallyOpen: true
            }, {
              title: 'Title3',
              content: 'Content3'
            }],
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 56,
              columnNumber: 7
            }
          })), driver = _render4.driver;
          _context4.t0 = expect;
          _context4.next = 4;
          return driver.isItemExpandedAt(0);
        case 4:
          _context4.t1 = _context4.sent;
          (0, _context4.t0)(_context4.t1).toBe(false);
          _context4.t2 = expect;
          _context4.next = 9;
          return driver.isItemExpandedAt(1);
        case 9:
          _context4.t3 = _context4.sent;
          (0, _context4.t2)(_context4.t3).toBe(true);
          _context4.t4 = expect;
          _context4.next = 14;
          return driver.isItemExpandedAt(2);
        case 14:
          _context4.t5 = _context4.sent;
          (0, _context4.t4)(_context4.t5).toBe(false);
        case 16:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })));
  it('should be controllable with `open` prop', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
    var _render5, driver, rerender;
    return _regenerator["default"].wrap(function _callee5$(_context5) {
      while (1) switch (_context5.prev = _context5.next) {
        case 0:
          _render5 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            items: [{
              title: 'Title1',
              content: 'Content1'
            }, {
              title: 'Title2',
              content: 'Content2',
              open: true
            }, {
              title: 'Title3',
              content: 'Content3'
            }],
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 72,
              columnNumber: 7
            }
          })), driver = _render5.driver, rerender = _render5.rerender;
          _context5.t0 = expect;
          _context5.next = 4;
          return driver.isItemExpandedAt(0);
        case 4:
          _context5.t1 = _context5.sent;
          (0, _context5.t0)(_context5.t1).toBe(false);
          _context5.t2 = expect;
          _context5.next = 9;
          return driver.isItemExpandedAt(1);
        case 9:
          _context5.t3 = _context5.sent;
          (0, _context5.t2)(_context5.t3).toBe(true);
          _context5.t4 = expect;
          _context5.next = 14;
          return driver.isItemExpandedAt(2);
        case 14:
          _context5.t5 = _context5.sent;
          (0, _context5.t4)(_context5.t5).toBe(false);
          rerender(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            items: [{
              title: 'Title1',
              content: 'Content1',
              open: true
            }, {
              title: 'Title2',
              content: 'Content2'
            }, {
              title: 'Title3',
              content: 'Content3'
            }],
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 86,
              columnNumber: 7
            }
          }));
          _context5.t6 = expect;
          _context5.next = 20;
          return driver.isItemExpandedAt(0);
        case 20:
          _context5.t7 = _context5.sent;
          (0, _context5.t6)(_context5.t7).toBe(true);
          _context5.t8 = expect;
          _context5.next = 25;
          return driver.isItemExpandedAt(1);
        case 25:
          _context5.t9 = _context5.sent;
          (0, _context5.t8)(_context5.t9).toBe(false);
          _context5.t10 = expect;
          _context5.next = 30;
          return driver.isItemExpandedAt(2);
        case 30:
          _context5.t11 = _context5.sent;
          (0, _context5.t10)(_context5.t11).toBe(false);
        case 32:
        case "end":
          return _context5.stop();
      }
    }, _callee5);
  })));
  it('should execute `onClick` prop when given', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
    var mockedOnClick, _render6, driver;
    return _regenerator["default"].wrap(function _callee6$(_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          mockedOnClick = vi.fn();
          _render6 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
            type: "checkbox",
            items: [{
              title: 'Title1',
              content: 'Content1',
              onClick: mockedOnClick,
              initiallyOpen: false
            }, {
              title: 'Title2',
              content: 'Content2',
              onClick: mockedOnClick,
              initiallyOpen: true
            }],
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 103,
              columnNumber: 7
            }
          })), driver = _render6.driver;
          _context6.next = 4;
          return driver.clickItemAt(0);
        case 4:
          expect(mockedOnClick).toHaveBeenCalledWith(expect.anything(), {
            open: true
          });
          _context6.next = 7;
          return driver.clickItemAt(1);
        case 7:
          expect(mockedOnClick).toHaveBeenCalledWith(expect.anything(), {
            open: false
          });
        case 8:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })));
  describe('disabled items', function () {
    it('should render items as disabled', /*#__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(_SelectableAccordion["default"], {
              items: [{
                title: 'Title1',
                content: 'Content1',
                disabled: true
              }, {
                title: 'Title2',
                content: 'Content2',
                initiallyOpen: true,
                disabled: true
              }],
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 135,
                columnNumber: 9
              }
            })), driver = _render7.driver;
            _context7.t0 = expect;
            _context7.next = 4;
            return driver.isItemDisabledAt(0);
          case 4:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toBe(true);
            _context7.t2 = expect;
            _context7.next = 9;
            return driver.isItemDisabledAt(1);
          case 9:
            _context7.t3 = _context7.sent;
            (0, _context7.t2)(_context7.t3).toBe(true);
          case 11:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    it('should not call change callback', /*#__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();
            _render8 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], {
              onSelectionChanged: onChange,
              items: [{
                title: 'Title1',
                content: 'Content1',
                disabled: true
              }, {
                title: 'Title2',
                content: 'Content2',
                initiallyOpen: true,
                disabled: true
              }],
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 155,
                columnNumber: 9
              }
            })), driver = _render8.driver;
            _context8.next = 4;
            return driver.clickItemAt(0);
          case 4:
            expect(onChange).not.toHaveBeenCalled();
          case 5:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
  });
  describe('Type Radio', function () {
    var props = {
      type: _constants.TYPES.RADIO,
      items: items
    };
    it('should open item', /*#__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(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 182,
                columnNumber: 33
              }
            }))), driver = _render9.driver;
            _context9.t0 = expect;
            _context9.next = 4;
            return driver.isItemExpandedAt(0);
          case 4:
            _context9.t1 = _context9.sent;
            (0, _context9.t0)(_context9.t1).toBe(false);
            _context9.next = 8;
            return driver.clickItemAt(0);
          case 8:
            _context9.t2 = expect;
            _context9.next = 11;
            return driver.isItemExpandedAt(0);
          case 11:
            _context9.t3 = _context9.sent;
            (0, _context9.t2)(_context9.t3).toBe(true);
          case 13:
          case "end":
            return _context9.stop();
        }
      }, _callee9);
    })));
    it('should not close open item', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0() {
      var _render0, driver;
      return _regenerator["default"].wrap(function _callee0$(_context0) {
        while (1) switch (_context0.prev = _context0.next) {
          case 0:
            _render0 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 190,
                columnNumber: 33
              }
            }))), driver = _render0.driver;
            _context0.next = 3;
            return driver.clickItemAt(0);
          case 3:
            _context0.t0 = expect;
            _context0.next = 6;
            return driver.isItemExpandedAt(0);
          case 6:
            _context0.t1 = _context0.sent;
            (0, _context0.t0)(_context0.t1).toBe(true);
            _context0.next = 10;
            return driver.clickItemAt(0);
          case 10:
            _context0.t2 = expect;
            _context0.next = 13;
            return driver.isItemExpandedAt(0);
          case 13:
            _context0.t3 = _context0.sent;
            (0, _context0.t2)(_context0.t3).toBe(true);
          case 15:
          case "end":
            return _context0.stop();
        }
      }, _callee0);
    })));
    it('should close previously open item', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1() {
      var _render1, driver;
      return _regenerator["default"].wrap(function _callee1$(_context1) {
        while (1) switch (_context1.prev = _context1.next) {
          case 0:
            _render1 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 199,
                columnNumber: 33
              }
            }))), driver = _render1.driver;
            _context1.next = 3;
            return driver.clickItemAt(0);
          case 3:
            _context1.t0 = expect;
            _context1.next = 6;
            return driver.isItemExpandedAt(0);
          case 6:
            _context1.t1 = _context1.sent;
            (0, _context1.t0)(_context1.t1).toBe(true);
            _context1.next = 10;
            return driver.clickItemAt(1);
          case 10:
            _context1.t2 = expect;
            _context1.next = 13;
            return driver.isItemExpandedAt(0);
          case 13:
            _context1.t3 = _context1.sent;
            (0, _context1.t2)(_context1.t3).toBe(false);
          case 15:
          case "end":
            return _context1.stop();
        }
      }, _callee1);
    })));
    it('should execute onSelectionChanged callback on item selection with a single open index', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10() {
      var props, _render10, driver;
      return _regenerator["default"].wrap(function _callee10$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            props = {
              onSelectionChanged: vi.fn(),
              items: items
            };
            _render10 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 213,
                columnNumber: 33
              }
            }))), driver = _render10.driver;
            _context10.next = 4;
            return driver.clickItemAt(0);
          case 4:
            expect(props.onSelectionChanged).toHaveBeenCalledWith([0]);
            _context10.next = 7;
            return driver.clickItemAt(1);
          case 7:
            expect(props.onSelectionChanged).toHaveBeenCalledWith([1]);
          case 8:
          case "end":
            return _context10.stop();
        }
      }, _callee10);
    })));
  });
  [_constants.TYPES.TOGGLE, _constants.TYPES.CHECKBOX].forEach(function (type) {
    describe("Type ".concat(type), function () {
      var props = {
        items: items,
        type: type
      };
      it('should open item', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11() {
        var _render11, driver;
        return _regenerator["default"].wrap(function _callee11$(_context11) {
          while (1) switch (_context11.prev = _context11.next) {
            case 0:
              _render11 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 227,
                  columnNumber: 35
                }
              }))), driver = _render11.driver;
              _context11.t0 = expect;
              _context11.next = 4;
              return driver.isItemExpandedAt(0);
            case 4:
              _context11.t1 = _context11.sent;
              (0, _context11.t0)(_context11.t1).toBe(false);
              _context11.next = 8;
              return driver.clickItemAt(0);
            case 8:
              _context11.t2 = expect;
              _context11.next = 11;
              return driver.isItemExpandedAt(0);
            case 11:
              _context11.t3 = _context11.sent;
              (0, _context11.t2)(_context11.t3).toBe(true);
            case 13:
            case "end":
              return _context11.stop();
          }
        }, _callee11);
      })));
      it('should close item', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12() {
        var _render12, driver;
        return _regenerator["default"].wrap(function _callee12$(_context12) {
          while (1) switch (_context12.prev = _context12.next) {
            case 0:
              _render12 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 235,
                  columnNumber: 35
                }
              }))), driver = _render12.driver;
              _context12.next = 3;
              return driver.clickItemAt(0);
            case 3:
              _context12.t0 = expect;
              _context12.next = 6;
              return driver.isItemExpandedAt(0);
            case 6:
              _context12.t1 = _context12.sent;
              (0, _context12.t0)(_context12.t1).toBe(true);
              _context12.next = 10;
              return driver.clickItemAt(0);
            case 10:
              _context12.t2 = expect;
              _context12.next = 13;
              return driver.isItemExpandedAt(0);
            case 13:
              _context12.t3 = _context12.sent;
              (0, _context12.t2)(_context12.t3).toBe(false);
            case 15:
            case "end":
              return _context12.stop();
          }
        }, _callee12);
      })));
      it('should open multiple items', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee13() {
        var _render13, driver;
        return _regenerator["default"].wrap(function _callee13$(_context13) {
          while (1) switch (_context13.prev = _context13.next) {
            case 0:
              _render13 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 244,
                  columnNumber: 35
                }
              }))), driver = _render13.driver;
              _context13.next = 3;
              return driver.clickItemAt(0);
            case 3:
              _context13.t0 = expect;
              _context13.next = 6;
              return driver.isItemExpandedAt(0);
            case 6:
              _context13.t1 = _context13.sent;
              (0, _context13.t0)(_context13.t1).toBe(true);
              _context13.next = 10;
              return driver.clickItemAt(1);
            case 10:
              _context13.t2 = expect;
              _context13.next = 13;
              return driver.isItemExpandedAt(0);
            case 13:
              _context13.t3 = _context13.sent;
              (0, _context13.t2)(_context13.t3).toBe(true);
              _context13.t4 = expect;
              _context13.next = 18;
              return driver.isItemExpandedAt(1);
            case 18:
              _context13.t5 = _context13.sent;
              (0, _context13.t4)(_context13.t5).toBe(true);
            case 20:
            case "end":
              return _context13.stop();
          }
        }, _callee13);
      })));
      it('should execute onSelectionChanged callback on item selection with multiple open indices', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee14() {
        var props, _render14, driver;
        return _regenerator["default"].wrap(function _callee14$(_context14) {
          while (1) switch (_context14.prev = _context14.next) {
            case 0:
              props = {
                onSelectionChanged: vi.fn(),
                items: items,
                type: type
              };
              _render14 = render(/*#__PURE__*/_react["default"].createElement(_SelectableAccordion["default"], (0, _extends2["default"])({}, props, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 260,
                  columnNumber: 35
                }
              }))), driver = _render14.driver;
              _context14.next = 4;
              return driver.clickItemAt(0);
            case 4:
              expect(props.onSelectionChanged).toHaveBeenCalledWith([0]);
              _context14.next = 7;
              return driver.clickItemAt(1);
            case 7:
              expect(props.onSelectionChanged).toHaveBeenCalledWith([0, 1]);
              _context14.next = 10;
              return driver.clickItemAt(0);
            case 10:
              expect(props.onSelectionChanged).toHaveBeenCalledWith([0]);
            case 11:
            case "end":
              return _context14.stop();
          }
        }, _callee14);
      })));
    });
  });
});