wix-style-react
Version:
71 lines (56 loc) • 2 kB
JavaScript
import ReactTestUtils from 'react-dom/test-utils';
import { dataHooks } from './constants';
var radioButtonDriverFactory = function radioButtonDriverFactory(_ref) {
var element = _ref.element;
var getByDataHook = function getByDataHook(dataHook) {
return element.querySelector("[data-hook=\"".concat(dataHook, "\"]"));
};
var radioWrapper = function radioWrapper() {
return getByDataHook(dataHooks.RadioButtonWrapper);
};
var radioButton = function radioButton() {
return getByDataHook(dataHooks.RadioButtonInput);
};
var label = function label() {
return getByDataHook(dataHooks.RadioButtonLabel);
};
return {
/** Simulating a check action by clicking the input element */
exists: function exists() {
return !!element;
},
/** Simulating a check action by clicking the input element */
check: function check() {
return ReactTestUtils.Simulate.change(radioButton());
},
/** Getting the component's "checked" value */
isChecked: function isChecked() {
return radioButton().checked;
},
/** Getting the component's "disabled" value */
isDisabled: function isDisabled() {
return radioButton().disabled;
},
/** Getting the component's label text value */
getLabel: function getLabel() {
return label().textContent;
},
/** Getting the component's label element */
getLabelElement: function getLabelElement() {
return label();
},
/** Getting the component's input value */
getValue: function getValue() {
return radioButton().value;
},
/** Getting the component's tab-index value */
getTabIndex: function getTabIndex() {
return radioWrapper().getAttribute('tabIndex');
},
/** Getting the component's content element */
getContent: function getContent() {
return element.querySelector("[data-hook=\"".concat(dataHooks.RadioButtonContent, "\"]"));
}
};
};
export default radioButtonDriverFactory;