UNPKG

wix-style-react

Version:
127 lines (126 loc) • 6.12 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.modalUniDriverFactory = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _unidriver = require("../test-utils/utils/unidriver"); var _TooltipUni = require("../Tooltip/Tooltip.uni.driver"); var _constants = require("./constants"); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var modalUniDriverFactory = (base, body) => { var getPortal = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)(function* () { if (yield base.exists()) { var dataHook = !!base.attr && (yield base.attr('data-hook')); return dataHook ? body.$(".portal.portal-".concat(dataHook)) : body.$('.portal'); } }); return function getPortal() { return _ref.apply(this, arguments); }; }(); var getOverlay = () => body.$('.ReactModal__Overlay'); var _getContent = () => body.$('.ReactModal__Content'); var getCloseButton = () => body.$("[data-hook=\"".concat(_constants.dataHooks.modalCloseButton, "\"]")); var getNavigationPrevious = () => body.$("[data-hook=\"".concat(_constants.dataHooks.navigationPrevButton, "\"]")); var getNavigationNext = () => body.$("[data-hook=\"".concat(_constants.dataHooks.navigationNextButton, "\"]")); var isOpen = () => _getContent().exists(); return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { /** true if the modal is on the DOM */ exists: function () { var _exists = (0, _asyncToGenerator2.default)(function* () { return !!(yield getPortal()); }); function exists() { return _exists.apply(this, arguments); } return exists; }(), /** true when the module is open */ isOpen, getChildBySelector: function () { var _getChildBySelector = (0, _asyncToGenerator2.default)(function* (selector) { var portal = yield getPortal(); return (yield portal.$(selector).exists()) ? portal.$(selector) : null; }); function getChildBySelector(_x) { return _getChildBySelector.apply(this, arguments); } return getChildBySelector; }(), /** true if the modal is scrollable */ isScrollable: function () { var _isScrollable = (0, _asyncToGenerator2.default)(function* () { var content = yield getPortal(); return !!(yield content.$('[data-scrollable]').exists()); }); function isScrollable() { return _isScrollable.apply(this, arguments); } return isScrollable; }(), closeButtonExists: () => getCloseButton().exists(), /** click on the modal overlay (helpful for testing if the modal is dismissed) */ clickOnOverlay: () => getOverlay().click(), clickOnCloseButton: () => getCloseButton().click(), /** click on navigation control previous button */ clickOnNavigationPrevious: () => getNavigationPrevious().click(), /** click on navigation control next button */ clickOnNavigationNext: () => getNavigationNext().click(), navigationPreviousExists: () => getNavigationPrevious().exists(), navigationNextExists: () => getNavigationNext().exists(), getNavigationPreviousLabel: () => { var tooltip = (0, _TooltipUni.tooltipDriverFactory)(body.$("[data-hook=\"".concat(_constants.dataHooks.navigationPrevTooltip, "\"]")), body); return tooltip.getTooltipText(); }, getNavigationNextLabel: () => { var tooltip = (0, _TooltipUni.tooltipDriverFactory)(body.$("[data-hook=\"".concat(_constants.dataHooks.navigationNextTooltip, "\"]")), body); return tooltip.getTooltipText(); }, /** 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)(function* () { return yield _getContent().getNative(); }); function getContent() { return _getContent2.apply(this, arguments); } return getContent; }(), /** returns the style of the modal content */ getContentStyle: function () { var _getContentStyle = (0, _asyncToGenerator2.default)(function* () { return yield _getContent()._prop('style'); }); function getContentStyle() { return _getContentStyle.apply(this, arguments); } return getContentStyle; }(), /** returns the modal aria-label value as given in contentLabel property */ getContentLabel: function () { var _getContentLabel = (0, _asyncToGenerator2.default)(function* () { return yield _getContent().attr('aria-label'); }); function getContentLabel() { return _getContentLabel.apply(this, arguments); } return getContentLabel; }(), getZIndex: function () { var _getZIndex = (0, _asyncToGenerator2.default)(function* () { var style = yield getOverlay()._prop('style'); return style['z-index']; }); function getZIndex() { return _getZIndex.apply(this, arguments); } return getZIndex; }() }); }; exports.modalUniDriverFactory = modalUniDriverFactory; //# sourceMappingURL=Modal.uni.driver.js.map