UNPKG

wix-style-react

Version:
180 lines (155 loc) • 6.45 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 '../../test/utils/unidriver'; import { testkit as inputUniDriverFactory } from '../Input/Input.uni.driver'; import { labelledElementDriverFactory as labelledElementUniDriverFactory } from '../LabelledElement/LabelledElement.uni.driver'; import dataHooks from './dataHooks'; import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver'; export var autoCompleteWithLabelDriverFactory = function autoCompleteWithLabelDriverFactory(base) { var labelledElementSelector = "[data-hook=\"".concat(dataHooks.labelledElement, "\"]"); var labelledElementDriver = labelledElementUniDriverFactory(base.$(labelledElementSelector)); var inputWrapperSelector = "[data-hook=\"".concat(dataHooks.inputWithLabel, "\"]"); var inputDriver = inputUniDriverFactory(base.$(inputWrapperSelector)); var dropdownLayoutDriver = dropdownLayoutDriverFactory(base.$("[data-hook=\"".concat(dataHooks.inputDropdownLayout, "\"]"))); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, { /** * Gets label text * @return {Promise<string>} */ getLabelText: function getLabelText() { return labelledElementDriver.getLabelText(); }, /** * Gets input value * @return {Promise<string>} */ getValue: function getValue() { return inputDriver.getValue(); }, /** * Enters given text to input * @param {string} text Text to input * @returns {Promise<void>} */ enterText: function () { var _enterText = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", inputDriver.enterText(text)); case 1: case "end": return _context.stop(); } } }, _callee); })); function enterText(_x) { return _enterText.apply(this, arguments); } return enterText; }(), /** * Clicks an option at given index * @param {number} index Position of the option * @returns {Promise<void>} */ clickAtOption: function () { var _clickAtOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index) { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return inputDriver.click(); case 2: return _context2.abrupt("return", dropdownLayoutDriver.clickAtOption(index)); case 3: case "end": return _context2.stop(); } } }, _callee2); })); function clickAtOption(_x2) { return _clickAtOption.apply(this, arguments); } return clickAtOption; }(), /** * Clicks an option with a given value * @param {string} value The option value * @returns {Promise<void>} */ clickAtOptionWithValue: function () { var _clickAtOptionWithValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(value) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return inputDriver.click(); case 2: return _context3.abrupt("return", dropdownLayoutDriver.clickAtOptionWithValue(value)); case 3: case "end": return _context3.stop(); } } }, _callee3); })); function clickAtOptionWithValue(_x3) { return _clickAtOptionWithValue.apply(this, arguments); } return clickAtOptionWithValue; }(), /** * Clicks the menu arrow * @returns {Promise<void>} */ clickMenuArrow: function clickMenuArrow() { return inputDriver.clickMenuArrow(); }, /** * Checks if input is disabled * @returns {Promise<boolean>} */ isDisabled: function () { var _isDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: return _context4.abrupt("return", inputDriver.isDisabled()); case 1: case "end": return _context4.stop(); } } }, _callee4); })); function isDisabled() { return _isDisabled.apply(this, arguments); } return isDisabled; }(), /** * Triggers blur event on the input element * @returns {Promise<void>} */ blur: function blur() { return inputDriver.blur(); }, /** * Checks whether there's a visible error icon * @return {Promise<boolean>} */ hasError: function hasError() { return inputDriver.hasStatus('error'); } }); };