UNPKG

wix-style-react

Version:
527 lines (437 loc) • 16.9 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 } from 'wix-ui-test-utils/base-driver'; import { findBaseByHook } from '../../test/utils'; import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver'; import { loaderUniDriverFactory } from '../Loader/Loader.uni.driver'; import { trendIndicatorDriverFactory } from '../TrendIndicator/TrendIndicator.uni.driver'; import { adaptiveHeadingDriverFactory } from '../utils/AdaptiveHeading/AdaptiveHeading.uni.driver'; import DataHooks from './dataHooks'; var statisticsWidgetDriverFactory = function statisticsWidgetDriverFactory(base, body) { var getHookSelector = function getHookSelector(hook) { return "[data-hook=\"".concat(hook, "\"]"); }; var getStatsItem = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(index) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", base.$$(getHookSelector(DataHooks.stat)).get(index)); case 1: case "end": return _context.stop(); } } }, _callee); })); return function getStatsItem(_x) { return _ref.apply(this, arguments); }; }(); var getTooltipDriver = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index) { var item, tooltip; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return getStatsItem(index); case 2: item = _context2.sent; _context2.next = 5; return item.$(getHookSelector(DataHooks.tooltip)); case 5: tooltip = _context2.sent; return _context2.abrupt("return", tooltipDriverFactory(tooltip, body)); case 7: case "end": return _context2.stop(); } } }, _callee2); })); return function getTooltipDriver(_x2) { return _ref2.apply(this, arguments); }; }(); var getTrendIndicatorDriver = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(index) { var item, tooltip; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return getStatsItem(index); case 2: item = _context3.sent; _context3.next = 5; return item.$(getHookSelector(DataHooks.percentage)); case 5: tooltip = _context3.sent; return _context3.abrupt("return", trendIndicatorDriverFactory(tooltip, body)); case 7: case "end": return _context3.stop(); } } }, _callee3); })); return function getTrendIndicatorDriver(_x3) { return _ref3.apply(this, arguments); }; }(); var getAdaptiveHeadingDriver = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(index) { var item, heading; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return getStatsItem(index); case 2: item = _context4.sent; _context4.next = 5; return item.$(getHookSelector(DataHooks.value)); case 5: heading = _context4.sent; return _context4.abrupt("return", adaptiveHeadingDriverFactory(heading)); case 7: case "end": return _context4.stop(); } } }, _callee4); })); return function getAdaptiveHeadingDriver(_x4) { return _ref4.apply(this, arguments); }; }(); var getLoaderDriver = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(index) { var item, loader; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return getStatsItem(index); case 2: item = _context5.sent; _context5.next = 5; return item.$(getHookSelector(DataHooks.loader)); case 5: loader = _context5.sent; return _context5.abrupt("return", loaderUniDriverFactory(loader)); case 7: case "end": return _context5.stop(); } } }, _callee5); })); return function getLoaderDriver(_x5) { return _ref5.apply(this, arguments); }; }(); var getStatsPartText = /*#__PURE__*/function () { var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(index, hook) { var node; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.t0 = findBaseByHook; _context6.next = 3; return getStatsItem(index); case 3: _context6.t1 = _context6.sent; _context6.t2 = hook; node = (0, _context6.t0)(_context6.t1, _context6.t2); _context6.next = 8; return node.exists(); case 8: if (_context6.sent) { _context6.next = 10; break; } return _context6.abrupt("return", null); case 10: _context6.next = 12; return node.text(); case 12: return _context6.abrupt("return", _context6.sent); case 13: case "end": return _context6.stop(); } } }, _callee6); })); return function getStatsPartText(_x6, _x7) { return _ref6.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** Get number of items */ getItemsCount: function () { var _getItemsCount = _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.$$(getHookSelector(DataHooks.stat)).count(); case 2: return _context7.abrupt("return", _context7.sent); case 3: case "end": return _context7.stop(); } } }, _callee7); })); function getItemsCount() { return _getItemsCount.apply(this, arguments); } return getItemsCount; }(), /** Click on the statistic with index */ clickStatistics: function () { var _clickStatistics = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(index) { var item; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return getStatsItem(index); case 2: item = _context8.sent; return _context8.abrupt("return", item.click()); case 4: case "end": return _context8.stop(); } } }, _callee8); })); function clickStatistics(_x8) { return _clickStatistics.apply(this, arguments); } return clickStatistics; }(), /** Get value of the statistic with index */ getValue: function () { var _getValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(index) { var heading; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return getAdaptiveHeadingDriver(index); case 2: heading = _context9.sent; return _context9.abrupt("return", heading.getText()); case 4: case "end": return _context9.stop(); } } }, _callee9); })); function getValue(_x9) { return _getValue.apply(this, arguments); } return getValue; }(), /** * Returns true if statistic item is in loading state * @param index: number */ isLoading: function () { var _isLoading = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(index) { var loader; return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return getLoaderDriver(index); case 2: loader = _context10.sent; return _context10.abrupt("return", loader.isLoading()); case 4: case "end": return _context10.stop(); } } }, _callee10); })); function isLoading(_x10) { return _isLoading.apply(this, arguments); } return isLoading; }(), /** Get short value of the stat with index */ getValueInShort: function () { var _getValueInShort = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(index) { var heading; return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return getAdaptiveHeadingDriver(index); case 2: heading = _context11.sent; return _context11.abrupt("return", heading.getShortText()); case 4: case "end": return _context11.stop(); } } }, _callee11); })); function getValueInShort(_x11) { return _getValueInShort.apply(this, arguments); } return getValueInShort; }(), /** Get description of the statistic with index */ getDescription: function () { var _getDescription = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(index) { return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: return _context12.abrupt("return", getStatsPartText(index, DataHooks.description)); case 1: case "end": return _context12.stop(); } } }, _callee12); })); function getDescription(_x12) { return _getDescription.apply(this, arguments); } return getDescription; }(), /** Get the text of the info tooltip */ getDescriptionInfo: function () { var _getDescriptionInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(index) { var tooltip, text; return _regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: _context13.next = 2; return getTooltipDriver(index); case 2: tooltip = _context13.sent; _context13.next = 5; return tooltip.exists(); case 5: if (_context13.sent) { _context13.next = 7; break; } return _context13.abrupt("return", null); case 7: _context13.next = 9; return tooltip.mouseEnter(); case 9: _context13.next = 11; return tooltip.getTooltipText(); case 11: text = _context13.sent; _context13.next = 14; return tooltip.mouseLeave(); case 14: return _context13.abrupt("return", text); case 15: case "end": return _context13.stop(); } } }, _callee13); })); function getDescriptionInfo(_x13) { return _getDescriptionInfo.apply(this, arguments); } return getDescriptionInfo; }(), /** Get children in section by hook */ getChildren: function () { var _getChildren = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(index, hook) { return _regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _context14.t0 = findBaseByHook; _context14.next = 3; return getStatsItem(index); case 3: _context14.t1 = _context14.sent; _context14.t2 = hook; return _context14.abrupt("return", (0, _context14.t0)(_context14.t1, _context14.t2)); case 6: case "end": return _context14.stop(); } } }, _callee14); })); function getChildren(_x14, _x15) { return _getChildren.apply(this, arguments); } return getChildren; }(), /** Get percentage of the statistic with index */ getPercentage: function () { var _getPercentage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(index) { var trendIndicator; return _regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: _context15.next = 2; return getTrendIndicatorDriver(index); case 2: trendIndicator = _context15.sent; _context15.next = 5; return trendIndicator.exists(); case 5: if (_context15.sent) { _context15.next = 7; break; } return _context15.abrupt("return", null); case 7: _context15.next = 9; return trendIndicator.getTrendValue(); case 9: return _context15.abrupt("return", _context15.sent); case 10: case "end": return _context15.stop(); } } }, _callee15); })); function getPercentage(_x16) { return _getPercentage.apply(this, arguments); } return getPercentage; }() }); }; export default statisticsWidgetDriverFactory;