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