"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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _react2 = require("../utils/test-utils/react");
var _Page = _interopRequireDefault(require("./Page"));
var _PagePrivateUni = require("./Page.private.uni.driver");
var _PageScrollContext = require("./PageScrollContext");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Page/Page.spec.jsx",
  _this = void 0;
var Content = function Content() {
  return /*#__PURE__*/_react["default"].createElement("div", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 11,
      columnNumber: 23
    }
  }, "content");
};
var Tail = function Tail() {
  return /*#__PURE__*/_react["default"].createElement("div", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 13,
      columnNumber: 20
    }
  }, "tail");
};
var renderPageWithProps = function renderPageWithProps() {
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return /*#__PURE__*/_react["default"].createElement(_Page["default"], (0, _extends2["default"])({}, props, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 16,
      columnNumber: 3
    }
  }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Header, {
    title: "title",
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 17,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Content, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 18,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react["default"].createElement(Content, {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 19,
      columnNumber: 7
    }
  })));
};
describe('Page', function () {
  var render = (0, _react2.createRendererWithUniDriver)(_PagePrivateUni.pagePrivateUniDriverFactory);
  var stub = console.error = vi.fn();
  afterEach(function () {
    vi.resetModules();
    stub.mockReset();
  });
  afterEach(function () {
    return (0, _react2.cleanup)();
  });
  it('should initialize component', /*#__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(renderPageWithProps()), driver = _render.driver;
          _context.t0 = expect;
          _context.next = 4;
          return driver.exists();
        case 4:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  describe('PageContext', function () {
    it('should expose scroll element via context', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
      var onScrollSpy, InternalComponent, _render2, driver;
      return _regenerator["default"].wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            InternalComponent = function _InternalComponent() {
              var _usePageScrollContext = (0, _PageScrollContext.usePageScrollContext)(),
                scrollableContentRef = _usePageScrollContext.scrollableContentRef;
              _react["default"].useEffect(function () {
                var handleScroll = function handleScroll(event) {
                  onScrollSpy(event);
                };
                var scrollableContent = scrollableContentRef.current;
                if (scrollableContent) {
                  scrollableContent.addEventListener('scroll', handleScroll);
                }
                return function () {
                  if (scrollableContent) {
                    scrollableContent.removeEventListener('scroll', handleScroll);
                  }
                };
              }, [scrollableContentRef]);
              return /*#__PURE__*/_react["default"].createElement("div", {
                "data-hook": "internal-component",
                __self: this,
                __source: {
                  fileName: _jsxFileName,
                  lineNumber: 65,
                  columnNumber: 16
                }
              });
            };
            onScrollSpy = vi.fn();
            _render2 = render(/*#__PURE__*/_react["default"].createElement(_Page["default"], {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 69,
                columnNumber: 9
              }
            }, /*#__PURE__*/_react["default"].createElement(_Page["default"].Header, {
              title: "title",
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 70,
                columnNumber: 11
              }
            }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Content, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 71,
                columnNumber: 11
              }
            }, /*#__PURE__*/_react["default"].createElement(InternalComponent, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 72,
                columnNumber: 13
              }
            })))), driver = _render2.driver;
            _context2.next = 5;
            return driver.scrollableContainer._scrollContentTo({
              y: 10
            });
          case 5:
            expect(onScrollSpy).toHaveBeenCalledTimes(1);
          case 6:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    })));
  });
  describe('Page.Header sticky', function () {
    it('should contain a wrapping div that fixes sticky issue for safari 12, 13', function () {
      var _render3 = render(renderPageWithProps({})),
        container = _render3.container;
      var magicFixWrapperExists = !!container.querySelector('[data-hook="safari-12-13-sticky-fix"]');
      expect(magicFixWrapperExists).toBe(true);
    });
  });
  describe('backgroundImage', function () {
    it('should initialize component with background image', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
      var _render4, driver;
      return _regenerator["default"].wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            _render4 = render(renderPageWithProps({
              backgroundImageUrl: '/some/image'
            })), driver = _render4.driver;
            _context3.t0 = expect;
            _context3.next = 4;
            return driver.backgroundImageExists();
          case 4:
            _context3.t1 = _context3.sent;
            (0, _context3.t0)(_context3.t1).toBe(true);
          case 6:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    })));
    it('should not initialize component with background image', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
      var _render5, driver;
      return _regenerator["default"].wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            _render5 = render(renderPageWithProps()), driver = _render5.driver;
            _context4.t0 = expect;
            _context4.next = 4;
            return driver.backgroundImageExists();
          case 4:
            _context4.t1 = _context4.sent;
            (0, _context4.t0)(_context4.t1).toBe(false);
          case 6:
          case "end":
            return _context4.stop();
        }
      }, _callee4);
    })));
  });
  describe('customClassName', function () {
    it('should have custom className', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5() {
      var _render6, driver;
      return _regenerator["default"].wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _render6 = render(renderPageWithProps({
              className: 'myClass'
            })), driver = _render6.driver;
            _context5.t0 = expect;
            _context5.next = 4;
            return driver.hasClass('myClass');
          case 4:
            _context5.t1 = _context5.sent;
            (0, _context5.t0)(_context5.t1).toBe(true);
          case 6:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })));
  });
  describe('gradientClassName', function () {
    it('should initialize component with gradient class name', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
      var _render7, driver;
      return _regenerator["default"].wrap(function _callee6$(_context6) {
        while (1) switch (_context6.prev = _context6.next) {
          case 0:
            _render7 = render(renderPageWithProps({
              gradientClassName: 'class'
            })), driver = _render7.driver;
            _context6.t0 = expect;
            _context6.next = 4;
            return driver.gradientClassNameExists();
          case 4:
            _context6.t1 = _context6.sent;
            (0, _context6.t0)(_context6.t1).toBe(true);
          case 6:
          case "end":
            return _context6.stop();
        }
      }, _callee6);
    })));
    it('should not initialize component with gradient class name by default', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
      var _render8, driver;
      return _regenerator["default"].wrap(function _callee7$(_context7) {
        while (1) switch (_context7.prev = _context7.next) {
          case 0:
            _render8 = render(renderPageWithProps()), driver = _render8.driver;
            _context7.t0 = expect;
            _context7.next = 4;
            return driver.gradientClassNameExists();
          case 4:
            _context7.t1 = _context7.sent;
            (0, _context7.t0)(_context7.t1).toBe(false);
          case 6:
          case "end":
            return _context7.stop();
        }
      }, _callee7);
    })));
  });
  describe('gradient size', function () {
    it('should be 36px by default', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8() {
      var _render9, driver;
      return _regenerator["default"].wrap(function _callee8$(_context8) {
        while (1) switch (_context8.prev = _context8.next) {
          case 0:
            _render9 = render(renderPageWithProps({
              gradientClassName: 'class'
            })), driver = _render9.driver;
            _context8.t0 = expect;
            _context8.next = 4;
            return driver.gradientContainerHeight();
          case 4:
            _context8.t1 = _context8.sent;
            (0, _context8.t0)(_context8.t1).toBe('36px');
          case 6:
          case "end":
            return _context8.stop();
        }
      }, _callee8);
    })));
    it('should not render 0 when maximized but header height delta is 0', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9() {
      var _render0, driver;
      return _regenerator["default"].wrap(function _callee9$(_context9) {
        while (1) switch (_context9.prev = _context9.next) {
          case 0:
            _render0 = render(renderPageWithProps()), driver = _render0.driver;
            _context9.t0 = expect;
            _context9.next = 4;
            return driver.getPageHtml();
          case 4:
            _context9.t1 = _context9.sent;
            (0, _context9.t0)(_context9.t1).not.toContain('>0<');
          case 6:
          case "end":
            return _context9.stop();
        }
      }, _callee9);
    })));
    it('should be zero when Tail exist', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0() {
      var props, _render1, driver;
      return _regenerator["default"].wrap(function _callee0$(_context0) {
        while (1) switch (_context0.prev = _context0.next) {
          case 0:
            props = {
              gradientClassName: 'class'
            };
            _render1 = render(/*#__PURE__*/_react["default"].createElement(_Page["default"], (0, _extends2["default"])({}, props, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 145,
                columnNumber: 9
              }
            }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Header, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 146,
                columnNumber: 11
              }
            }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Tail, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 147,
                columnNumber: 11
              }
            }, /*#__PURE__*/_react["default"].createElement(Tail, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 148,
                columnNumber: 13
              }
            })), /*#__PURE__*/_react["default"].createElement(_Page["default"].Content, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 150,
                columnNumber: 11
              }
            }, /*#__PURE__*/_react["default"].createElement(Content, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 151,
                columnNumber: 13
              }
            })))), driver = _render1.driver;
            _context0.t0 = expect;
            _context0.next = 5;
            return driver.gradientContainerHeight();
          case 5:
            _context0.t1 = _context0.sent;
            (0, _context0.t0)(_context0.t1).toBe('0px');
          case 7:
          case "end":
            return _context0.stop();
        }
      }, _callee0);
    })));
  });
  describe('Page.Tail', function () {
    it('should attach a tail component', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1() {
      var _render10, driver;
      return _regenerator["default"].wrap(function _callee1$(_context1) {
        while (1) switch (_context1.prev = _context1.next) {
          case 0:
            _render10 = render(/*#__PURE__*/_react["default"].createElement(_Page["default"], {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 162,
                columnNumber: 9
              }
            }, /*#__PURE__*/_react["default"].createElement(_Page["default"].Header, {
              title: "title",
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 163,
                columnNumber: 11
              }
            }), /*#__PURE__*/_react["default"].createElement(_Page["default"].Tail, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 164,
                columnNumber: 11
              }
            }, /*#__PURE__*/_react["default"].createElement(Tail, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 165,
                columnNumber: 13
              }
            })), /*#__PURE__*/_react["default"].createElement(_Page["default"].Content, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 167,
                columnNumber: 11
              }
            }, /*#__PURE__*/_react["default"].createElement(Content, {
              __self: _this,
              __source: {
                fileName: _jsxFileName,
                lineNumber: 168,
                columnNumber: 13
              }
            })))), driver = _render10.driver;
            _context1.t0 = expect;
            _context1.next = 4;
            return driver.tailExists();
          case 4:
            _context1.t1 = _context1.sent;
            (0, _context1.t0)(_context1.t1).toBe(true);
          case 6:
          case "end":
            return _context1.stop();
        }
      }, _callee1);
    })));
    it('should not attach a tail component', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10() {
      var _render11, driver;
      return _regenerator["default"].wrap(function _callee10$(_context10) {
        while (1) switch (_context10.prev = _context10.next) {
          case 0:
            _render11 = render(renderPageWithProps()), driver = _render11.driver;
            _context10.t0 = expect;
            _context10.next = 4;
            return driver.tailExists();
          case 4:
            _context10.t1 = _context10.sent;
            (0, _context10.t0)(_context10.t1).toBe(false);
          case 6:
          case "end":
            return _context10.stop();
        }
      }, _callee10);
    })));
  });
  describe('DOM calculations', function () {
    it.skip('should recalculate component heights when re-rendered', function () {
      // TODO:
    });
  });
  describe('Header layer', function () {
    it('should NOT block clicks on content close to header', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11() {
      return _regenerator["default"].wrap(function _callee11$(_context11) {
        while (1) switch (_context11.prev = _context11.next) {
          case 0:
          case "end":
            return _context11.stop();
        }
      }, _callee11);
    })));
    it('should NOT block clicks on content close to header when MiniHeader appears', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12() {
      return _regenerator["default"].wrap(function _callee12$(_context12) {
        while (1) switch (_context12.prev = _context12.next) {
          case 0:
          case "end":
            return _context12.stop();
        }
      }, _callee12);
    })));
  });
});