UNPKG

wix-style-react

Version:
194 lines (157 loc) • 6.53 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.avatarUniDriverFactory = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _unidriver = require("../../test/utils/unidriver"); var _constants = require("./constants"); var _IconButtonUni = require("../IconButton/IconButton.uni.driver"); var _LoaderUni = require("../Loader/Loader.uni.driver"); 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 avatarUniDriverFactory = function avatarUniDriverFactory(base) { var getIndication = function getIndication() { return (0, _IconButtonUni.iconButtonDriverFactory)((0, _unidriver.findByHook)(base, _constants.dataHooks.indication)); }; var getLoader = function getLoader() { return (0, _LoaderUni.loaderUniDriverFactory)((0, _unidriver.findByHook)(base, _constants.dataHooks.loader)); }; var getCustomIndication = function getCustomIndication() { return (0, _IconButtonUni.iconButtonDriverFactory)((0, _unidriver.findByHook)(base, _constants.dataHooks.customIndication)); }; return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { /** * Clicks on the Avatar element * @return {Promise<void>} */ click: function click() { return (0, _unidriver.findByHook)(base, _constants.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return (0, _unidriver.findByHook)(base, _constants.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 = (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 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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() { return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return (0, _unidriver.findByHook)(base, _constants.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(); } }); }; exports.avatarUniDriverFactory = avatarUniDriverFactory;