wix-style-react
Version:
wix-style-react
84 lines (83 loc) • 4.71 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _toArray = _interopRequireDefault(require("lodash/toArray"));
var _Radio = _interopRequireDefault(require("../Radio/Radio.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 radioGroupDriverFactory = _ref => {
var {
element,
eventTrigger
} = _ref;
var getOptionContainer = () => element.querySelector("[data-hook=\"".concat(_constants.dataHooks.RadioOptionContainer, "\"]"));
var getRadios = () => (0, _toArray.default)(element.querySelectorAll("[data-hook^=\"".concat(_constants.dataHooks.RadioContainer, "-\"] > :first-child"))).map(radio => radioButtonDriverFactory({
element: radio,
eventTrigger,
container: getOptionContainer
}));
var getRadioByIndex = index => getRadios()[index];
var getRadioByValue = value => radioButtonDriverFactory({
element: element.querySelector("[data-hook=\"".concat(_constants.dataHooks.RadioContainer, "-").concat(value, "\"] > :first-child")),
eventTrigger,
container: getOptionContainer
});
var getRadioContainerAt = index => element.querySelectorAll("[data-hook=\"".concat(_constants.dataHooks.RadioOptionContainer, "\"]"))[index];
var getLabelElements = () => getRadios().map(radio => radio.getLabelElement());
var getSelectedRadio = () => getRadios().find(radio => radio.isChecked());
return {
/** Checks that the element exists */
exists: () => !!element,
/** Selects the radio that matches the provided value */
selectByValue: value => getRadioByValue(value).click(),
/** Selects the radio at the provided index */
selectByIndex: index => getRadioByIndex(index).click(),
/** Get the radio value at the provided index */
getRadioValueAt: index => getRadioByIndex(index).getValue(),
/** Get the radio element in the provided index */
getRadioAtIndex: index => getRadios()[index],
/** Get the value of the selected radio */
getSelectedValue: () => {
var selected = getSelectedRadio();
return selected ? selected.getValue() : null;
},
/** Checks if the radio in the provided index is disabled */
isRadioDisabled: index => getRadios()[index].isDisabled(),
// TODO: We should deprecate getClassOfLabelAt(). Css tests should be in e2e tests.
/** Get the class of the label element at the provided index */
getClassOfLabelAt: index => getLabelElements()[index].className,
/** Checks if the display is set to vertical */
isVerticalDisplay: () => element.getAttribute(_constants.dataAttr.DISPLAY) === 'vertical',
/** Checks if the display is set to horizontal */
isHorizontalDisplay: () => element.getAttribute(_constants.dataAttr.DISPLAY) === 'horizontal',
/** Get the value of applied spacing between radios */
spacing: () => getRadioContainerAt(1).style._values['margin-top'],
/** Get the number of rendered radios */
getNumberOfRadios: () => getRadios().length,
/** Get the value of radio button id at the provided index */
getRadioIdAt: index => getRadioByIndex(index).getId(),
/** Get the value of radio button name at the provided index */
getRadioName: () => getRadioByIndex(0).getName(),
/** Checks if the radio with the provided index is checked */
isRadioChecked: index => getRadioByIndex(index).isChecked()
};
};
var radioButtonDriverFactory = _ref2 => {
var {
element,
eventTrigger,
container
} = _ref2;
return _objectSpread(_objectSpread({}, (0, _Radio.default)({
element,
eventTrigger
})), {}, {
/** Getting the component's content element */
getContent: () => container().querySelector("[data-hook=\"".concat(_constants.dataHooks.RadioContent, "\"]"))
});
};
var _default = exports.default = radioGroupDriverFactory;
//# sourceMappingURL=RadioGroup.driver.js.map