wix-style-react
Version:
86 lines (73 loc) • 3.42 kB
JavaScript
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 } from '../../test/utils/unidriver'; // It turns out that react-slick duplicates the children, so we ditch the cloned nodes
var withoutClonedNodes = function withoutClonedNodes() {
var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return ".slick-slide:not(.slick-cloned) ".concat(selector);
};
export var carouselUniDriverFactory = function carouselUniDriverFactory(base) {
return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, {
/**
* Checks whether the carousel is loading
* @return {Promise<boolean>}
*/
isLoading: function () {
var _isLoading = _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 base.$$('[data-hook="loader"]').count();
case 2:
_context.t0 = _context.sent;
return _context.abrupt("return", _context.t0 > 0);
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function isLoading() {
return _isLoading.apply(this, arguments);
}
return isLoading;
}(),
/**
* Gets children list elements
* @return {UniDriverList}
*/
getChildren: function getChildren() {
return base.$$(withoutClonedNodes()).map(function (child) {
return child;
});
},
/**
* Get a list of the carousel images
* @return {Promise<Array<string | null>>}
*/
getImages: function getImages() {
return base.$$(withoutClonedNodes('[data-hook="carousel-img"]')).map(function (img) {
return img.attr('src');
});
},
/**
* Click on the previous item button
* @return {Promise<void>}
*/
clickPrevious: function clickPrevious() {
return base.$('[data-hook="prev-button"]').click();
},
/**
* Click on the next item button
* @return {Promise<void>}
*/
clickNext: function clickNext() {
return base.$('[data-hook="next-button"]').click();
}
});
};