UNPKG

wix-style-react

Version:
429 lines (361 loc) • 14.2 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; 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 _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory, ReactBase } from '../../test/utils/unidriver'; import { DATA_HOOKS, DATA_ATTRIBUTES, SIZES, THEMES } from './constnats'; export var breadcrumbsUniDriverFactory = function breadcrumbsUniDriverFactory(base) { var optionAt = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(position) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", base.$("[data-hook=\"".concat(DATA_HOOKS.ITEM_WRAPPER, "-").concat(position, "\"]"))); case 1: case "end": return _context.stop(); } } }, _callee); })); return function optionAt(_x) { return _ref.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** * Gets number of breadcrumbs * @return {Promise<number>} */ breadcrumbsLength: function () { var _breadcrumbsLength = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return base.$$("[data-hook^=\"".concat(DATA_HOOKS.ITEM_WRAPPER, "-\"]")).count(); case 2: return _context2.abrupt("return", _context2.sent); case 3: case "end": return _context2.stop(); } } }, _callee2); })); function breadcrumbsLength() { return _breadcrumbsLength.apply(this, arguments); } return breadcrumbsLength; }(), /** * Gets breadcrumb content at position * @param {number} position Breadcrumb index * @return {Promise<string>} */ breadcrumbContentAt: function () { var _breadcrumbContentAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(position) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return optionAt(position); case 2: _context3.next = 4; return _context3.sent.text(); case 4: return _context3.abrupt("return", _context3.sent); case 5: case "end": return _context3.stop(); } } }, _callee3); })); function breadcrumbContentAt(_x2) { return _breadcrumbContentAt.apply(this, arguments); } return breadcrumbContentAt; }(), /** * Clicks on breadcrumb at position * @param {number} position Breadcrumb index * @return {Promise<void>} */ clickBreadcrumbAt: function () { var _clickBreadcrumbAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(position) { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: return _context4.abrupt("return", base.$("[data-hook^=\"".concat(DATA_HOOKS.BREADCRUMB_CLICKABLE, "-").concat(position, "\"]")).click()); case 1: case "end": return _context4.stop(); } } }, _callee4); })); function clickBreadcrumbAt(_x3) { return _clickBreadcrumbAt.apply(this, arguments); } return clickBreadcrumbAt; }(), /** * Gets the active breadcrumb position or null if no breadcrumb is active * @return {Promise<number | null>} */ getActiveItemId: function () { var _getActiveItemId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var activeItem; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return base.$$("[".concat(DATA_ATTRIBUTES.DATA_ACTIVE, "=\"true\"]")); case 2: activeItem = _context5.sent; _context5.next = 5; return activeItem.count(); case 5: _context5.t0 = _context5.sent; if (!(_context5.t0 === 1)) { _context5.next = 14; break; } _context5.t2 = parseInt; _context5.next = 10; return activeItem.get(0).attr(DATA_ATTRIBUTES.DATA_POSITION_ID); case 10: _context5.t3 = _context5.sent; _context5.t1 = (0, _context5.t2)(_context5.t3); _context5.next = 15; break; case 14: _context5.t1 = null; case 15: return _context5.abrupt("return", _context5.t1); case 16: case "end": return _context5.stop(); } } }, _callee5); })); function getActiveItemId() { return _getActiveItemId.apply(this, arguments); } return getActiveItemId; }(), /** * Checks whether breadcrumbs are size large * @return {Promise<boolean>} */ isLarge: function () { var _isLarge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return base.attr(DATA_ATTRIBUTES.DATA_SIZE); case 2: _context6.t0 = _context6.sent; _context6.t1 = SIZES.large; return _context6.abrupt("return", _context6.t0 === _context6.t1); case 5: case "end": return _context6.stop(); } } }, _callee6); })); function isLarge() { return _isLarge.apply(this, arguments); } return isLarge; }(), /** * Checks whether breadcrumbs are size medium * @return {Promise<boolean>} */ isMedium: function () { var _isMedium = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return base.attr(DATA_ATTRIBUTES.DATA_SIZE); case 2: _context7.t0 = _context7.sent; _context7.t1 = SIZES.medium; return _context7.abrupt("return", _context7.t0 === _context7.t1); case 5: case "end": return _context7.stop(); } } }, _callee7); })); function isMedium() { return _isMedium.apply(this, arguments); } return isMedium; }(), /** * Checks whether breadcrumbs are on white background * @return {Promise<boolean>} */ isOnWhiteBackground: function () { var _isOnWhiteBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return base.attr(DATA_ATTRIBUTES.DATA_THEME); case 2: _context8.t0 = _context8.sent; _context8.t1 = THEMES.onWhiteBackground; return _context8.abrupt("return", _context8.t0 === _context8.t1); case 5: case "end": return _context8.stop(); } } }, _callee8); })); function isOnWhiteBackground() { return _isOnWhiteBackground.apply(this, arguments); } return isOnWhiteBackground; }(), /** * Checks whether breadcrumbs are on gray background * @return {Promise<boolean>} */ isOnGrayBackground: function () { var _isOnGrayBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return base.attr(DATA_ATTRIBUTES.DATA_THEME); case 2: _context9.t0 = _context9.sent; _context9.t1 = THEMES.onGrayBackground; return _context9.abrupt("return", _context9.t0 === _context9.t1); case 5: case "end": return _context9.stop(); } } }, _callee9); })); function isOnGrayBackground() { return _isOnGrayBackground.apply(this, arguments); } return isOnGrayBackground; }(), /** * Checks whether breadcrumbs are on dark background * @return {Promise<boolean>} */ isOnDarkBackground: function () { var _isOnDarkBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() { return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return base.attr(DATA_ATTRIBUTES.DATA_THEME); case 2: _context10.t0 = _context10.sent; _context10.t1 = THEMES.onDarkBackground; return _context10.abrupt("return", _context10.t0 === _context10.t1); case 5: case "end": return _context10.stop(); } } }, _callee10); })); function isOnDarkBackground() { return _isOnDarkBackground.apply(this, arguments); } return isOnDarkBackground; }(), /** * Gets breadcrumb classes at index * @param position * @param {number} position Breadcrumb index * @return {Promise<string>} */ getLabelClassList: function () { var _getLabelClassList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(position) { var breadcrumbAt, breadcrumbItem, classList; return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return optionAt(position); case 2: breadcrumbAt = _context11.sent; breadcrumbItem = breadcrumbAt.$("[data-hook=\"".concat(DATA_HOOKS.BREADCRUMBS_ITEM, "\"]")); _context11.next = 6; return ReactBase(breadcrumbItem)._DEPRECATED_getClassList(); case 6: classList = _context11.sent; return _context11.abrupt("return", Array.from(classList).join(' ')); case 8: case "end": return _context11.stop(); } } }, _callee11); })); function getLabelClassList(_x4) { return _getLabelClassList.apply(this, arguments); } return getLabelClassList; }(), /** * Checks whether breadcrumb at index is active * @param {number} index Breadcrumb index * @return {Promise<boolean>} */ isActiveLinkAt: function () { var _isActiveLinkAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(index) { return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: _context12.next = 2; return optionAt(index); case 2: _context12.next = 4; return _context12.sent.$('a').exists(); case 4: return _context12.abrupt("return", _context12.sent); case 5: case "end": return _context12.stop(); } } }, _callee12); })); function isActiveLinkAt(_x5) { return _isActiveLinkAt.apply(this, arguments); } return isActiveLinkAt; }() }); };