UNPKG

wix-style-react

Version:
73 lines (69 loc) 2.39 kB
import ReactTestUtils from 'react-dom/test-utils'; import toArray from 'lodash/toArray'; import { isClassExists } from '../../test/utils'; var radioGroupDriverFactory = function radioGroupDriverFactory(_ref) { var element = _ref.element; var radios = toArray(element.children) || []; var radioButtons = radios.map(function (radio) { return radio.childNodes[0]; }); var labels = radios.map(function (radio) { return radio.childNodes[1]; }); var selectedRadio = function selectedRadio() { return radios.find(function (radio) { return radio.childNodes[0].checked; }); }; var getRadioByValue = function getRadioByValue(value) { return radioButtons.find(function (radioButton) { return radioButton.value === value.toString(); }); }; return { exists: function exists() { return !!element; }, selectByValue: function selectByValue(value) { return ReactTestUtils.Simulate.change(getRadioByValue(value)); }, selectByIndex: function selectByIndex(index) { return ReactTestUtils.Simulate.change(radioButtons[index]); }, getRadioValueAt: function getRadioValueAt(index) { return radioButtons[index].value; }, getRadioAtIndex: function getRadioAtIndex(index) { return radios[index]; }, getSelectedValue: function getSelectedValue() { return selectedRadio() ? selectedRadio().childNodes[0].value : null; }, isRadioDisabled: function isRadioDisabled(index) { return radioButtons[index].disabled; }, // TODO: We should deprecate getClassOfLabelAt(). Css tests should be in e2e tests. getClassOfLabelAt: function getClassOfLabelAt(index) { return labels[index].className; }, isVerticalDisplay: function isVerticalDisplay() { return isClassExists(element, 'vertical'); }, isHorizontalDisplay: function isHorizontalDisplay() { return isClassExists(element, 'horizontal'); }, isButtonType: function isButtonType() { return isClassExists(element, 'buttonType'); }, spacing: function spacing() { return radios[1].style._values['margin-top']; }, lineHeight: function lineHeight() { return labels[0].style._values['line-height']; }, getNumberOfRadios: function getNumberOfRadios() { return radios.length; } }; }; export default radioGroupDriverFactory;