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/FloatingHelper/test/FloatingHelper.spec.jsx",
  _this = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import floatingHelperUniDriverFactory from '../FloatingHelper.uni.driver';
import FloatingHelper from '../FloatingHelper';
import FloatingHelperContent from '../FloatingHelperContent/FloatingHelperContent';
import { createRendererWithUniDriver, cleanup, waitFor, act } from '../../utils/test-utils/unit';
describe('FloatingHelper', function () {
  var title = 'my title';
  var requiredProps = {
    content: /*#__PURE__*/React.createElement(FloatingHelperContent, {
      title: title,
      body: "this is the body",
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 16,
        columnNumber: 14
      }
    }),
    placement: 'right',
    target: /*#__PURE__*/React.createElement("div", {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 18,
        columnNumber: 13
      }
    }, "This is the target element")
  };
  describe('[async]', function () {
    runTest(createRendererWithUniDriver(floatingHelperUniDriverFactory));
  });
  function runTest(render) {
    var _this2 = this;
    afterEach(function () {
      return cleanup();
    });
    var waitForClose = function waitForClose(driver) {
      return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              _context.t0 = expect;
              _context.next = 3;
              return driver.isOpened();
            case 3:
              _context.t1 = _context.sent;
              return _context.abrupt("return", (0, _context.t0)(_context.t1).toBe(false));
            case 5:
            case "end":
              return _context.stop();
          }
        }, _callee);
      })));
    };
    describe('sanity', function () {
      it('should have helper content (with title)', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
        var _render, driver, helperContent;
        return _regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              _render = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 33,
                  columnNumber: 35
                }
              }))), driver = _render.driver;
              _context3.next = 3;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
                return _regeneratorRuntime.wrap(function _callee2$(_context2) {
                  while (1) switch (_context2.prev = _context2.next) {
                    case 0:
                      _context2.t0 = expect;
                      _context2.next = 3;
                      return driver.isTargetElementExists();
                    case 3:
                      _context2.t1 = _context2.sent;
                      return _context2.abrupt("return", (0, _context2.t0)(_context2.t1).toBe(true));
                    case 5:
                    case "end":
                      return _context2.stop();
                  }
                }, _callee2);
              })));
            case 3:
              helperContent = driver.helperContent;
              _context3.t0 = expect;
              _context3.next = 7;
              return helperContent.exists();
            case 7:
              _context3.t1 = _context3.sent;
              (0, _context3.t0)(_context3.t1).toBe(true);
              _context3.t2 = expect;
              _context3.next = 12;
              return helperContent.getTitleContent();
            case 12:
              _context3.t3 = _context3.sent;
              (0, _context3.t2)(_context3.t3).toBe(title);
            case 14:
            case "end":
              return _context3.stop();
          }
        }, _callee3);
      })));
      it('have a close button', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
        var _render2, driver;
        return _regeneratorRuntime.wrap(function _callee5$(_context5) {
          while (1) switch (_context5.prev = _context5.next) {
            case 0:
              _render2 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 46,
                  columnNumber: 35
                }
              }))), driver = _render2.driver;
              _context5.next = 3;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
                return _regeneratorRuntime.wrap(function _callee4$(_context4) {
                  while (1) switch (_context4.prev = _context4.next) {
                    case 0:
                      _context4.t0 = expect;
                      _context4.next = 3;
                      return driver.hasCloseButton();
                    case 3:
                      _context4.t1 = _context4.sent;
                      (0, _context4.t0)(_context4.t1).toBe(true);
                    case 5:
                    case "end":
                      return _context4.stop();
                  }
                }, _callee4);
              })));
            case 3:
            case "end":
              return _context5.stop();
          }
        }, _callee5);
      })));
    });
    describe('width', function () {
      it('should have default width of 444', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
        var _render3, driver;
        return _regeneratorRuntime.wrap(function _callee7$(_context7) {
          while (1) switch (_context7.prev = _context7.next) {
            case 0:
              _render3 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 56,
                  columnNumber: 35
                }
              }))), driver = _render3.driver;
              _context7.next = 3;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
                return _regeneratorRuntime.wrap(function _callee6$(_context6) {
                  while (1) switch (_context6.prev = _context6.next) {
                    case 0:
                      _context6.t0 = expect;
                      _context6.next = 3;
                      return driver.getWidth();
                    case 3:
                      _context6.t1 = _context6.sent;
                      (0, _context6.t0)(_context6.t1).toBe('444px');
                    case 5:
                    case "end":
                      return _context6.stop();
                  }
                }, _callee6);
              })));
            case 3:
            case "end":
              return _context7.stop();
          }
        }, _callee7);
      })));
      it('should have a custom width (which is a string)', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
        var props, _render4, driver;
        return _regeneratorRuntime.wrap(function _callee9$(_context9) {
          while (1) switch (_context9.prev = _context9.next) {
            case 0:
              props = {
                width: '500px'
              };
              _render4 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, props, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 66,
                  columnNumber: 11
                }
              }))), driver = _render4.driver;
              _context9.next = 4;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
                return _regeneratorRuntime.wrap(function _callee8$(_context8) {
                  while (1) switch (_context8.prev = _context8.next) {
                    case 0:
                      _context8.t0 = expect;
                      _context8.next = 3;
                      return driver.getWidth();
                    case 3:
                      _context8.t1 = _context8.sent;
                      (0, _context8.t0)(_context8.t1).toBe(props.width);
                    case 5:
                    case "end":
                      return _context8.stop();
                  }
                }, _callee8);
              })));
            case 4:
            case "end":
              return _context9.stop();
          }
        }, _callee9);
      })));
      it('should have a custom width (which is a number)', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() {
        var props, _render5, driver;
        return _regeneratorRuntime.wrap(function _callee1$(_context1) {
          while (1) switch (_context1.prev = _context1.next) {
            case 0:
              props = {
                width: 600
              };
              _render5 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, props, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 77,
                  columnNumber: 11
                }
              }))), driver = _render5.driver;
              _context1.next = 4;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() {
                return _regeneratorRuntime.wrap(function _callee0$(_context0) {
                  while (1) switch (_context0.prev = _context0.next) {
                    case 0:
                      _context0.t0 = expect;
                      _context0.next = 3;
                      return driver.getWidth();
                    case 3:
                      _context0.t1 = _context0.sent;
                      (0, _context0.t0)(_context0.t1).toBe("".concat(props.width, "px"));
                    case 5:
                    case "end":
                      return _context0.stop();
                  }
                }, _callee0);
              })));
            case 4:
            case "end":
              return _context1.stop();
          }
        }, _callee1);
      })));
    });
    describe('close', function () {
      it('should be opened by default', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
        var _render6, driver;
        return _regeneratorRuntime.wrap(function _callee11$(_context11) {
          while (1) switch (_context11.prev = _context11.next) {
            case 0:
              _render6 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 88,
                  columnNumber: 35
                }
              }))), driver = _render6.driver;
              _context11.next = 3;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
                return _regeneratorRuntime.wrap(function _callee10$(_context10) {
                  while (1) switch (_context10.prev = _context10.next) {
                    case 0:
                      _context10.t0 = expect;
                      _context10.next = 3;
                      return driver.isOpened();
                    case 3:
                      _context10.t1 = _context10.sent;
                      (0, _context10.t0)(_context10.t1).toBe(true);
                    case 5:
                    case "end":
                      return _context10.stop();
                  }
                }, _callee10);
              })));
            case 3:
            case "end":
              return _context11.stop();
          }
        }, _callee11);
      })));
      it('should close popover when close-button is clicked', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
        var _render7, driver;
        return _regeneratorRuntime.wrap(function _callee13$(_context13) {
          while (1) switch (_context13.prev = _context13.next) {
            case 0:
              _render7 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 96,
                  columnNumber: 35
                }
              }))), driver = _render7.driver;
              _context13.next = 3;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
                return _regeneratorRuntime.wrap(function _callee12$(_context12) {
                  while (1) switch (_context12.prev = _context12.next) {
                    case 0:
                      _context12.t0 = expect;
                      _context12.next = 3;
                      return driver.isTargetElementExists();
                    case 3:
                      _context12.t1 = _context12.sent;
                      return _context12.abrupt("return", (0, _context12.t0)(_context12.t1).toBe(true));
                    case 5:
                    case "end":
                      return _context12.stop();
                  }
                }, _callee12);
              })));
            case 3:
              _context13.next = 5;
              return driver.clickCloseButton();
            case 5:
              _context13.next = 7;
              return waitForClose(driver);
            case 7:
            case "end":
              return _context13.stop();
          }
        }, _callee13);
      })));
    });
    describe('programmatic open/close sanity', function () {
      it('should open and close programmatically', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
        var props, component, _render8, driver;
        return _regeneratorRuntime.wrap(function _callee17$(_context17) {
          while (1) switch (_context17.prev = _context17.next) {
            case 0:
              props = {
                initiallyOpened: false
              };
              _render8 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({
                ref: function ref(comp) {
                  return component = comp;
                }
              }, requiredProps, props, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 113,
                  columnNumber: 11
                }
              }))), driver = _render8.driver;
              _context17.next = 4;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
                return _regeneratorRuntime.wrap(function _callee14$(_context14) {
                  while (1) switch (_context14.prev = _context14.next) {
                    case 0:
                      _context14.t0 = expect;
                      _context14.next = 3;
                      return driver.isTargetElementExists();
                    case 3:
                      _context14.t1 = _context14.sent;
                      return _context14.abrupt("return", (0, _context14.t0)(_context14.t1).toBe(true));
                    case 5:
                    case "end":
                      return _context14.stop();
                  }
                }, _callee14);
              })));
            case 4:
              _context17.t0 = expect;
              _context17.next = 7;
              return driver.isOpened();
            case 7:
              _context17.t1 = _context17.sent;
              (0, _context17.t0)(_context17.t1).toBe(false);
              _context17.next = 11;
              return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
                return _regeneratorRuntime.wrap(function _callee15$(_context15) {
                  while (1) switch (_context15.prev = _context15.next) {
                    case 0:
                      component.open();
                    case 1:
                    case "end":
                      return _context15.stop();
                  }
                }, _callee15);
              })));
            case 11:
              _context17.t2 = expect;
              _context17.next = 14;
              return driver.isOpened();
            case 14:
              _context17.t3 = _context17.sent;
              (0, _context17.t2)(_context17.t3).toBe(true);
              _context17.next = 18;
              return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
                return _regeneratorRuntime.wrap(function _callee16$(_context16) {
                  while (1) switch (_context16.prev = _context16.next) {
                    case 0:
                      component.close();
                    case 1:
                    case "end":
                      return _context16.stop();
                  }
                }, _callee16);
              })));
            case 18:
              _context17.next = 20;
              return waitForClose(driver);
            case 20:
              _context17.t4 = expect;
              _context17.next = 23;
              return driver.isOpened();
            case 23:
              _context17.t5 = _context17.sent;
              (0, _context17.t4)(_context17.t5).toBe(false);
            case 25:
            case "end":
              return _context17.stop();
          }
        }, _callee17);
      })));
    });
    describe('controlled', function () {
      it('should call onClose but not close', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
        var props, _render9, driver;
        return _regeneratorRuntime.wrap(function _callee19$(_context19) {
          while (1) switch (_context19.prev = _context19.next) {
            case 0:
              props = {
                onClose: vi.fn(),
                opened: true
              };
              _render9 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, props, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 149,
                  columnNumber: 11
                }
              }))), driver = _render9.driver;
              _context19.next = 4;
              return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
                return _regeneratorRuntime.wrap(function _callee18$(_context18) {
                  while (1) switch (_context18.prev = _context18.next) {
                    case 0:
                      _context18.t0 = expect;
                      _context18.next = 3;
                      return driver.isTargetElementExists();
                    case 3:
                      _context18.t1 = _context18.sent;
                      return _context18.abrupt("return", (0, _context18.t0)(_context18.t1).toBe(true));
                    case 5:
                    case "end":
                      return _context18.stop();
                  }
                }, _callee18);
              })));
            case 4:
              _context19.next = 6;
              return driver.clickCloseButton();
            case 6:
              expect(props.onClose).toHaveBeenCalled();
              _context19.t0 = expect;
              _context19.next = 10;
              return driver.isOpened();
            case 10:
              _context19.t1 = _context19.sent;
              (0, _context19.t0)(_context19.t1).toBe(true);
            case 12:
            case "end":
              return _context19.stop();
          }
        }, _callee19);
      })));
      it('should not throw error when closeButton clicked and there is no onClose callback', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
        var props, _render0, driver, click;
        return _regeneratorRuntime.wrap(function _callee21$(_context21) {
          while (1) switch (_context21.prev = _context21.next) {
            case 0:
              props = {
                opened: true
              };
              _render0 = render(/*#__PURE__*/React.createElement(FloatingHelper, _extends({}, requiredProps, props, {
                __self: _this2,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 165,
                  columnNumber: 11
                }
              }))), driver = _render0.driver;
              click = /*#__PURE__*/function () {
                var _ref21 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
                  return _regeneratorRuntime.wrap(function _callee20$(_context20) {
                    while (1) switch (_context20.prev = _context20.next) {
                      case 0:
                        _context20.next = 2;
                        return driver.clickCloseButton();
                      case 2:
                        return _context20.abrupt("return", _context20.sent);
                      case 3:
                      case "end":
                        return _context20.stop();
                    }
                  }, _callee20);
                }));
                return function click() {
                  return _ref21.apply(this, arguments);
                };
              }();
              _context21.next = 5;
              return waitFor(function () {
                expect(click).not.toThrow();
              });
            case 5:
            case "end":
              return _context21.stop();
          }
        }, _callee21);
      })));
    });
  }
});