"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 _react = _interopRequireDefault(require("react"));
var _react2 = require("../../utils/test-utils/react");
var _EditableRow = _interopRequireDefault(require("./EditableRow"));
var _EditableRowUni = require("./EditableRow.uni.driver");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/EditableSelector/EditableRow/EditableRow.spec.jsx";
describe('EditableRow', function () {
  describe('[async]', function () {
    runTests((0, _react2.createRendererWithUniDriver)(_EditableRowUni.editableRowUniDriverFactory));
  });
  function runTests(render) {
    var _this = this;
    afterEach(function () {
      return (0, _react2.cleanup)();
    });
    it('should focus on input when mounted', /*#__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(_EditableRow["default"], {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 18,
                columnNumber: 33
              }
            })), driver = _render.driver;
            _context.t0 = expect;
            _context.next = 4;
            return driver.isInputFocused();
          case 4:
            _context.t1 = _context.sent;
            (0, _context.t0)(_context.t1).toEqual(true);
          case 6:
          case "end":
            return _context.stop();
        }
      }, _callee);
    })));
    it('should toggle accept button disabled state according to input presence', /*#__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(_EditableRow["default"], {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 23,
                columnNumber: 33
              }
            })), driver = _render2.driver;
            _context2.t0 = expect;
            _context2.next = 4;
            return driver.isApproveDisabled();
          case 4:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).toBe(true);
            _context2.next = 8;
            return driver.setText('new option');
          case 8:
            _context2.t2 = expect;
            _context2.next = 11;
            return driver.isApproveDisabled();
          case 11:
            _context2.t3 = _context2.sent;
            (0, _context2.t2)(_context2.t3).toBe(false);
          case 13:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it('should set input text from props', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      var text, _render3, driver;
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            text = 'new option';
            _render3 = render(/*#__PURE__*/_react["default"].createElement(_EditableRow["default"], {
              newOption: text,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 31,
                columnNumber: 33
              }
            })), driver = _render3.driver;
            _context3.t0 = expect;
            _context3.next = 5;
            return driver.getText();
          case 5:
            _context3.t1 = _context3.sent;
            (0, _context3.t0)(_context3.t1).toEqual(text);
          case 7:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should trigger onApprove callback when approve button is clicked', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      var onApprove, _render4, driver, text;
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            onApprove = vi.fn();
            _render4 = render(/*#__PURE__*/_react["default"].createElement(_EditableRow["default"], {
              onApprove: onApprove,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 37,
                columnNumber: 33
              }
            })), driver = _render4.driver;
            text = 'new option';
            _context4.next = 5;
            return driver.setText(text);
          case 5:
            _context4.next = 7;
            return driver.clickApprove();
          case 7:
            expect(onApprove).toHaveBeenCalled();
            expect(onApprove.mock.calls[0][0]).toBe(text);
          case 9:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
    it('should trigger onApprove callback when enter key is pressed', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var onApprove, _render5, driver, text;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            onApprove = vi.fn();
            _render5 = render(/*#__PURE__*/_react["default"].createElement(_EditableRow["default"], {
              onApprove: onApprove,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 47,
                columnNumber: 33
              }
            })), driver = _render5.driver;
            text = 'new option';
            _context5.next = 5;
            return driver.setText(text);
          case 5:
            _context5.next = 7;
            return driver.keyDown(13);
          case 7:
            // enter
            expect(onApprove).toHaveBeenCalled();
            expect(onApprove.mock.calls[0][0]).toBe(text);
          case 9:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
    it('should trigger onCancel callback when cancel button is clicked', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var onCancel, _render6, driver;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            onCancel = vi.fn();
            _render6 = render(/*#__PURE__*/_react["default"].createElement(_EditableRow["default"], {
              onCancel: onCancel,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 57,
                columnNumber: 33
              }
            })), driver = _render6.driver;
            _context6.next = 4;
            return driver.clickCancel();
          case 4:
            expect(onCancel).toHaveBeenCalled();
          case 5:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should trigger onCancel callback when escape key is pressed', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      var onCancel, _render7, driver;
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            onCancel = vi.fn();
            _render7 = render(/*#__PURE__*/_react["default"].createElement(_EditableRow["default"], {
              onCancel: onCancel,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 64,
                columnNumber: 33
              }
            })), driver = _render7.driver;
            _context7.next = 4;
            return driver.keyDown(27);
          case 4:
            // esc
            expect(onCancel).toHaveBeenCalled();
          case 5:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
  }
});