UNPKG

wix-style-react

Version:
352 lines (303 loc) • 11.6 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _regeneratorRuntime from "@babel/runtime/regenerator"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import { baseUniDriverFactory } from 'wix-ui-test-utils/base-driver'; import { ReactBase } from '../../test/utils/unidriver'; import { dataAttr, dataHooks } from './constants'; import { statusIndicatorDriverFactory } from '../StatusIndicator/StatusIndicator.uni.driver'; export var inputAreaUniDriverFactory = function inputAreaUniDriverFactory(base, body) { var textArea = base.$('textarea'); var counterSelector = '[data-hook="counter"]'; var getStatusIndicatorDriver = function getStatusIndicatorDriver() { return statusIndicatorDriverFactory(base.$("[data-hook=\"".concat(dataHooks.tooltip, "\"]")), body); }; var textAreaBase = ReactBase(textArea); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { trigger: function trigger(_trigger, event) { return textAreaBase[_trigger](event); }, focus: function focus() { return textAreaBase.focus(); }, enterText: function enterText(text) { return textArea.enterValue(text); }, getValue: function getValue() { return textArea.value(); }, getName: function getName() { return textArea.attr('name'); }, getPlaceholder: function getPlaceholder() { return textArea._prop('placeholder'); }, getDefaultValue: function getDefaultValue() { return textArea._prop('defaultValue'); }, getRowsCount: function getRowsCount() { return textArea._prop('rows'); }, getMaxLength: function getMaxLength() { return textArea._prop('maxLength'); }, getTabIndex: function getTabIndex() { return textArea._prop('tabIndex'); }, getReadOnly: function getReadOnly() { return textArea._prop('readOnly'); }, getCursorLocation: function getCursorLocation() { return textArea._prop('selectionStart'); }, getResizable: function () { var _getResizable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return base.attr(dataAttr.RESIZABLE); case 2: return _context.abrupt("return", !!_context.sent); case 3: case "end": return _context.stop(); } } }, _callee); })); function getResizable() { return _getResizable.apply(this, arguments); } return getResizable; }(), getDisabled: function () { var _getDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return base.attr(dataAttr.DISABLED); case 2: _context2.t0 = !!_context2.sent; if (!_context2.t0) { _context2.next = 7; break; } _context2.next = 6; return textArea._prop('disabled'); case 6: _context2.t0 = !!_context2.sent; case 7: return _context2.abrupt("return", _context2.t0); case 8: case "end": return _context2.stop(); } } }, _callee2); })); function getDisabled() { return _getDisabled.apply(this, arguments); } return getDisabled; }(), getRequired: function getRequired() { return textArea._prop('required'); }, getHasCounter: function getHasCounter() { return !!base.$$(counterSelector).length; }, getCounterValue: function getCounterValue() { return base.$(counterSelector).text(); }, hasExclamation: function () { var _hasExclamation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return base.attr(dataAttr.STATUS); case 2: return _context3.abrupt("return", !!_context3.sent); case 3: case "end": return _context3.stop(); } } }, _callee3); })); function hasExclamation() { return _hasExclamation.apply(this, arguments); } return hasExclamation; }(), isFocusedStyle: function () { var _isFocusedStyle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return base.attr(dataAttr.FOCUS); case 2: return _context4.abrupt("return", !!_context4.sent); case 3: case "end": return _context4.stop(); } } }, _callee4); })); function isFocusedStyle() { return _isFocusedStyle.apply(this, arguments); } return isFocusedStyle; }(), isSizeSmall: function () { var _isSizeSmall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return base.attr(dataAttr.SIZE); case 2: _context5.t0 = _context5.sent; return _context5.abrupt("return", _context5.t0 === 'small'); case 4: case "end": return _context5.stop(); } } }, _callee5); })); function isSizeSmall() { return _isSizeSmall.apply(this, arguments); } return isSizeSmall; }(), isHoveredStyle: function () { var _isHoveredStyle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return base.attr(dataAttr.HOVER); case 2: return _context6.abrupt("return", !!_context6.sent); case 3: case "end": return _context6.stop(); } } }, _callee6); })); function isHoveredStyle() { return _isHoveredStyle.apply(this, arguments); } return isHoveredStyle; }(), isFocus: function isFocus() { return textAreaBase.isFocus(); }, exists: function exists() { return textArea.exists(); }, getStyle: function getStyle() { return textArea._prop('style'); }, getAriaLabel: function getAriaLabel() { return textArea.attr('aria-label'); }, getAriaControls: function getAriaControls() { return textArea.attr('aria-controls'); }, getAriaDescribedby: function getAriaDescribedby() { return textArea.attr('aria-describedby'); }, getTooltipDataHook: function getTooltipDataHook() { return dataHooks.tooltip; }, getTooltipElement: function getTooltipElement() { return base; }, // Status /** Return true if there's a status */ hasStatus: function () { var _hasStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(status) { var statusIndicatorDriver; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: statusIndicatorDriver = getStatusIndicatorDriver(); _context7.next = 3; return statusIndicatorDriver.exists(); case 3: if (!_context7.sent) { _context7.next = 9; break; } _context7.t0 = status; _context7.next = 7; return statusIndicatorDriver.getStatus(); case 7: _context7.t1 = _context7.sent; return _context7.abrupt("return", _context7.t0 === _context7.t1); case 9: return _context7.abrupt("return", false); case 10: case "end": return _context7.stop(); } } }, _callee7); })); function hasStatus(_x) { return _hasStatus.apply(this, arguments); } return hasStatus; }(), /** If there's a status message, returns its text value */ getStatusMessage: function () { var _getStatusMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { var statusIndicatorDriver, tooltipText; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: statusIndicatorDriver = getStatusIndicatorDriver(); tooltipText = null; _context8.next = 4; return statusIndicatorDriver.hasMessage(); case 4: if (!_context8.sent) { _context8.next = 8; break; } _context8.next = 7; return statusIndicatorDriver.getMessage(); case 7: tooltipText = _context8.sent; case 8: return _context8.abrupt("return", tooltipText); case 9: case "end": return _context8.stop(); } } }, _callee8); })); function getStatusMessage() { return _getStatusMessage.apply(this, arguments); } return getStatusMessage; }() }); };