import _extends from "@babel/runtime/helpers/extends";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/EditableSelector/test/EditableSelector.spec.jsx";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import EditableSelector from '..';
import { createRendererWithUniDriver } from '../../utils/test-utils/react';
import { editableSelectorPrivateUniDriverFactory } from './EditableSelector.private.uni.driver';
describe('EditableSelector', function () {
  describe('[async]', function () {
    runTests(createRendererWithUniDriver(editableSelectorPrivateUniDriverFactory));
  });
  function runTests(render) {
    var _this = this;
    var props;
    var createDriver = function createDriver(jsx) {
      return render(jsx).driver;
    };
    beforeEach(function () {
      props = {};
    });
    it('should have a list of selectors', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            props.options = [{
              title: 'a'
            }, {
              title: 'b'
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 24,
                columnNumber: 35
              }
            })));
            _context.t0 = expect;
            _context.next = 5;
            return driver.items();
          case 5:
            _context.t1 = _context.sent;
            (0, _context.t0)(_context.t1).toHaveLength(props.options.length);
          case 7:
          case "end":
            return _context.stop();
        }
      }, _callee);
    })));
    it('should have all selector data ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
      var driver, selector;
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            props.options = [{
              isSelected: true,
              title: 'Shir',
              onToggle: function onToggle() {}
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 30,
                columnNumber: 35
              }
            })));
            _context2.next = 4;
            return driver.items();
          case 4:
            selector = _context2.sent[0];
            _context2.t0 = expect;
            _context2.next = 8;
            return selector.isChecked();
          case 8:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).toEqual(props.options[0].isSelected);
            _context2.t2 = expect;
            _context2.next = 13;
            return selector.titleTextDriver().getText();
          case 13:
            _context2.t3 = _context2.sent;
            (0, _context2.t2)(_context2.t3).toEqual(props.options[0].title);
          case 15:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it('should render a title', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            props.title = "I'm a Title";
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 40,
                columnNumber: 35
              }
            })));
            _context3.t0 = expect;
            _context3.next = 5;
            return driver.title();
          case 5:
            _context3.t1 = _context3.sent;
            (0, _context3.t0)(_context3.t1).toEqual(props.title);
          case 7:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should render "add row" button', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            props.newRowLabel = 'add new!';
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 46,
                columnNumber: 35
              }
            })));
            _context4.t0 = expect;
            _context4.next = 5;
            return driver.newRowButtonText();
          case 5:
            _context4.t1 = _context4.sent;
            (0, _context4.t0)(_context4.t1).toEqual(props.newRowLabel);
          case 7:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
    it('should call onOptionAdded', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
      var driver, newTitle;
      return _regeneratorRuntime.wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            props.onOptionAdded = vi.fn();
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 52,
                columnNumber: 35
              }
            })));
            newTitle = 'new option';
            _context5.next = 5;
            return driver.addNewRow(newTitle);
          case 5:
            _context5.next = 7;
            return driver.clickApprove();
          case 7:
            expect(props.onOptionAdded).toHaveBeenCalledWith({
              newTitle: newTitle
            });
          case 8:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should exit editing mode after approve click', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
      var driver, label;
      return _regeneratorRuntime.wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 60,
                columnNumber: 35
              }
            })));
            label = 'new option';
            _context6.next = 4;
            return driver.addNewRow(label);
          case 4:
            _context6.next = 6;
            return driver.clickApprove();
          case 6:
            _context6.t0 = expect;
            _context6.next = 9;
            return driver.isEditing();
          case 9:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toEqual(false);
          case 11:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should exit editing mode after cancel click', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
      var driver, label;
      return _regeneratorRuntime.wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 68,
                columnNumber: 35
              }
            })));
            label = 'new option';
            _context7.next = 4;
            return driver.addNewRow(label);
          case 4:
            _context7.next = 6;
            return driver.clickCancel();
          case 6:
            _context7.t0 = expect;
            _context7.next = 9;
            return driver.isEditing();
          case 9:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toEqual(false);
          case 11:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
    it('should have edit and delete actions for each option', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir'
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 77,
                columnNumber: 35
              }
            })));
            _context8.t0 = expect;
            _context8.next = 5;
            return driver.deleteButtonAt(0);
          case 5:
            _context8.t1 = _context8.sent;
            (0, _context8.t0)(_context8.t1).not.toBeUndefined();
            _context8.t2 = expect;
            _context8.next = 10;
            return driver.editButtonAt(0);
          case 10:
            _context8.t3 = _context8.sent;
            (0, _context8.t2)(_context8.t3).not.toBeUndefined();
          case 12:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
    it('should get "edit" button text from props', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee9$(_context9) {
        while (1) switch (_context9.prev = _context9.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir'
            }];
            props.editButtonText = 'Edit Label';
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 85,
                columnNumber: 35
              }
            })));
            _context9.t0 = expect;
            _context9.next = 6;
            return driver.editButtonTextAt(0);
          case 6:
            _context9.t1 = _context9.sent;
            (0, _context9.t0)(_context9.t1).toEqual(props.editButtonText);
          case 8:
          case "end":
            return _context9.stop();
        }
      }, _callee9);
    })));
    it('should call onOptionEdit', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() {
      var driver, newTitle;
      return _regeneratorRuntime.wrap(function _callee0$(_context0) {
        while (1) switch (_context0.prev = _context0.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir',
              onToggle: function onToggle() {}
            }];
            props.onOptionEdit = vi.fn();
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 94,
                columnNumber: 35
              }
            })));
            newTitle = 'yo';
            _context0.next = 6;
            return driver.editRow(0, newTitle);
          case 6:
            _context0.next = 8;
            return driver.clickApprove();
          case 8:
            expect(props.onOptionEdit).toHaveBeenCalledWith({
              newTitle: newTitle,
              index: 0
            });
          case 9:
          case "end":
            return _context0.stop();
        }
      }, _callee0);
    })));
    it('should call onOptionToggle', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee1$(_context1) {
        while (1) switch (_context1.prev = _context1.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir'
            }];
            props.onOptionToggle = vi.fn();
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 104,
                columnNumber: 35
              }
            })));
            _context1.next = 5;
            return driver.toggleItem(0);
          case 5:
            expect(props.onOptionToggle).toHaveBeenCalledTimes(1);
            expect(props.onOptionToggle).toHaveBeenCalledWith(0);
          case 7:
          case "end":
            return _context1.stop();
        }
      }, _callee1);
    })));
    it('should call onOptionDelete', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
      var driver;
      return _regeneratorRuntime.wrap(function _callee10$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir',
              onToggle: function onToggle() {}
            }];
            props.onOptionDelete = vi.fn();
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 115,
                columnNumber: 35
              }
            })));
            _context10.next = 5;
            return driver.deleteRow(0);
          case 5:
            expect(props.onOptionDelete).toHaveBeenCalledWith({
              index: 0
            });
          case 6:
          case "end":
            return _context10.stop();
        }
      }, _callee10);
    })));
    it('should use checkbox toggles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
      var driver, selector;
      return _regeneratorRuntime.wrap(function _callee11$(_context11) {
        while (1) switch (_context11.prev = _context11.next) {
          case 0:
            props.toggleType = 'checkbox';
            props.options = [{
              isSelected: false,
              title: 'Shir'
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 123,
                columnNumber: 35
              }
            })));
            _context11.next = 5;
            return driver.items();
          case 5:
            selector = _context11.sent[0];
            _context11.t0 = expect;
            _context11.next = 9;
            return selector.toggleType();
          case 9:
            _context11.t1 = _context11.sent;
            (0, _context11.t0)(_context11.t1).toEqual(props.toggleType);
          case 11:
          case "end":
            return _context11.stop();
        }
      }, _callee11);
    })));
    it('should use radio toggles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
      var driver, selector;
      return _regeneratorRuntime.wrap(function _callee12$(_context12) {
        while (1) switch (_context12.prev = _context12.next) {
          case 0:
            props.toggleType = 'radio';
            props.options = [{
              isSelected: false,
              title: 'Shir'
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 131,
                columnNumber: 35
              }
            })));
            _context12.next = 5;
            return driver.items();
          case 5:
            selector = _context12.sent[0];
            _context12.t0 = expect;
            _context12.next = 9;
            return selector.toggleType();
          case 9:
            _context12.t1 = _context12.sent;
            (0, _context12.t0)(_context12.t1).toEqual(props.toggleType);
          case 11:
          case "end":
            return _context12.stop();
        }
      }, _callee12);
    })));
    it('should stop edit when click add new row', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
      var driver, newTitle;
      return _regeneratorRuntime.wrap(function _callee13$(_context13) {
        while (1) switch (_context13.prev = _context13.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir',
              onToggle: function onToggle() {}
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 140,
                columnNumber: 35
              }
            })));
            newTitle = 'yo';
            _context13.t0 = expect;
            _context13.next = 6;
            return driver.isEditingRow();
          case 6:
            _context13.t1 = _context13.sent;
            (0, _context13.t0)(_context13.t1).toBe(false);
            _context13.next = 10;
            return driver.startEditing(0, newTitle);
          case 10:
            _context13.t2 = expect;
            _context13.next = 13;
            return driver.isEditingRow();
          case 13:
            _context13.t3 = _context13.sent;
            (0, _context13.t2)(_context13.t3).toBe(true);
            _context13.next = 17;
            return driver.startAdding();
          case 17:
            _context13.t4 = expect;
            _context13.next = 20;
            return driver.isEditingRow();
          case 20:
            _context13.t5 = _context13.sent;
            (0, _context13.t4)(_context13.t5).toBe(false);
            _context13.t6 = expect;
            _context13.next = 25;
            return driver.isAddingRow();
          case 25:
            _context13.t7 = _context13.sent;
            (0, _context13.t6)(_context13.t7).toBe(true);
          case 27:
          case "end":
            return _context13.stop();
        }
      }, _callee13);
    })));
    it('should stop add when click edit row', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
      var driver, newTitle;
      return _regeneratorRuntime.wrap(function _callee14$(_context14) {
        while (1) switch (_context14.prev = _context14.next) {
          case 0:
            props.options = [{
              isSelected: false,
              title: 'Shir',
              onToggle: function onToggle() {}
            }];
            driver = createDriver(/*#__PURE__*/React.createElement(EditableSelector, _extends({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 154,
                columnNumber: 35
              }
            })));
            newTitle = 'yo';
            _context14.next = 5;
            return driver.startAdding();
          case 5:
            _context14.t0 = expect;
            _context14.next = 8;
            return driver.isAddingRow();
          case 8:
            _context14.t1 = _context14.sent;
            (0, _context14.t0)(_context14.t1).toBe(true);
            _context14.next = 12;
            return driver.startEditing(0, newTitle);
          case 12:
            _context14.t2 = expect;
            _context14.next = 15;
            return driver.isEditingRow();
          case 15:
            _context14.t3 = _context14.sent;
            (0, _context14.t2)(_context14.t3).toBe(true);
            _context14.t4 = expect;
            _context14.next = 20;
            return driver.isAddingRow();
          case 20:
            _context14.t5 = _context14.sent;
            (0, _context14.t4)(_context14.t5).toBe(false);
          case 22:
          case "end":
            return _context14.stop();
        }
      }, _callee14);
    })));
  }
});