UNPKG

wix-style-react

Version:
554 lines (454 loc) • 17.8 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; 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) { _defineProperty(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; } import _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory } from 'wix-ui-test-utils/base-driver'; import { iconButtonDriverFactory } from '../IconButton/IconButton.uni.driver'; import { addItemUniDriverFactory } from '../AddItem/AddItem.uni.driver'; import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver'; import { dataAttributes, dataHooks } from './constants'; import { statusIndicatorDriverFactory } from '../StatusIndicator/StatusIndicator.uni.driver'; import { PopoverMenuDriver } from '../PopoverMenu/PopoverMenu.uni.driver'; export var imageViewerUniDriverFactory = function imageViewerUniDriverFactory(base, body) { var find = function find(dataHook) { return base.$("[data-hook=\"".concat(dataHook, "\"]")); }; var hasDataAttribute = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(dataAttr, el) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return el.attr(dataAttr); case 2: _context.t0 = _context.sent; return _context.abrupt("return", _context.t0 === 'true'); case 4: case "end": return _context.stop(); } } }, _callee); })); return function hasDataAttribute(_x, _x2) { return _ref.apply(this, arguments); }; }(); var hoverElement = function hoverElement() { return base.hover(); }; var showButtons = hoverElement; var isImagesContainerElementVisible = function isImagesContainerElementVisible() { return hasDataAttribute(dataAttributes.containerVisible, find(dataHooks.imagesContainer)); }; var isImageElementVisible = function isImageElementVisible(imgElement) { return hasDataAttribute(dataAttributes.imageVisible, imgElement); }; var addItemTestkit = addItemUniDriverFactory(find(dataHooks.addItem), body); var tooltipTestkit = function tooltipTestkit(dataHook) { return tooltipDriverFactory(find(dataHook), body); }; var iconButtonTestkit = function iconButtonTestkit(dataHook) { return iconButtonDriverFactory(find(dataHook)); }; var popoverMenuDriver = function popoverMenuDriver(dataHook) { return PopoverMenuDriver(find(dataHook), body); }; var removeIconButton = iconButtonTestkit(dataHooks.remove); var downloadIconButton = iconButtonTestkit(dataHooks.download); var updateIconButton = iconButtonTestkit(dataHooks.update); var moreIconButton = iconButtonTestkit(dataHooks.more); var updateTooltip = tooltipTestkit(dataHooks.updateTooltip); var downloadTooltip = tooltipTestkit(dataHooks.downloadTooltip); var removeTooltip = tooltipTestkit(dataHooks.removeTooltip); var moreTooltip = tooltipTestkit(dataHooks.moreTooltip); var getStatusIndicatorDriver = function getStatusIndicatorDriver() { return statusIndicatorDriverFactory(base.$("[data-hook=\"".concat(dataHooks.errorTooltip, "\"]")), body); }; var moreButtonExists = function moreButtonExists() { return moreIconButton.exists(); }; var clickMore = function clickMore() { return showButtons().then(function () { return moreIconButton.click(); }); }; return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { updateExists: function updateExists() { return !!find(dataHooks.update); }, updateButtonExists: function updateButtonExists() { return updateIconButton.exists(); }, removeButtonExists: function removeButtonExists() { return removeIconButton.exists(); }, downloadButtonExists: function downloadButtonExists() { return downloadIconButton.exists(); }, moreButtonExists: moreButtonExists, clickAdd: function clickAdd() { return addItemTestkit.click(); }, clickUpdate: function clickUpdate() { return showButtons().then(function () { return updateIconButton.click(); }); }, clickDownload: function () { var _clickDownload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var moreActions; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return showButtons(); case 2: _context2.next = 4; return moreButtonExists(); case 4: if (!_context2.sent) { _context2.next = 11; break; } _context2.next = 7; return clickMore(); case 7: moreActions = popoverMenuDriver(dataHooks.actionsMenu); return _context2.abrupt("return", moreActions.clickAtChild(0)); case 11: return _context2.abrupt("return", downloadIconButton.click()); case 12: case "end": return _context2.stop(); } } }, _callee2); })); function clickDownload() { return _clickDownload.apply(this, arguments); } return clickDownload; }(), clickRemove: function () { var _clickRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var moreActions; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return showButtons(); case 2: _context3.next = 4; return moreButtonExists(); case 4: if (!_context3.sent) { _context3.next = 11; break; } _context3.next = 7; return clickMore(); case 7: moreActions = popoverMenuDriver(dataHooks.actionsMenu); return _context3.abrupt("return", moreActions.clickAtChild(1)); case 11: return _context3.abrupt("return", removeIconButton.click()); case 12: case "end": return _context3.stop(); } } }, _callee3); })); function clickRemove() { return _clickRemove.apply(this, arguments); } return clickRemove; }(), getContainerStyles: function getContainerStyles() { return base.attr('style'); }, getAddTooltipContent: function getAddTooltipContent() { return addItemTestkit.getTooltipContent(); }, getUpdateTooltipContent: function getUpdateTooltipContent() { return updateTooltip.getTooltipText(); }, getDownloadTooltipContent: function getDownloadTooltipContent() { return downloadTooltip.getTooltipText(); }, getRemoveTooltipContent: function getRemoveTooltipContent() { return removeTooltip.getTooltipText(); }, getMoreTooltipContent: function getMoreTooltipContent() { return moreTooltip.getTooltipText(); }, isDisabled: function isDisabled() { return base.attr(dataAttributes.disabled).then(function (x) { return x === 'true'; }); }, isAddItemVisible: function isAddItemVisible() { return find(dataHooks.addItem).exists(); }, isLoaderVisible: function isLoaderVisible() { return find(dataHooks.loader).exists(); }, isImageLoaded: function isImageLoaded() { return base.$('[data-was-image-loaded]').exists(); }, isImageVisible: function () { var _isImageVisible = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var image; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: image = find(dataHooks.image); _context4.next = 3; return image.exists(); case 3: _context4.t2 = _context4.sent; if (!_context4.t2) { _context4.next = 8; break; } _context4.next = 7; return image.attr('src'); case 7: _context4.t2 = !!_context4.sent; case 8: _context4.t1 = _context4.t2; if (!_context4.t1) { _context4.next = 13; break; } _context4.next = 12; return isImageElementVisible(image); case 12: _context4.t1 = _context4.sent; case 13: _context4.t0 = _context4.t1; if (!_context4.t0) { _context4.next = 18; break; } _context4.next = 17; return isImagesContainerElementVisible(); case 17: _context4.t0 = _context4.sent; case 18: return _context4.abrupt("return", _context4.t0); case 19: case "end": return _context4.stop(); } } }, _callee4); })); function isImageVisible() { return _isImageVisible.apply(this, arguments); } return isImageVisible; }(), isPreviousImageVisible: function () { var _isPreviousImageVisible = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var previousImage; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: previousImage = find(dataHooks.previousImage); _context5.next = 3; return previousImage.exists(); case 3: _context5.t2 = _context5.sent; if (!_context5.t2) { _context5.next = 8; break; } _context5.next = 7; return previousImage.attr('src'); case 7: _context5.t2 = !!_context5.sent; case 8: _context5.t1 = _context5.t2; if (!_context5.t1) { _context5.next = 13; break; } _context5.next = 12; return isImageElementVisible(previousImage); case 12: _context5.t1 = _context5.sent; case 13: _context5.t0 = _context5.t1; if (!_context5.t0) { _context5.next = 18; break; } _context5.next = 17; return isImagesContainerElementVisible(); case 17: _context5.t0 = _context5.sent; case 18: return _context5.abrupt("return", _context5.t0); case 19: case "end": return _context5.stop(); } } }, _callee5); })); function isPreviousImageVisible() { return _isPreviousImageVisible.apply(this, arguments); } return isPreviousImageVisible; }(), getImageUrl: function () { var _getImageUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { var image; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: image = find(dataHooks.image); _context6.next = 3; return image.exists(); case 3: _context6.t0 = _context6.sent; if (!_context6.t0) { _context6.next = 8; break; } _context6.next = 7; return image.attr('src'); case 7: _context6.t0 = _context6.sent; case 8: return _context6.abrupt("return", _context6.t0); case 9: case "end": return _context6.stop(); } } }, _callee6); })); function getImageUrl() { return _getImageUrl.apply(this, arguments); } return getImageUrl; }(), getPreviousImageUrl: function () { var _getPreviousImageUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { var previousImage; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: previousImage = find(dataHooks.previousImage); _context7.next = 3; return previousImage.exists(); case 3: _context7.t0 = _context7.sent; if (!_context7.t0) { _context7.next = 8; break; } _context7.next = 7; return previousImage.attr('src'); case 7: _context7.t0 = _context7.sent; case 8: return _context7.abrupt("return", _context7.t0); case 9: case "end": return _context7.stop(); } } }, _callee7); })); function getPreviousImageUrl() { return _getPreviousImageUrl.apply(this, arguments); } return getPreviousImageUrl; }(), hover: hoverElement, // Status /** Return true if there's a status */ hasStatus: function () { var _hasStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(status) { var statusIndicatorDriver; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: statusIndicatorDriver = getStatusIndicatorDriver(); _context8.next = 3; return statusIndicatorDriver.exists(); case 3: if (!_context8.sent) { _context8.next = 9; break; } _context8.t0 = status; _context8.next = 7; return statusIndicatorDriver.getStatus(); case 7: _context8.t1 = _context8.sent; return _context8.abrupt("return", _context8.t0 === _context8.t1); case 9: return _context8.abrupt("return", false); case 10: case "end": return _context8.stop(); } } }, _callee8); })); function hasStatus(_x3) { return _hasStatus.apply(this, arguments); } return hasStatus; }(), /** If there's a status message, returns its text value */ getStatusMessage: function () { var _getStatusMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { var statusIndicatorDriver, tooltipText; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: statusIndicatorDriver = getStatusIndicatorDriver(); tooltipText = null; _context9.next = 4; return statusIndicatorDriver.hasMessage(); case 4: if (!_context9.sent) { _context9.next = 8; break; } _context9.next = 7; return statusIndicatorDriver.getMessage(); case 7: tooltipText = _context9.sent; case 8: return _context9.abrupt("return", tooltipText); case 9: case "end": return _context9.stop(); } } }, _callee9); })); function getStatusMessage() { return _getStatusMessage.apply(this, arguments); } return getStatusMessage; }() }); };