wix-style-react
Version:
wix-style-react
126 lines (125 loc) • 5.13 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.thumbnailDriverFactory = 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 _TextUni = require("../Text/Text.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 thumbnailDriverFactory = base => {
var byHook = hook => base.$("[data-hook*=\"".concat(hook, "\"]"));
var getThumbnailWrapper = () => byHook(_constants.dataHooks.thumbnailWrapper);
var getStyle = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)(function* (element, rule) {
return (yield element.attr('style')).match(new RegExp("".concat(rule, ": (.*?);")))[1];
});
return function getStyle(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
var _getTitle = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2.default)(function* () {
if (yield byHook(_constants.dataHooks.thumbnailTitle).exists()) {
return (0, _TextUni.textUniDriverFactory)(byHook(_constants.dataHooks.thumbnailTitle));
}
if (yield byHook(_constants.dataHooks.thumbnailBottomTitle).exists()) {
return (0, _TextUni.textUniDriverFactory)(byHook(_constants.dataHooks.thumbnailBottomTitle));
}
});
return function getTitle() {
return _ref2.apply(this, arguments);
};
}();
return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
/**
* Gets thumbnail title
* @returns {Promise<string>}
*/
getTitle: function () {
var _getTitle2 = (0, _asyncToGenerator2.default)(function* () {
return (yield _getTitle()).getText();
});
function getTitle() {
return _getTitle2.apply(this, arguments);
}
return getTitle;
}(),
/**
* Gets thumbnail description
* @returns {Promise<string>}
*/
getDescription: () => byHook(_constants.dataHooks.thumbnailDescription).text(),
/**
* Gets selected icon driver
* @returns {Promise<UniDriver>}
*/
getSelectedIcon: () => byHook(_constants.dataHooks.thumbnailSelectedIcon),
/**
* Gets background image driver
* @returns {Promise<UniDriver>}
*/
getBackgroundImage: () => byHook(_constants.dataHooks.thumbnailBackgroundImage),
/**
* Checks whether Thumbnail is selected
* @returns {Promise<boolean>}
*/
isSelected: function () {
var _isSelected = (0, _asyncToGenerator2.default)(function* () {
return (yield getThumbnailWrapper().attr('data-selected')) === 'true';
});
function isSelected() {
return _isSelected.apply(this, arguments);
}
return isSelected;
}(),
/**
* Checks whether Thumbnail is disabled
* @returns {Promise<boolean>}
*/
isDisabled: function () {
var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
return (yield getThumbnailWrapper().attr('data-disabled')) === 'true';
});
function isDisabled() {
return _isDisabled.apply(this, arguments);
}
return isDisabled;
}(),
/**
* Gets thumbnail image driver
* @returns {Promise<UniDriver>}
*/
getImage: () => byHook(_constants.dataHooks.thumbnailImage),
/**
* Gets thumbnail width, if it's set through `width` prop
* @returns {Promise<string>}
*/
getWidth: function () {
var _getWidth = (0, _asyncToGenerator2.default)(function* () {
return yield getStyle(base, 'width');
});
function getWidth() {
return _getWidth.apply(this, arguments);
}
return getWidth;
}(),
/**
* Gets thumbnail height, if it's set through `height` prop
* @returns {Promise<string>}
* */
getHeight: function () {
var _getHeight = (0, _asyncToGenerator2.default)(function* () {
return yield getStyle(yield getThumbnailWrapper(), 'height');
});
function getHeight() {
return _getHeight.apply(this, arguments);
}
return getHeight;
}()
});
};
exports.thumbnailDriverFactory = thumbnailDriverFactory;
//# sourceMappingURL=Thumbnail.uni.driver.js.map