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/VariableInput/test/VariableInput.spec.jsx",
  _this = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { createRendererWithUniDriver, cleanup, act } from '../../utils/test-utils/react';
import publicDriverFactory from '../VariableInput.uni.driver';
import privateDriverFactory from './VariableInput.private.uni.driver';
import VariableInput from '../VariableInput';
import { sizeTypes } from '../constants';
import { selectionBehaviorPolyfill } from '../../polyfills';
describe('VariableInput', function () {
  afterEach(function () {
    return cleanup();
  });
  var render = createRendererWithUniDriver(privateDriverFactory);
  var variableEntity = {
    text: 'Page name',
    value: 'page.name'
  };
  var variableParser = function variableParser(value) {
    return value === variableEntity.value ? variableEntity.text : false;
  };
  beforeAll(function () {
    selectionBehaviorPolyfill.install();
  });
  afterAll(function () {
    selectionBehaviorPolyfill.uninstall();
  });
  describe('initialValue', function () {
    it('should render the text when `initialValue` prop is plain text', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var text, _render, driver;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            text = 'Some text';
            _render = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: text,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 35,
                columnNumber: 9
              }
            })), driver = _render.driver;
            _context.t0 = expect;
            _context.next = 5;
            return driver.exists();
          case 5:
            _context.t1 = _context.sent;
            (0, _context.t0)(_context.t1).toBe(true);
            _context.t2 = expect;
            _context.next = 10;
            return driver.getContent();
          case 10:
            _context.t3 = _context.sent;
            (0, _context.t2)(_context.t3).toBe(text);
          case 12:
          case "end":
            return _context.stop();
        }
      }, _callee);
    })));
  });
  describe('variableParser', function () {
    it('should render the text when `initialValue` prop contains valid variables', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
      var _render2, driver;
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            _render2 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: "hello world {{page.name}}",
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 44,
                columnNumber: 9
              }
            })), driver = _render2.driver;
            _context2.t0 = expect;
            _context2.next = 4;
            return driver.getContent();
          case 4:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).toBe('hello world  Page name ');
          case 6:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
    it('should keep text as is if variable not valid in the parser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
      var _render3, driver;
      return _regeneratorRuntime.wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            _render3 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: "hello world {{test.val}}",
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 53,
                columnNumber: 9
              }
            })), driver = _render3.driver;
            _context3.t0 = expect;
            _context3.next = 4;
            return driver.getContent();
          case 4:
            _context3.t1 = _context3.sent;
            (0, _context3.t0)(_context3.t1).toBe('hello world {{test.val}}');
          case 6:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should ignore preceding and following brackets', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
      var _render4, driver;
      return _regeneratorRuntime.wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            _render4 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: "hello world {{{page.name}}}",
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 62,
                columnNumber: 9
              }
            })), driver = _render4.driver;
            _context4.t0 = expect;
            _context4.next = 4;
            return driver.getContent();
          case 4:
            _context4.t1 = _context4.sent;
            (0, _context4.t0)(_context4.t1).toBe('hello world { Page name }');
          case 6:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
  });
  describe('insertVariable', function () {
    it('should add variable text to content if variable is valid in parser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
      var myRef, _render5, driver;
      return _regeneratorRuntime.wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            myRef = null;
            _render5 = render(/*#__PURE__*/React.createElement(VariableInput, {
              variableParser: variableParser,
              ref: function ref(_ref6) {
                myRef = _ref6;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 74,
                columnNumber: 9
              }
            })), driver = _render5.driver;
            _context6.t0 = expect;
            _context6.next = 5;
            return driver.getContent();
          case 5:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toBe('');
            _context6.next = 9;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
              return _regeneratorRuntime.wrap(function _callee5$(_context5) {
                while (1) switch (_context5.prev = _context5.next) {
                  case 0:
                    myRef.insertVariable(variableEntity.value);
                  case 1:
                  case "end":
                    return _context5.stop();
                }
              }, _callee5);
            })));
          case 9:
            _context6.t2 = expect;
            _context6.next = 12;
            return driver.getContent();
          case 12:
            _context6.t3 = _context6.sent;
            (0, _context6.t2)(_context6.t3).toBe(' Page name  ');
          case 14:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should add wrapped variable value to content if variable is not valid in parser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
      var myRef, _render6, driver;
      return _regeneratorRuntime.wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            myRef = null;
            _render6 = render(/*#__PURE__*/React.createElement(VariableInput, {
              variableParser: variableParser,
              ref: function ref(_ref9) {
                myRef = _ref9;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 92,
                columnNumber: 9
              }
            })), driver = _render6.driver;
            _context8.t0 = expect;
            _context8.next = 5;
            return driver.getContent();
          case 5:
            _context8.t1 = _context8.sent;
            (0, _context8.t0)(_context8.t1).toBe('');
            _context8.next = 9;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
              return _regeneratorRuntime.wrap(function _callee7$(_context7) {
                while (1) switch (_context7.prev = _context7.next) {
                  case 0:
                    myRef.insertVariable('unknown.variable');
                  case 1:
                  case "end":
                    return _context7.stop();
                }
              }, _callee7);
            })));
          case 9:
            _context8.t2 = expect;
            _context8.next = 12;
            return driver.getContent();
          case 12:
            _context8.t3 = _context8.sent;
            (0, _context8.t2)(_context8.t3).toBe("{{unknown.variable}} ");
          case 14:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
  });
  describe('insertText', function () {
    it('should insert text at cursor position', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() {
      var myRef, marker, parser, initialValue, _render7, driver;
      return _regeneratorRuntime.wrap(function _callee1$(_context1) {
        while (1) switch (_context1.prev = _context1.next) {
          case 0:
            myRef = null;
            marker = {
              text: 'Marker',
              value: 'marker'
            };
            parser = function parser(value) {
              return value === marker.value ? marker.text : false;
            };
            initialValue = "hello {{".concat(marker.value, "}} there");
            _render7 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref10) {
                myRef = _ref10;
              },
              initialValue: initialValue,
              variableParser: parser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 116,
                columnNumber: 9
              }
            })), driver = _render7.driver;
            _context1.t0 = expect;
            _context1.next = 8;
            return driver.getContent();
          case 8:
            _context1.t1 = _context1.sent;
            (0, _context1.t0)(_context1.t1).toBe('hello  Marker  there');
            _context1.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
              return _regeneratorRuntime.wrap(function _callee9$(_context9) {
                while (1) switch (_context9.prev = _context9.next) {
                  case 0:
                    myRef.focus({
                      variableKey: marker.value
                    });
                  case 1:
                  case "end":
                    return _context9.stop();
                }
              }, _callee9);
            })));
          case 12:
            _context1.next = 14;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() {
              return _regeneratorRuntime.wrap(function _callee0$(_context0) {
                while (1) switch (_context0.prev = _context0.next) {
                  case 0:
                    myRef.insertText('😁');
                  case 1:
                  case "end":
                    return _context0.stop();
                }
              }, _callee0);
            })));
          case 14:
            _context1.t2 = expect;
            _context1.next = 17;
            return driver.getContent();
          case 17:
            _context1.t3 = _context1.sent;
            (0, _context1.t2)(_context1.t3).toBe('hello  Marker 😁 there');
          case 19:
          case "end":
            return _context1.stop();
        }
      }, _callee1);
    })));
  });
  describe('typing text with variables', function () {
    it('should add variable text to content', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
      var stateValue, _render8, driver;
      return _regeneratorRuntime.wrap(function _callee10$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            _render8 = render(/*#__PURE__*/React.createElement(VariableInput, {
              variableParser: variableParser,
              onChange: function onChange(value) {
                return stateValue = value;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 142,
                columnNumber: 9
              }
            })), driver = _render8.driver;
            _context10.next = 3;
            return driver.click();
          case 3:
            _context10.next = 5;
            return driver.enterText("/\uD83E\uDD14{{".concat(variableEntity.value, "}}/\uD83E\uDD14{{").concat(variableEntity.value, "}}"));
          case 5:
            _context10.next = 7;
            return driver.blur();
          case 7:
            _context10.t0 = expect;
            _context10.next = 10;
            return driver.getContent();
          case 10:
            _context10.t1 = _context10.sent;
            (0, _context10.t0)(_context10.t1).toBe('/🤔 Page name /🤔 Page name ');
            expect(stateValue).toEqual('/🤔{{page.name}}/🤔{{page.name}}');
          case 13:
          case "end":
            return _context10.stop();
        }
      }, _callee10);
    })));
  });
  describe('setValue', function () {
    it('should update text while using `setValue`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
      var text, myRef, _render9, driver;
      return _regeneratorRuntime.wrap(function _callee12$(_context12) {
        while (1) switch (_context12.prev = _context12.next) {
          case 0:
            text = 'Some text';
            myRef = null;
            _render9 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref15) {
                myRef = _ref15;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 163,
                columnNumber: 9
              }
            })), driver = _render9.driver;
            _context12.t0 = expect;
            _context12.next = 6;
            return driver.getContent();
          case 6:
            _context12.t1 = _context12.sent;
            (0, _context12.t0)(_context12.t1).toBe('');
            _context12.next = 10;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
              return _regeneratorRuntime.wrap(function _callee11$(_context11) {
                while (1) switch (_context11.prev = _context11.next) {
                  case 0:
                    myRef.setValue(text);
                  case 1:
                  case "end":
                    return _context11.stop();
                }
              }, _callee11);
            })));
          case 10:
            _context12.t2 = expect;
            _context12.next = 13;
            return driver.getContent();
          case 13:
            _context12.t3 = _context12.sent;
            (0, _context12.t2)(_context12.t3).toBe("".concat(text));
          case 15:
          case "end":
            return _context12.stop();
        }
      }, _callee12);
    })));
  });
  describe('onSubmit', function () {
    it('should invoke `onSubmit` with variable after `insertVariable`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
      var callback, text, expectedHtmlValue, myRef, _render0, driver;
      return _regeneratorRuntime.wrap(function _callee14$(_context14) {
        while (1) switch (_context14.prev = _context14.next) {
          case 0:
            callback = vi.fn();
            text = 'Some text';
            expectedHtmlValue = "{{".concat(text, "}} ");
            myRef = null;
            _render0 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onSubmit: callback,
              ref: function ref(_ref18) {
                myRef = _ref18;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 185,
                columnNumber: 9
              }
            })), driver = _render0.driver;
            _context14.t0 = expect;
            _context14.next = 8;
            return driver.getContent();
          case 8:
            _context14.t1 = _context14.sent;
            (0, _context14.t0)(_context14.t1).toBe('');
            _context14.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
              return _regeneratorRuntime.wrap(function _callee13$(_context13) {
                while (1) switch (_context13.prev = _context13.next) {
                  case 0:
                    myRef.insertVariable(text);
                  case 1:
                  case "end":
                    return _context13.stop();
                }
              }, _callee13);
            })));
          case 12:
            expect(callback).toHaveBeenCalledWith(expectedHtmlValue);
          case 13:
          case "end":
            return _context14.stop();
        }
      }, _callee14);
    })));
    it('should invoke `onSubmit` with variable after `setValue`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
      var callback, text, expectedHtmlValue, myRef, _render1, driver;
      return _regeneratorRuntime.wrap(function _callee16$(_context16) {
        while (1) switch (_context16.prev = _context16.next) {
          case 0:
            callback = vi.fn();
            text = 'Some text {{page.name}}';
            expectedHtmlValue = "Some text  Page name ";
            myRef = null;
            _render1 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onSubmit: callback,
              variableParser: variableParser,
              ref: function ref(_ref21) {
                myRef = _ref21;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 206,
                columnNumber: 9
              }
            })), driver = _render1.driver;
            _context16.t0 = expect;
            _context16.next = 8;
            return driver.getContent();
          case 8:
            _context16.t1 = _context16.sent;
            (0, _context16.t0)(_context16.t1).toBe('');
            _context16.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
              return _regeneratorRuntime.wrap(function _callee15$(_context15) {
                while (1) switch (_context15.prev = _context15.next) {
                  case 0:
                    myRef.setValue(text);
                  case 1:
                  case "end":
                    return _context15.stop();
                }
              }, _callee15);
            })));
          case 12:
            _context16.t2 = expect;
            _context16.next = 15;
            return driver.getContent();
          case 15:
            _context16.t3 = _context16.sent;
            (0, _context16.t2)(_context16.t3).toBe(expectedHtmlValue);
            expect(callback).toHaveBeenCalledWith(text);
          case 18:
          case "end":
            return _context16.stop();
        }
      }, _callee16);
    })));
    it('should not invoke `onSubmit` while typing', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
      var callback, text, _render10, driver;
      return _regeneratorRuntime.wrap(function _callee17$(_context17) {
        while (1) switch (_context17.prev = _context17.next) {
          case 0:
            callback = vi.fn();
            text = 'Some text {{page.name}}';
            _render10 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onSubmit: callback,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 228,
                columnNumber: 9
              }
            })), driver = _render10.driver;
            driver.enterText(text);
            expect(callback).not.toHaveBeenCalled();
          case 5:
          case "end":
            return _context17.stop();
        }
      }, _callee17);
    })));
  });
  describe('variableTemplate', function () {
    it('should render the text when `initialValue` prop is plain text', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
      var callback, text, expectedHtmlValue, myRef, _render11, driver;
      return _regeneratorRuntime.wrap(function _callee19$(_context19) {
        while (1) switch (_context19.prev = _context19.next) {
          case 0:
            callback = vi.fn();
            text = 'Some text $(page.name)';
            expectedHtmlValue = "Some text  Page name ";
            myRef = null;
            _render11 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onSubmit: callback,
              variableParser: variableParser,
              variableTemplate: {
                prefix: '$(',
                suffix: ')'
              },
              ref: function ref(_ref25) {
                myRef = _ref25;
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 242,
                columnNumber: 9
              }
            })), driver = _render11.driver;
            _context19.t0 = expect;
            _context19.next = 8;
            return driver.getContent();
          case 8:
            _context19.t1 = _context19.sent;
            (0, _context19.t0)(_context19.t1).toBe('');
            _context19.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
              return _regeneratorRuntime.wrap(function _callee18$(_context18) {
                while (1) switch (_context18.prev = _context18.next) {
                  case 0:
                    myRef.setValue(text);
                  case 1:
                  case "end":
                    return _context18.stop();
                }
              }, _callee18);
            })));
          case 12:
            _context19.t2 = expect;
            _context19.next = 15;
            return driver.getContent();
          case 15:
            _context19.t3 = _context19.sent;
            (0, _context19.t2)(_context19.t3).toBe(expectedHtmlValue);
            expect(callback).toHaveBeenCalledWith(text);
          case 18:
          case "end":
            return _context19.stop();
        }
      }, _callee19);
    })));
  });
  describe('status attribute', function () {
    it('should have no status', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
      var render, _render12, driver;
      return _regeneratorRuntime.wrap(function _callee20$(_context20) {
        while (1) switch (_context20.prev = _context20.next) {
          case 0:
            render = createRendererWithUniDriver(publicDriverFactory);
            _render12 = render(/*#__PURE__*/React.createElement(VariableInput, _extends({}, test, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 265,
                columnNumber: 33
              }
            }))), driver = _render12.driver;
            _context20.t0 = expect;
            _context20.next = 5;
            return driver.hasStatus('error');
          case 5:
            _context20.t1 = _context20.sent;
            (0, _context20.t0)(_context20.t1).toBe(false);
          case 7:
          case "end":
            return _context20.stop();
        }
      }, _callee20);
    })));
    it.each([{
      status: 'error'
    }, {
      status: 'warning'
    }, {
      status: 'loading'
    }])('should display status when %p', /*#__PURE__*/function () {
      var _ref28 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21(test) {
        var render, _render13, driver;
        return _regeneratorRuntime.wrap(function _callee21$(_context21) {
          while (1) switch (_context21.prev = _context21.next) {
            case 0:
              render = createRendererWithUniDriver(publicDriverFactory);
              _render13 = render(/*#__PURE__*/React.createElement(VariableInput, _extends({}, test, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 276,
                  columnNumber: 33
                }
              }))), driver = _render13.driver;
              _context21.t0 = expect;
              _context21.next = 5;
              return driver.hasStatus(test.status);
            case 5:
              _context21.t1 = _context21.sent;
              (0, _context21.t0)(_context21.t1).toBe(true);
              _context21.t2 = expect;
              _context21.next = 10;
              return driver.getStatusMessage();
            case 10:
              _context21.t3 = _context21.sent;
              (0, _context21.t2)(_context21.t3).toBeNull();
            case 12:
            case "end":
              return _context21.stop();
          }
        }, _callee21);
      }));
      return function (_x) {
        return _ref28.apply(this, arguments);
      };
    }());
    it.each([{
      status: 'error',
      statusMessage: 'Error Message'
    }, {
      status: 'warning',
      statusMessage: 'Warning Message'
    }, {
      status: 'loading',
      statusMessage: 'Loading Message'
    }])('should display status with message when %p', /*#__PURE__*/function () {
      var _ref29 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee22(test) {
        var render, _render14, driver;
        return _regeneratorRuntime.wrap(function _callee22$(_context22) {
          while (1) switch (_context22.prev = _context22.next) {
            case 0:
              render = createRendererWithUniDriver(publicDriverFactory);
              _render14 = render(/*#__PURE__*/React.createElement(VariableInput, _extends({}, test, {
                __self: _this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 288,
                  columnNumber: 33
                }
              }))), driver = _render14.driver;
              _context22.t0 = expect;
              _context22.next = 5;
              return driver.hasStatus(test.status);
            case 5:
              _context22.t1 = _context22.sent;
              (0, _context22.t0)(_context22.t1).toBe(true);
              _context22.t2 = expect;
              _context22.next = 10;
              return driver.getStatusMessage();
            case 10:
              _context22.t3 = _context22.sent;
              (0, _context22.t2)(_context22.t3).toBe(test.statusMessage);
            case 12:
            case "end":
              return _context22.stop();
          }
        }, _callee22);
      }));
      return function (_x2) {
        return _ref29.apply(this, arguments);
      };
    }());
  });
  describe('variableTagPropsParser', function () {
    it('should render a tag in error theme ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
      var text, _render15, driver;
      return _regeneratorRuntime.wrap(function _callee23$(_context23) {
        while (1) switch (_context23.prev = _context23.next) {
          case 0:
            text = "Some text {{".concat(variableEntity.value, "}} ");
            _render15 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: text,
              variableParser: variableParser,
              variableTagPropsParser: function variableTagPropsParser() {
                return {
                  theme: 'error'
                };
              },
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 299,
                columnNumber: 9
              }
            })), driver = _render15.driver;
            _context23.t0 = expect;
            _context23.next = 5;
            return driver.getTagDriver().isErrorTheme();
          case 5:
            _context23.t1 = _context23.sent;
            (0, _context23.t0)(_context23.t1).toBe(true);
          case 7:
          case "end":
            return _context23.stop();
        }
      }, _callee23);
    })));
  });
  describe('size', function () {
    it('should render a tag in small size', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee24() {
      var text, _render16, driver;
      return _regeneratorRuntime.wrap(function _callee24$(_context24) {
        while (1) switch (_context24.prev = _context24.next) {
          case 0:
            text = "Some text {{".concat(variableEntity.value, "}} ");
            _render16 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: text,
              size: sizeTypes.small,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 314,
                columnNumber: 9
              }
            })), driver = _render16.driver;
            _context24.t0 = expect;
            _context24.next = 5;
            return driver.isTagTiny();
          case 5:
            _context24.t1 = _context24.sent;
            (0, _context24.t0)(_context24.t1).toBe(true);
          case 7:
          case "end":
            return _context24.stop();
        }
      }, _callee24);
    })));
    it('should render a tag in medium size', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee25() {
      var text, _render17, driver;
      return _regeneratorRuntime.wrap(function _callee25$(_context25) {
        while (1) switch (_context25.prev = _context25.next) {
          case 0:
            text = "Some text {{".concat(variableEntity.value, "}} ");
            _render17 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: text,
              size: sizeTypes.medium,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 325,
                columnNumber: 9
              }
            })), driver = _render17.driver;
            _context25.t0 = expect;
            _context25.next = 5;
            return driver.isTagSmall();
          case 5:
            _context25.t1 = _context25.sent;
            (0, _context25.t0)(_context25.t1).toBe(true);
          case 7:
          case "end":
            return _context25.stop();
        }
      }, _callee25);
    })));
    it('should render a tag in large size', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee26() {
      var text, _render18, driver;
      return _regeneratorRuntime.wrap(function _callee26$(_context26) {
        while (1) switch (_context26.prev = _context26.next) {
          case 0:
            text = "Some text {{".concat(variableEntity.value, "}} ");
            _render18 = render(/*#__PURE__*/React.createElement(VariableInput, {
              initialValue: text,
              size: sizeTypes.large,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 336,
                columnNumber: 9
              }
            })), driver = _render18.driver;
            _context26.t0 = expect;
            _context26.next = 5;
            return driver.isTagSmall();
          case 5:
            _context26.t1 = _context26.sent;
            (0, _context26.t0)(_context26.t1).toBe(true);
          case 7:
          case "end":
            return _context26.stop();
        }
      }, _callee26);
    })));
  });
  describe('disabled', function () {
    it('should disable component when passing `disabled` prop', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee27() {
      var _render19, driver;
      return _regeneratorRuntime.wrap(function _callee27$(_context27) {
        while (1) switch (_context27.prev = _context27.next) {
          case 0:
            _render19 = render(/*#__PURE__*/React.createElement(VariableInput, {
              disabled: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 347,
                columnNumber: 33
              }
            })), driver = _render19.driver;
            _context27.t0 = expect;
            _context27.next = 4;
            return driver.isDisabled();
          case 4:
            _context27.t1 = _context27.sent;
            (0, _context27.t0)(_context27.t1).toBe(true);
          case 6:
          case "end":
            return _context27.stop();
        }
      }, _callee27);
    })));
  });
  describe('readOnly', function () {
    it('should disable component when passing `readOnly` prop', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee28() {
      var _render20, driver;
      return _regeneratorRuntime.wrap(function _callee28$(_context28) {
        while (1) switch (_context28.prev = _context28.next) {
          case 0:
            _render20 = render(/*#__PURE__*/React.createElement(VariableInput, {
              readOnly: true,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 353,
                columnNumber: 33
              }
            })), driver = _render20.driver;
            _context28.t0 = expect;
            _context28.next = 4;
            return driver.isDisabled();
          case 4:
            _context28.t1 = _context28.sent;
            (0, _context28.t0)(_context28.t1).toBe(true);
          case 6:
          case "end":
            return _context28.stop();
        }
      }, _callee28);
    })));
  });
  describe('placeholder', function () {
    it('should render a placeholder', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee29() {
      var placeholderText, _render21, driver;
      return _regeneratorRuntime.wrap(function _callee29$(_context29) {
        while (1) switch (_context29.prev = _context29.next) {
          case 0:
            placeholderText = 'Placeholder';
            _render21 = render(/*#__PURE__*/React.createElement(VariableInput, {
              placeholder: placeholderText,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 361,
                columnNumber: 9
              }
            })), driver = _render21.driver;
            _context29.t0 = expect;
            _context29.next = 5;
            return driver.getContent();
          case 5:
            _context29.t1 = _context29.sent;
            (0, _context29.t0)(_context29.t1).toBe('');
            _context29.t2 = expect;
            _context29.next = 10;
            return driver.getPlaceholder();
          case 10:
            _context29.t3 = _context29.sent;
            (0, _context29.t2)(_context29.t3).toBe(placeholderText);
          case 12:
          case "end":
            return _context29.stop();
        }
      }, _callee29);
    })));
  });
  describe('onChange', function () {
    it('should invoke `onChange` with variable while typing', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee30() {
      var callback, expectedHtmlValue, _render22, driver;
      return _regeneratorRuntime.wrap(function _callee30$(_context30) {
        while (1) switch (_context30.prev = _context30.next) {
          case 0:
            callback = vi.fn();
            expectedHtmlValue = "{{".concat(variableEntity.value, "}} ");
            _render22 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onChange: callback,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 372,
                columnNumber: 9
              }
            })), driver = _render22.driver;
            _context30.next = 5;
            return driver.enterText(expectedHtmlValue);
          case 5:
            expect(callback).toHaveBeenCalledWith(expectedHtmlValue);
          case 6:
          case "end":
            return _context30.stop();
        }
      }, _callee30);
    })));
  });
  describe('onBlur', function () {
    it('should invoke `onBlur` with string while blur', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee31() {
      var callback, expectedHtmlValue, _render23, driver;
      return _regeneratorRuntime.wrap(function _callee31$(_context31) {
        while (1) switch (_context31.prev = _context31.next) {
          case 0:
            callback = vi.fn();
            expectedHtmlValue = "{{".concat(variableEntity.value, "}} ");
            _render23 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onBlur: callback,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 383,
                columnNumber: 9
              }
            })), driver = _render23.driver;
            _context31.next = 5;
            return driver.focus();
          case 5:
            _context31.next = 7;
            return driver.enterText(expectedHtmlValue);
          case 7:
            _context31.next = 9;
            return driver.blur();
          case 9:
            expect(callback).toHaveBeenCalledWith(expectedHtmlValue);
          case 10:
          case "end":
            return _context31.stop();
        }
      }, _callee31);
    })));
  });
  describe('onFocus', function () {
    it('should invoke `onFocus` with string while focus', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee32() {
      var callback, expectedHtmlValue, _render24, driver;
      return _regeneratorRuntime.wrap(function _callee32$(_context32) {
        while (1) switch (_context32.prev = _context32.next) {
          case 0:
            callback = vi.fn();
            expectedHtmlValue = "{{".concat(variableEntity.value, "}} ");
            _render24 = render(/*#__PURE__*/React.createElement(VariableInput, {
              onBlur: callback,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 397,
                columnNumber: 9
              }
            })), driver = _render24.driver;
            _context32.next = 5;
            return driver.focus();
          case 5:
            _context32.next = 7;
            return driver.enterText(expectedHtmlValue);
          case 7:
            _context32.next = 9;
            return driver.blur();
          case 9:
            _context32.next = 11;
            return driver.focus();
          case 11:
            expect(callback).toHaveBeenCalledWith(expectedHtmlValue);
          case 12:
          case "end":
            return _context32.stop();
        }
      }, _callee32);
    })));
  });
  describe('keyboard focus cursor position', function () {
    it('should place cursor at the end when focused via keyboard (Tab)', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee34() {
      var myRef, initialValue, _render25, driver;
      return _regeneratorRuntime.wrap(function _callee34$(_context34) {
        while (1) switch (_context34.prev = _context34.next) {
          case 0:
            myRef = null;
            initialValue = 'Hello world';
            _render25 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref41) {
                myRef = _ref41;
              },
              initialValue: initialValue,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 412,
                columnNumber: 9
              }
            })), driver = _render25.driver;
            _context34.t0 = expect;
            _context34.next = 6;
            return driver.getContent();
          case 6:
            _context34.t1 = _context34.sent;
            (0, _context34.t0)(_context34.t1).toBe('Hello world');
            _context34.next = 10;
            return driver.focus();
          case 10:
            _context34.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee33() {
              return _regeneratorRuntime.wrap(function _callee33$(_context33) {
                while (1) switch (_context33.prev = _context33.next) {
                  case 0:
                    myRef.insertText('!');
                  case 1:
                  case "end":
                    return _context33.stop();
                }
              }, _callee33);
            })));
          case 12:
            _context34.t2 = expect;
            _context34.next = 15;
            return driver.getContent();
          case 15:
            _context34.t3 = _context34.sent;
            (0, _context34.t2)(_context34.t3).toBe('Hello world!');
          case 17:
          case "end":
            return _context34.stop();
        }
      }, _callee34);
    })));
    it('should place cursor at end on keyboard focus when content has variables', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee36() {
      var myRef, initialValue, _render26, driver;
      return _regeneratorRuntime.wrap(function _callee36$(_context36) {
        while (1) switch (_context36.prev = _context36.next) {
          case 0:
            myRef = null;
            initialValue = "Hello {{".concat(variableEntity.value, "}} world");
            _render26 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref44) {
                myRef = _ref44;
              },
              initialValue: initialValue,
              variableParser: variableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 438,
                columnNumber: 9
              }
            })), driver = _render26.driver;
            _context36.t0 = expect;
            _context36.next = 6;
            return driver.getContent();
          case 6:
            _context36.t1 = _context36.sent;
            (0, _context36.t0)(_context36.t1).toBe('Hello  Page name  world');
            _context36.next = 10;
            return driver.focus();
          case 10:
            _context36.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee35() {
              return _regeneratorRuntime.wrap(function _callee35$(_context35) {
                while (1) switch (_context35.prev = _context35.next) {
                  case 0:
                    myRef.insertText('!');
                  case 1:
                  case "end":
                    return _context35.stop();
                }
              }, _callee35);
            })));
          case 12:
            _context36.t2 = expect;
            _context36.next = 15;
            return driver.getContent();
          case 15:
            _context36.t3 = _context36.sent;
            (0, _context36.t2)(_context36.t3).toBe('Hello  Page name  world!');
          case 17:
          case "end":
            return _context36.stop();
        }
      }, _callee36);
    })));
  });
  describe('focus', function () {
    it('should call variableInputRef.current.focus() and trigger onFocus', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee38() {
      var onFocusMock, variableInputRef, _render27, driver;
      return _regeneratorRuntime.wrap(function _callee38$(_context38) {
        while (1) switch (_context38.prev = _context38.next) {
          case 0:
            onFocusMock = vi.fn();
            variableInputRef = null;
            _render27 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref47) {
                variableInputRef = _ref47;
              },
              onFocus: onFocusMock,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 465,
                columnNumber: 9
              }
            })), driver = _render27.driver;
            _context38.next = 5;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee37() {
              return _regeneratorRuntime.wrap(function _callee37$(_context37) {
                while (1) switch (_context37.prev = _context37.next) {
                  case 0:
                    variableInputRef.focus();
                  case 1:
                  case "end":
                    return _context37.stop();
                }
              }, _callee37);
            })));
          case 5:
            expect(onFocusMock).toHaveBeenCalled();
          case 6:
          case "end":
            return _context38.stop();
        }
      }, _callee38);
    })));
    it('should focus after the specified variableKey', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee41() {
      var variableInputRef, anotherVariable, customVariableParser, initialValue, _render28, driver;
      return _regeneratorRuntime.wrap(function _callee41$(_context41) {
        while (1) switch (_context41.prev = _context41.next) {
          case 0:
            variableInputRef = null;
            anotherVariable = {
              text: 'Site name',
              value: 'site.name'
            };
            customVariableParser = function customVariableParser(value) {
              if (value === variableEntity.value) {
                return variableEntity.text;
              }
              if (value === anotherVariable.value) {
                return anotherVariable.text;
              }
              return false;
            };
            initialValue = "Hello {{".concat(variableEntity.value, "}} world");
            _render28 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref50) {
                variableInputRef = _ref50;
              },
              initialValue: initialValue,
              variableParser: customVariableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 494,
                columnNumber: 9
              }
            })), driver = _render28.driver;
            _context41.t0 = expect;
            _context41.next = 8;
            return driver.getContent();
          case 8:
            _context41.t1 = _context41.sent;
            (0, _context41.t0)(_context41.t1).toBe("Hello  ".concat(variableEntity.text, "  world"));
            _context41.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee39() {
              return _regeneratorRuntime.wrap(function _callee39$(_context39) {
                while (1) switch (_context39.prev = _context39.next) {
                  case 0:
                    variableInputRef.focus({
                      variableKey: variableEntity.value
                    });
                  case 1:
                  case "end":
                    return _context39.stop();
                }
              }, _callee39);
            })));
          case 12:
            _context41.next = 14;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee40() {
              return _regeneratorRuntime.wrap(function _callee40$(_context40) {
                while (1) switch (_context40.prev = _context40.next) {
                  case 0:
                    variableInputRef.insertVariable(anotherVariable.value);
                  case 1:
                  case "end":
                    return _context40.stop();
                }
              }, _callee40);
            })));
          case 14:
            _context41.t2 = expect;
            _context41.next = 17;
            return driver.getContent();
          case 17:
            _context41.t3 = _context41.sent;
            (0, _context41.t2)(_context41.t3).toBe("Hello  ".concat(variableEntity.text, "  ").concat(anotherVariable.text, "   world"));
          case 19:
          case "end":
            return _context41.stop();
        }
      }, _callee41);
    })));
    it('should focus at the end of input content with not-found/empty variableKey', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee46() {
      var variableInputRef, anotherVariable, customVariableParser, initialValue, _render29, driver;
      return _regeneratorRuntime.wrap(function _callee46$(_context46) {
        while (1) switch (_context46.prev = _context46.next) {
          case 0:
            variableInputRef = null;
            anotherVariable = {
              text: 'Site name',
              value: 'site.name'
            };
            customVariableParser = function customVariableParser(value) {
              if (value === variableEntity.value) {
                return variableEntity.text;
              }
              if (value === anotherVariable.value) {
                return anotherVariable.text;
              }
              return false;
            };
            initialValue = "Hello {{".concat(variableEntity.value, "}} world");
            _render29 = render(/*#__PURE__*/React.createElement(VariableInput, {
              ref: function ref(_ref54) {
                variableInputRef = _ref54;
              },
              initialValue: initialValue,
              variableParser: customVariableParser,
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 534,
                columnNumber: 9
              }
            })), driver = _render29.driver;
            _context46.t0 = expect;
            _context46.next = 8;
            return driver.getContent();
          case 8:
            _context46.t1 = _context46.sent;
            (0, _context46.t0)(_context46.t1).toBe("Hello  ".concat(variableEntity.text, "  world"));
            _context46.next = 12;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee42() {
              return _regeneratorRuntime.wrap(function _callee42$(_context42) {
                while (1) switch (_context42.prev = _context42.next) {
                  case 0:
                    variableInputRef.focus({
                      variableKey: 'nonexistent.variable'
                    });
                  case 1:
                  case "end":
                    return _context42.stop();
                }
              }, _callee42);
            })));
          case 12:
            _context46.next = 14;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee43() {
              return _regeneratorRuntime.wrap(function _callee43$(_context43) {
                while (1) switch (_context43.prev = _context43.next) {
                  case 0:
                    variableInputRef.insertVariable(anotherVariable.value);
                  case 1:
                  case "end":
                    return _context43.stop();
                }
              }, _callee43);
            })));
          case 14:
            _context46.t2 = expect;
            _context46.next = 17;
            return driver.getContent();
          case 17:
            _context46.t3 = _context46.sent;
            (0, _context46.t2)(_context46.t3).toBe("Hello  ".concat(variableEntity.text, "  world ").concat(anotherVariable.text, "  "));
            _context46.next = 21;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee44() {
              return _regeneratorRuntime.wrap(function _callee44$(_context44) {
                while (1) switch (_context44.prev = _context44.next) {
                  case 0:
                    variableInputRef.focus();
                  case 1:
                  case "end":
                    return _context44.stop();
                }
              }, _callee44);
            })));
          case 21:
            _context46.t4 = expect;
            _context46.next = 24;
            return driver.getContent();
          case 24:
            _context46.t5 = _context46.sent;
            (0, _context46.t4)(_context46.t5).toBe("Hello  ".concat(variableEntity.text, "  world ").concat(anotherVariable.text, "  "));
            _context46.next = 28;
            return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee45() {
              return _regeneratorRuntime.wrap(function _callee45$(_context45) {
                while (1) switch (_context45.prev = _context45.next) {
                  case 0:
                    variableInputRef.insertVariable(anotherVariable.value);
                  case 1:
                  case "end":
                    return _context45.stop();
                }
              }, _callee45);
            })));
          case 28:
            _context46.t6 = expect;
            _context46.next = 31;
            return driver.getContent();
          case 31:
            _context46.t7 = _context46.sent;
            (0, _context46.t6)(_context46.t7).toBe("Hello  ".concat(variableEntity.text, "  world ").concat(anotherVariable.text, "   ").concat(anotherVariable.text, "  "));
          case 33:
          case "end":
            return _context46.stop();
        }
      }, _callee46);
    })));
  });
});