UNPKG

wix-style-react

Version:
38 lines (36 loc) 1.48 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import ReactTestUtils from 'react-dom/test-utils'; export var carouselDriverFactory = function carouselDriverFactory(_ref) { var element = _ref.element; // 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); }; return { exists: function exists() { return !!element; }, isLoading: function isLoading() { var loader = element.querySelector('[data-hook="loader"]'); return !!loader; }, getChildren: function getChildren() { return element.querySelectorAll(withoutClonedNodes()); }, getImages: function getImages() { // Converting the result from NodeList to a real array return _toConsumableArray(element.querySelectorAll(withoutClonedNodes('[data-hook="carousel-img"]'))).map(function (img) { return img.src; }); }, clickPrevious: function clickPrevious() { var prevButton = element.querySelector('[data-hook="prev-button"]'); ReactTestUtils.Simulate.click(prevButton); }, clickNext: function clickNext() { var nextButton = element.querySelector('[data-hook="next-button"]'); ReactTestUtils.Simulate.click(nextButton); } }; };