UNPKG

wix-style-react

Version:
79 lines (62 loc) 2.57 kB
import ReactTestUtils from 'react-dom/test-utils'; import { isClassExists } from '../../test/utils'; var breadcrumbsDriverFactory = function breadcrumbsDriverFactory(_ref) { var element = _ref.element; var optionAt = function optionAt(position) { return element.childNodes[position]; }; return { exists: function exists() { return !!element; }, /** return the number of the items in the breadcrumbs */ breadcrumbsLength: function breadcrumbsLength() { return element.childNodes.length; }, /** return the breadcrumb item content at position */ breadcrumbContentAt: function breadcrumbContentAt(position) { return optionAt(position).textContent; }, /** click on breadcrumb item at position */ clickBreadcrumbAt: function clickBreadcrumbAt(position) { return ReactTestUtils.Simulate.click(optionAt(position).querySelector('[data-hook="breadcrumb-clickable"]')); }, /** return the active breadcrumb item position or return null if no active item exists */ getActiveItemId: function getActiveItemId() { var activeItem = element.querySelector('.active'); if (!activeItem) { return null; } return Array.from(activeItem.parentNode.children).indexOf(activeItem); }, /** fulfilled if breadcrumbs component is large */ isLarge: function isLarge() { return isClassExists(element, 'large'); }, /** fulfilled if breadcrumbs component is medium */ isMedium: function isMedium() { return isClassExists(element, 'medium'); }, /** fulfilled if breadcrumbs component is on white background */ isOnWhiteBackground: function isOnWhiteBackground() { return isClassExists(element, 'onWhiteBackground'); }, /** fulfilled if breadcrumbs component is on gray background */ isOnGrayBackground: function isOnGrayBackground() { return isClassExists(element, 'onGrayBackground'); }, /** fulfilled if breadcrumbs component is on dark background */ isOnDarkBackground: function isOnDarkBackground() { return isClassExists(element, 'onDarkBackground'); }, /** returns breadcrumbs component classes */ getLabelClassList: function getLabelClassList(position) { return optionAt(position).querySelector('[data-hook="breadcrumbs-item"]').className; }, /** returns true if the item is a link */ isActiveLinkAt: function isActiveLinkAt(index) { return !!optionAt(index).querySelector('a'); } }; }; export default breadcrumbsDriverFactory;