UNPKG

wix-style-react

Version:
299 lines (241 loc) • 9.65 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.modalUniDriverFactory = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _unidriver = require("../../test/utils/unidriver"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } var modalUniDriverFactory = function modalUniDriverFactory(base, body) { var getPortal = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { var dataHook; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return base.exists(); case 2: if (!_context.sent) { _context.next = 10; break; } _context.t0 = !!base.attr; if (!_context.t0) { _context.next = 8; break; } _context.next = 7; return base.attr('data-hook'); case 7: _context.t0 = _context.sent; case 8: dataHook = _context.t0; return _context.abrupt("return", dataHook ? body.$(".portal.portal-".concat(dataHook)) : body.$('.portal')); case 10: case "end": return _context.stop(); } } }, _callee); })); return function getPortal() { return _ref.apply(this, arguments); }; }(); var getOverlay = function getOverlay() { return body.$('.ReactModal__Overlay'); }; var _getContent = function getContent() { return body.$('.ReactModal__Content'); }; var getCloseButton = function getCloseButton() { return body.$('[data-hook="modal-close-button"]'); }; var isOpen = function isOpen() { return _getContent().exists(); }; return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { /** true if the modal is on the DOM */ exists: function () { var _exists = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return getPortal(); case 2: return _context2.abrupt("return", !!_context2.sent); case 3: case "end": return _context2.stop(); } } }, _callee2); })); function exists() { return _exists.apply(this, arguments); } return exists; }(), /** true when the module is open */ isOpen: isOpen, getChildBySelector: function () { var _getChildBySelector = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(selector) { var portal; return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return getPortal(); case 2: portal = _context3.sent; _context3.next = 5; return portal.$(selector).exists(); case 5: if (!_context3.sent) { _context3.next = 9; break; } _context3.t0 = portal.$(selector); _context3.next = 10; break; case 9: _context3.t0 = null; case 10: return _context3.abrupt("return", _context3.t0); case 11: case "end": return _context3.stop(); } } }, _callee3); })); function getChildBySelector(_x) { return _getChildBySelector.apply(this, arguments); } return getChildBySelector; }(), /** true if the modal is scrollable */ isScrollable: function () { var _isScrollable = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() { var content; return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return getPortal(); case 2: content = _context4.sent; _context4.next = 5; return content.$('[data-scrollable]').exists(); case 5: return _context4.abrupt("return", !!_context4.sent); case 6: case "end": return _context4.stop(); } } }, _callee4); })); function isScrollable() { return _isScrollable.apply(this, arguments); } return isScrollable; }(), closeButtonExists: function closeButtonExists() { return getCloseButton().exists(); }, /** click on the modal overlay (helpful for testing if the modal is dismissed) */ clickOnOverlay: function clickOnOverlay() { return getOverlay().click(); }, clickOnCloseButton: function clickOnCloseButton() { return getCloseButton().click(); }, /** returns the element of the modal content (helpful to initialize a layout testkit) */ // eslint-disable-next-line no-restricted-properties getContent: function () { var _getContent2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() { return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return _getContent().getNative(); case 2: return _context5.abrupt("return", _context5.sent); case 3: case "end": return _context5.stop(); } } }, _callee5); })); function getContent() { return _getContent2.apply(this, arguments); } return getContent; }(), /** returns the style of the modal content */ getContentStyle: function () { var _getContentStyle = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() { return _regenerator["default"].wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return _getContent()._prop('style'); case 2: return _context6.abrupt("return", _context6.sent); case 3: case "end": return _context6.stop(); } } }, _callee6); })); function getContentStyle() { return _getContentStyle.apply(this, arguments); } return getContentStyle; }(), /** returns the modal aria-label value as given in contentLabel property */ getContentLabel: function getContentLabel() { return _getContent().attr('aria-label'); }, getZIndex: function () { var _getZIndex = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() { var style; return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return getOverlay()._prop('style'); case 2: style = _context7.sent; return _context7.abrupt("return", style['z-index']); case 4: case "end": return _context7.stop(); } } }, _callee7); })); function getZIndex() { return _getZIndex.apply(this, arguments); } return getZIndex; }() }); }; exports.modalUniDriverFactory = modalUniDriverFactory;