wix-style-react
Version:
wix-style-react
164 lines (163 loc) • 7.26 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.radioGroupUniDriverFactory = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../test-utils/utils/unidriver");
var _RadioUni = require("../Radio/Radio.uni.driver");
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var radioGroupUniDriverFactory = (base, body) => {
var getOptionContainer = () => base.$("[data-hook=\"".concat(_constants.dataHooks.RadioOptionContainer, "\"]"));
var getRadios = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)(function* () {
return yield base.$$("[data-hook^=\"".concat(_constants.dataHooks.RadioContainer, "-\"] > :first-child")).map(radio => radioButtonUniDriverFactory(radio, body, getOptionContainer));
});
return function getRadios() {
return _ref.apply(this, arguments);
};
}();
var getRadioByValue = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2.default)(function* (value) {
return radioButtonUniDriverFactory(base.$("[data-hook=\"".concat(_constants.dataHooks.RadioContainer, "-").concat(value, "\"] > :first-child")), body, getOptionContainer);
});
return function getRadioByValue(_x) {
return _ref2.apply(this, arguments);
};
}();
var getRadioByIndex = /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadios())[index];
});
return function getRadioByIndex(_x2) {
return _ref3.apply(this, arguments);
};
}();
var getSelectedRadio = /*#__PURE__*/function () {
var _ref4 = (0, _asyncToGenerator2.default)(function* () {
for (var radio of yield getRadios()) {
if (yield radio.isChecked()) {
return radio;
}
}
});
return function getSelectedRadio() {
return _ref4.apply(this, arguments);
};
}();
return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base, body)), {}, {
/** Selects the radio that matches the provided value */
selectByValue: function () {
var _selectByValue = (0, _asyncToGenerator2.default)(function* (value) {
return (yield getRadioByValue(value)).click();
});
function selectByValue(_x3) {
return _selectByValue.apply(this, arguments);
}
return selectByValue;
}(),
/** Selects the radio in the provided index */
selectByIndex: function () {
var _selectByIndex = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadioByIndex(index)).click();
});
function selectByIndex(_x4) {
return _selectByIndex.apply(this, arguments);
}
return selectByIndex;
}(),
/** Get the radio value in the provided index */
getRadioValueAt: function () {
var _getRadioValueAt = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadioByIndex(index)).getValue();
});
function getRadioValueAt(_x5) {
return _getRadioValueAt.apply(this, arguments);
}
return getRadioValueAt;
}(),
/** Get the radio element in the provided index, returns an element merged with the RadioButton driver methods */
getRadioAtIndex: function () {
var _getRadioAtIndex = (0, _asyncToGenerator2.default)(function* (index) {
return yield getRadioByIndex(index);
});
function getRadioAtIndex(_x6) {
return _getRadioAtIndex.apply(this, arguments);
}
return getRadioAtIndex;
}(),
/** Get the value of the selected radio */
getSelectedValue: function () {
var _getSelectedValue = (0, _asyncToGenerator2.default)(function* () {
var selected = yield getSelectedRadio();
return selected ? selected.getValue() : null;
});
function getSelectedValue() {
return _getSelectedValue.apply(this, arguments);
}
return getSelectedValue;
}(),
/** Checks if the radio in the provided index is disabled */
isRadioDisabled: function () {
var _isRadioDisabled = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadioByIndex(index)).isDisabled();
});
function isRadioDisabled(_x7) {
return _isRadioDisabled.apply(this, arguments);
}
return isRadioDisabled;
}(),
/** Get the number of rendered radios */
getNumberOfRadios: function () {
var _getNumberOfRadios = (0, _asyncToGenerator2.default)(function* () {
return (yield getRadios()).length;
});
function getNumberOfRadios() {
return _getNumberOfRadios.apply(this, arguments);
}
return getNumberOfRadios;
}(),
/** Get the value of radio button id at the provided index */
getRadioIdAt: function () {
var _getRadioIdAt = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadioByIndex(index)).getId();
});
function getRadioIdAt(_x8) {
return _getRadioIdAt.apply(this, arguments);
}
return getRadioIdAt;
}(),
/** Get the value of radio button name at the provided index */
getRadioName: function () {
var _getRadioName = (0, _asyncToGenerator2.default)(function* () {
return (yield getRadioByIndex(0)).getName();
});
function getRadioName() {
return _getRadioName.apply(this, arguments);
}
return getRadioName;
}(),
/** Checks if the radio with the provided index is checked */
isRadioChecked: function () {
var _isRadioChecked = (0, _asyncToGenerator2.default)(function* (index) {
return (yield getRadioByIndex(index)).isChecked();
});
function isRadioChecked(_x9) {
return _isRadioChecked.apply(this, arguments);
}
return isRadioChecked;
}()
});
};
exports.radioGroupUniDriverFactory = radioGroupUniDriverFactory;
var radioButtonUniDriverFactory = (base, body, container) => {
return _objectSpread(_objectSpread({}, (0, _RadioUni.radioUniDriverFactory)(base, body)), {}, {
/** Getting the component's content element */
getContent: () =>
// eslint-disable-next-line no-restricted-properties
container().$("[data-hook=\"".concat(_constants.dataHooks.RadioContent, "\"]")).getNative()
});
};
//# sourceMappingURL=RadioGroup.uni.driver.js.map