UNPKG

wix-style-react

Version:
48 lines (44 loc) 1.75 kB
import ReactTestUtils from 'react-dom/test-utils'; var fieldWithSelectionCompositeDriverFactory = function fieldWithSelectionCompositeDriverFactory(_ref) { var element = _ref.element; var label = element.querySelector('.label>label'); var textInput = element.querySelector('input.input') || element.querySelector('textarea'); var deprecatedSelectionInput = element.querySelector('input'); return { exists: function exists() { return !!element; }, getLabel: function getLabel() { return label && label.textContent; }, /** @deprecated it is for internal testing and should not be exposed to users */ hasLabel: function hasLabel() { return !!label; }, /** @deprecated it is for internal testing and should not be exposed to users */ hasInput: function hasInput() { return !!textInput; }, getInput: function getInput() { return textInput; }, triggerInputBlur: function triggerInputBlur() { return ReactTestUtils.Simulate.blur(textInput); }, /** @deprecated it is for internal testing and should not be exposed to users */ hasSelectionInput: function hasSelectionInput() { return !!deprecatedSelectionInput.tagName; }, getAttr: function getAttr(attrName) { return element.getAttribute(attrName); }, /** @deprecated it is for internal testing and should not be exposed to users */ getNumberOfChildren: function getNumberOfChildren() { return element.childElementCount; }, hasFieldLabelAttributes: function hasFieldLabelAttributes() { return !!element.querySelectorAll('[data-hook="field-label-attributes"]').length; } }; }; export default fieldWithSelectionCompositeDriverFactory;