UNPKG

wix-style-react

Version:
142 lines (120 loc) 4.51 kB
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'; import { dataHooks } from './constants'; export var radioUniDriverFactory = function radioUniDriverFactory(base, body) { var byHook = function byHook(hook) { return base.$("[data-hook=\"".concat(hook, "\"]")); }; var getInput = function getInput() { return byHook(dataHooks.input); }; var getIcon = function getIcon() { return byHook(dataHooks.icon); }; var getLabel = function getLabel() { return byHook(dataHooks.label); }; return _objectSpread(_objectSpread({}, baseUniDriverFactory(base, body)), {}, { /** /* Triggers a keyDown event on the radio input * @param {string} key * @return {Promise<void>} */ keyDown: function keyDown(key) { return getInput().pressKey(key); }, /** * Gets value of radio input * @return {Promise<string>} */ getValue: function getValue() { return getInput().attr('value'); }, /** * Gets name of radio input * @return {Promise<string>} */ getName: function getName() { return getInput().attr('name'); }, /** * Gets id of radio input * @return {Promise<string>} */ getId: function getId() { return getInput().attr('id'); }, /** * Checks if icon of radio exists * @return {Promise<boolean>} */ iconExists: function iconExists() { return getIcon().exists(); }, /** * Checks if label of radio exists * @return {Promise<boolean>} */ labelExists: function labelExists() { return getLabel().exists(); }, /** * Checks if radio is checked * @return {Promise<boolean>} */ isChecked: function () { var _isChecked = _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.attr('data-checked'); case 2: _context.t0 = _context.sent; return _context.abrupt("return", _context.t0 === 'true'); case 4: case "end": return _context.stop(); } } }, _callee); })); function isChecked() { return _isChecked.apply(this, arguments); } return isChecked; }(), /** * Checks if radio is disabled * @return {Promise<boolean>} */ isDisabled: function () { var _isDisabled = _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.attr('data-disabled'); case 2: _context2.t0 = _context2.sent; return _context2.abrupt("return", _context2.t0 === 'true'); case 4: case "end": return _context2.stop(); } } }, _callee2); })); function isDisabled() { return _isDisabled.apply(this, arguments); } return isDisabled; }() }); };