UNPKG

wix-style-react

Version:
49 lines (46 loc) 2.15 kB
import ReactTestUtils from 'react-dom/test-utils'; import styles from './InputArea.scss'; const inputAreaDriverFactory = ({ element }) => { const textAreaElement = element && element.childNodes[0]; const textArea = element.querySelector('textarea'); const name = textArea.getAttribute('name'); const counterSelector = '[data-hook="counter"]'; return { trigger: (trigger, event) => ReactTestUtils.Simulate[trigger](textArea, event), focus: () => textArea.focus(), enterText: text => ReactTestUtils.Simulate.change(textArea, { target: { name, value: text }, }), getValue: () => textArea.value, getName: () => name, getPlaceholder: () => textArea.placeholder, getDefaultValue: () => textArea.defaultValue, getRowsCount: () => textArea.rows, getMaxLength: () => textArea.maxLength, getTabIndex: () => textArea.tabIndex, getReadOnly: () => textArea.readOnly, getResizable: () => textAreaElement.classList.contains(styles.resizable), getDisabled: () => textAreaElement.classList.contains(styles.disabled) && textArea.disabled, getHasCounter: () => !!element.querySelectorAll(counterSelector).length, getCounterValue: () => element.querySelector(counterSelector).textContent, hasExclamation: () => element.querySelectorAll(`.${styles.exclamation}`).length === 1, hasError: () => textAreaElement.classList.contains(styles.hasError), isFocusedStyle: () => textAreaElement.classList.contains(styles.hasFocus), isHoveredStyle: () => textAreaElement.classList.contains(styles.hasHover), isOfStyle: style => textAreaElement.classList.contains(styles[`theme-${style}`]), isFocus: () => document.activeElement === textArea, exists: () => !!textArea, getStyle: () => textArea.style, getAriaLabel: () => textArea.getAttribute('aria-label'), getAriaControls: () => textArea.getAttribute('aria-controls'), getAriaDescribedby: () => textArea.getAttribute('aria-describedby'), getTooltipDataHook: () => 'inputArea-tooltip', getTooltipElement: () => element, }; }; export default inputAreaDriverFactory;