UNPKG

wix-style-react

Version:
291 lines (246 loc) • 9.5 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; 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 _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory, findByHook } from '../../test/utils/unidriver'; import { inputWithOptionsUniDriverFactory } from '../InputWithOptions/InputWithOptions.uni.driver'; import { loaderUniDriverFactory } from '../Loader/Loader.uni.driver'; import { statusIndicatorDriverFactory } from '../StatusIndicator/StatusIndicator.uni.driver'; import { addressInputItemDriverFactory } from '../AddressInputItem/AddressInputItem.uni.driver'; import { dataHooks } from './constants'; import { dataHooks as inputDataHooks } from '../Input/constants'; export var addressInputDriverFactory = function addressInputDriverFactory(base, body) { var _inputWithOptionsUniD = inputWithOptionsUniDriverFactory(base, body), driver = _inputWithOptionsUniD.driver, inputDriver = _inputWithOptionsUniD.inputDriver, dropdownLayoutDriver = _inputWithOptionsUniD.dropdownLayoutDriver; var getItemDriverAt = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(index) { var optionDrivers, item; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return dropdownLayoutDriver.options(); case 2: optionDrivers = _context.sent; _context.next = 5; return optionDrivers[index].element(); case 5: item = _context.sent; return _context.abrupt("return", addressInputItemDriverFactory(item)); case 7: case "end": return _context.stop(); } } }, _callee); })); return function getItemDriverAt(_x) { return _ref.apply(this, arguments); }; }(); var loaderTestkit = function loaderTestkit() { return loaderUniDriverFactory(findByHook(base, dataHooks.loader)); }; var statusIndicatorTestkit = function statusIndicatorTestkit() { return statusIndicatorDriverFactory(findByHook(base, inputDataHooks.status)); }; var isDropdownLoaderShown = function isDropdownLoaderShown() { return loaderTestkit().exists(); }; var isLoadingIndicatorShown = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var status; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.prev = 0; _context2.next = 3; return statusIndicatorTestkit().getStatus(); case 3: status = _context2.sent; return _context2.abrupt("return", status === 'loading'); case 7: _context2.prev = 7; _context2.t0 = _context2["catch"](0); return _context2.abrupt("return", false); case 10: case "end": return _context2.stop(); } } }, _callee2, null, [[0, 7]]); })); return function isLoadingIndicatorShown() { return _ref2.apply(this, arguments); }; }(); return _objectSpread(_objectSpread({}, baseUniDriverFactory(base, body)), {}, { /** * Returns value of the input * @returns {Promise<string>} */ getInputValue: function getInputValue() { return inputDriver.getValue(); }, /** * Enters given text to input * @param {string} text Text to input * @returns {Promise<void>} */ enterText: function enterText(text) { return inputDriver.enterText(text); }, /** * Clicks on the clear button to clear input text * @returns {Promise<void>} */ clickClear: function clickClear() { return inputDriver.clickClear(); }, /** * Checks if input is disabled * @returns {Promise<boolean>} */ isDisabled: function isDisabled() { return driver.isDisabled(); }, /** * Clicks an option at given index * @param {number} index Position of the option * @returns {Promise<void>} */ clickAtOption: function clickAtOption(index) { return dropdownLayoutDriver.clickAtOption(index); }, /** * Clicks an option with a given value * @param {string} value The option value * @returns {Promise<void>} */ clickAtOptionWithValue: function clickAtOptionWithValue(value) { return dropdownLayoutDriver.clickAtOptionWithValue(value); }, /** Whether loader is shown * @returns {Promise<boolean>} */ isLoading: function () { var _isLoading = _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 isLoadingIndicatorShown(); case 2: _context3.t0 = _context3.sent; if (_context3.t0) { _context3.next = 7; break; } _context3.next = 6; return isDropdownLoaderShown(); case 6: _context3.t0 = _context3.sent; case 7: return _context3.abrupt("return", _context3.t0); case 8: case "end": return _context3.stop(); } } }, _callee3); })); function isLoading() { return _isLoading.apply(this, arguments); } return isLoading; }(), /** * Clicks on input * @returns {Promise<void>} */ clickInput: function clickInput() { return inputDriver.click(); }, /** * Gets amount of dropdown items * @returns {Promise<number>} */ getAmountOfItems: function getAmountOfItems() { return dropdownLayoutDriver.optionsLength(); }, /** * Gets item main label text at given index * @param {number} index * @returns {Promise<string>} */ getItemMainLabelAt: function () { var _getItemMainLabelAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(index) { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return getItemDriverAt(index); case 2: return _context4.abrupt("return", _context4.sent.getMainLabelText()); case 3: case "end": return _context4.stop(); } } }, _callee4); })); function getItemMainLabelAt(_x2) { return _getItemMainLabelAt.apply(this, arguments); } return getItemMainLabelAt; }(), /** * Gets item secondary label text at given index * @param {number} index * @returns {Promise<string>} */ getItemSecondaryLabelAt: function () { var _getItemSecondaryLabelAt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(index) { return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return getItemDriverAt(index); case 2: return _context5.abrupt("return", _context5.sent.getSecondaryLabelText()); case 3: case "end": return _context5.stop(); } } }, _callee5); })); function getItemSecondaryLabelAt(_x3) { return _getItemSecondaryLabelAt.apply(this, arguments); } return getItemSecondaryLabelAt; }(), /** * Press enter on address input * @returns {Promise<void>} */ pressEnter: function pressEnter() { return driver.pressKey('Enter'); }, /** * Checks whether the address input is focused * @returns {Promise<boolean>} */ isFocused: function isFocused() { return inputDriver.isFocus(); } }); };