UNPKG

wix-style-react

Version:
226 lines (215 loc) • 8.03 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _testUtils = require('react-dom/test-utils'); var _testUtils2 = _interopRequireDefault(_testUtils); var _Input = require('./Input.scss'); var _Input2 = _interopRequireDefault(_Input); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var inputDriverFactory = function inputDriverFactory(_ref) { var element = _ref.element; var input = element && element.querySelector('input'); var clearButton = element && element.querySelector('[data-hook=input-clear-button]'); var suffixNode = element && element.querySelector('.' + _Input2.default.suffix); var unitNode = element && element.querySelector('.' + _Input2.default.unit); var magnifyingGlassNode = element && element.querySelector('.' + _Input2.default.magnifyingGlass); var menuArrowNode = element && element.querySelector('.' + _Input2.default.menuArrow); var getName = function getName() { return input.getAttribute('name'); }; var getType = function getType() { return input.getAttribute('type'); }; var driver = { trigger: function trigger(_trigger, event) { return _testUtils2.default.Simulate[_trigger](input, event); }, focus: function focus(options) { input.focus(options); _testUtils2.default.Simulate.focus(input); }, blur: function blur() { input.blur(); _testUtils2.default.Simulate.blur(input); }, getName: getName, getType: getType, keyDown: function keyDown(key) { return _testUtils2.default.Simulate.keyDown(input, { key: key }); }, click: function click() { return _testUtils2.default.Simulate.click(input); }, clickSuffix: function clickSuffix() { return _testUtils2.default.Simulate.click(suffixNode); }, clickClear: function clickClear() { return _testUtils2.default.Simulate.click(clearButton); }, clickUnit: function clickUnit() { return _testUtils2.default.Simulate.click(unitNode); }, clickMagnifyingGlass: function clickMagnifyingGlass() { return _testUtils2.default.Simulate.click(magnifyingGlassNode); }, clickMenuArrow: function clickMenuArrow() { return _testUtils2.default.Simulate.click(menuArrowNode); }, mouseOver: function mouseOver() { return _testUtils2.default.Simulate.mouseOver(input); }, mouseOut: function mouseOut() { return _testUtils2.default.Simulate.mouseOut(input); }, clearText: function clearText() { return driver.enterText(''); }, enterText: function enterText(text) { input.value = text; _testUtils2.default.Simulate.change(input, { target: { name: getName(), type: getType(), value: text } }); }, getValue: function getValue() { return input.value; }, getPlaceholder: function getPlaceholder() { return input.placeholder; }, getDefaultValue: function getDefaultValue() { return input.defaultValue; }, getTabIndex: function getTabIndex() { return input.tabIndex; }, getReadOnly: function getReadOnly() { return input.readOnly; }, getTextOverflow: function getTextOverflow() { return input.style['text-overflow']; }, getAriaLabel: function getAriaLabel() { return input.getAttribute('aria-label'); }, getAriaControls: function getAriaControls() { return input.getAttribute('aria-controls'); }, getAriaDescribedby: function getAriaDescribedby() { return input.getAttribute('aria-describedby'); }, getAutocomplete: function getAutocomplete() { return input.getAttribute('autocomplete'); }, getRequired: function getRequired() { return input.required; }, hasPrefix: function hasPrefix() { return element.querySelectorAll('.' + _Input2.default.prefix).length === 1; }, hasPrefixClass: function hasPrefixClass() { return element.querySelectorAll('.' + _Input2.default.input + '.' + _Input2.default.withPrefix).length === 1; }, hasSuffix: function hasSuffix() { return !!suffixNode; }, hasSuffixClass: function hasSuffixClass() { return element.querySelectorAll('.' + _Input2.default.input + '.' + _Input2.default.withSuffix).length === 1; }, hasSuffixesClass: function hasSuffixesClass() { return element.querySelectorAll('.' + _Input2.default.input + '.' + _Input2.default.withSuffixes).length === 1; }, prefixComponentExists: function prefixComponentExists(style) { return !!element.querySelector('.' + _Input2.default.prefix + ' ' + style); }, suffixComponentExists: function suffixComponentExists(style) { return !!element.querySelector('.' + _Input2.default.suffix + ' ' + style); }, isMenuArrowLast: function isMenuArrowLast() { return element.querySelectorAll('.' + _Input2.default.suffixes + ' .' + _Input2.default.suffix + ':last-child > .' + _Input2.default.menuArrow).length === 1; }, hasExclamation: function hasExclamation() { return !!element.querySelector('.' + _Input2.default.exclamation); }, isNarrowError: function isNarrowError() { return !!element.querySelector('.' + _Input2.default.narrow); }, hasHelp: function hasHelp() { return !!element.querySelector('.' + _Input2.default.help); }, hasError: function hasError() { return element.classList.contains(_Input2.default.hasError); }, getTooltipElement: function getTooltipElement() { return element; }, hasLoader: function hasLoader() { return element.querySelector('.loaderContainer'); }, getTooltipDataHook: function getTooltipDataHook() { return 'input-tooltip'; }, getDataHook: function getDataHook() { return element.getAttribute('data-hook'); }, getUnit: function getUnit() { return unitNode.textContent; }, hasMagnifyingGlass: function hasMagnifyingGlass() { return !!magnifyingGlassNode; }, hasMenuArrow: function hasMenuArrow() { return !!menuArrowNode; }, hasClearButton: function hasClearButton() { return !!clearButton; }, isRTL: function isRTL() { return element.className.indexOf(_Input2.default.rtl) >= 0; }, isFocusedStyle: function isFocusedStyle() { return element.classList.contains(_Input2.default.hasFocus); }, isHoveredStyle: function isHoveredStyle() { return element.classList.contains(_Input2.default.hasHover); }, isDisabled: function isDisabled() { return element.classList.contains(_Input2.default.disabled); }, isOfStyle: function isOfStyle(style) { return element.classList.contains(_Input2.default['theme-' + style]); }, isOfSize: function isOfSize(size) { return element.classList.contains(_Input2.default['size-' + size]); }, isFocus: function isFocus() { return document.activeElement === input; }, exists: function exists() { return !!(element && element.querySelector('input')); }, startComposing: function startComposing() { return _testUtils2.default.Simulate.compositionStart(input); }, endComposing: function endComposing() { return _testUtils2.default.Simulate.compositionEnd(input); }, getCursorLocation: function getCursorLocation() { return input.selectionStart; }, getRootElementClasses: function getRootElementClasses() { return element.classList; }, getInputElementClasses: function getInputElementClasses() { return input.classList; }, hasRightBorderRadius: function hasRightBorderRadius() { return !element.classList.contains(_Input2.default.noRightBorderRadius); }, hasLeftBorderRadius: function hasLeftBorderRadius() { return !element.classList.contains(_Input2.default.noLeftBorderRadius); } }; return driver; }; exports.default = inputDriverFactory;