UNPKG

wix-style-react

Version:
177 lines (150 loc) • 5.9 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _regeneratorRuntime from "@babel/runtime/regenerator"; 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 { baseUniDriverFactory, findByHook } from '../../test/utils/unidriver'; import { dataHooks } from './constants'; import { iconButtonDriverFactory } from '../IconButton/IconButton.uni.driver'; import { loaderUniDriverFactory } from '../Loader/Loader.uni.driver'; export var avatarUniDriverFactory = function avatarUniDriverFactory(base) { var getIndication = function getIndication() { return iconButtonDriverFactory(findByHook(base, dataHooks.indication)); }; var getLoader = function getLoader() { return loaderUniDriverFactory(findByHook(base, dataHooks.loader)); }; var getCustomIndication = function getCustomIndication() { return iconButtonDriverFactory(findByHook(base, dataHooks.customIndication)); }; return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** * Clicks on the Avatar element * @return {Promise<void>} */ click: function click() { return findByHook(base, dataHooks.avatarCore).click(); }, /** * Gets the content type * @returns {Promise<'text' | 'placeholder' | 'image'>} */ getContentType: function getContentType() { return base.attr('data-content-type'); }, /** * Gets the text content * @returns {Promise<string>} */ getTextContent: function () { var _getTextContent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return findByHook(base, dataHooks.textContainer).text(); case 2: return _context.abrupt("return", _context.sent); case 3: case "end": return _context.stop(); } } }, _callee); })); function getTextContent() { return _getTextContent.apply(this, arguments); } return getTextContent; }(), /** * Checks whether the image is loaded * @returns {Promise<boolean>} */ isImageLoaded: function () { var _isImageLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return base.attr('data-img-loaded'); case 2: _context2.t0 = _context2.sent; return _context2.abrupt("return", _context2.t0 === 'true'); case 4: case "end": return _context2.stop(); } } }, _callee2); })); function isImageLoaded() { return _isImageLoaded.apply(this, arguments); } return isImageLoaded; }(), /** * Hovers the component * @returns {Promise<void>} */ hover: function () { var _hover = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return findByHook(base, dataHooks.avatarWSR).hover(); case 2: return _context3.abrupt("return", _context3.sent); case 3: case "end": return _context3.stop(); } } }, _callee3); })); function hover() { return _hover.apply(this, arguments); } return hover; }(), /** * Checks whether the Avatar indication exists * @returns {Promise<boolean>} */ indicationExists: function indicationExists() { return getIndication().exists(); }, /** * Clicks the Avatar indication * @returns {Promise<void>} */ clickIndication: function clickIndication() { return getIndication().click(); }, /** * Checks whether the Avatar custom indication exists * @returns {Promise<boolean>} */ customIndicationExists: function customIndicationExists() { return getCustomIndication().exists(); }, /** * Clicks the Avatar custom indication * @returns {Promise<void>} */ clickCustomIndication: function clickCustomIndication() { return getCustomIndication().click(); }, /** * Checks whether the Avatar is loading * @returns {Promise<boolean>} */ isLoading: function isLoading() { return getLoader().exists(); } }); };