wix-style-react
Version:
311 lines (253 loc) • 10.1 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addressInputDriverFactory = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../../test/utils/unidriver");
var _InputWithOptionsUni = require("../InputWithOptions/InputWithOptions.uni.driver");
var _LoaderUni = require("../Loader/Loader.uni.driver");
var _StatusIndicatorUni = require("../StatusIndicator/StatusIndicator.uni.driver");
var _AddressInputItemUni = require("../AddressInputItem/AddressInputItem.uni.driver");
var _constants = require("./constants");
var _constants2 = require("../Input/constants");
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) { (0, _defineProperty2["default"])(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; }
var addressInputDriverFactory = function addressInputDriverFactory(base, body) {
var _inputWithOptionsUniD = (0, _InputWithOptionsUni.inputWithOptionsUniDriverFactory)(base, body),
driver = _inputWithOptionsUniD.driver,
inputDriver = _inputWithOptionsUniD.inputDriver,
dropdownLayoutDriver = _inputWithOptionsUniD.dropdownLayoutDriver;
var getItemDriverAt = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(index) {
var optionDrivers, item;
return _regenerator["default"].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", (0, _AddressInputItemUni.addressInputItemDriverFactory)(item));
case 7:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function getItemDriverAt(_x) {
return _ref.apply(this, arguments);
};
}();
var loaderTestkit = function loaderTestkit() {
return (0, _LoaderUni.loaderUniDriverFactory)((0, _unidriver.findByHook)(base, _constants.dataHooks.loader));
};
var statusIndicatorTestkit = function statusIndicatorTestkit() {
return (0, _StatusIndicatorUni.statusIndicatorDriverFactory)((0, _unidriver.findByHook)(base, _constants2.dataHooks.status));
};
var isDropdownLoaderShown = function isDropdownLoaderShown() {
return loaderTestkit().exists();
};
var isLoadingIndicatorShown = /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
var status;
return _regenerator["default"].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({}, (0, _unidriver.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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(index) {
return _regenerator["default"].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 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(index) {
return _regenerator["default"].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();
}
});
};
exports.addressInputDriverFactory = addressInputDriverFactory;