wix-style-react
Version:
249 lines (214 loc) • 9.21 kB
JavaScript
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 { loaderUniDriverFactory } from '../Loader/Loader.uni.driver';
import { selectorUniDriverFactory } from '../Selector/Selector.uni.driver';
import { searchUniDriverFactory } from '../Search/Search.uni.driver';
import { checkboxUniDriverFactory } from '../Checkbox/Checkbox.uni.driver';
import { dataHooks } from './SelectorList.helpers';
export var selectorListUniDriverFactory = function selectorListUniDriverFactory(base, body) {
var findInListByDataHook = function findInListByDataHook(dataHook) {
return base.$("[data-hook=\"".concat(dataHook, "\"]"));
};
var mainLoaderDriver = loaderUniDriverFactory(base.$("[data-hook=\"".concat(dataHooks.mainLoader, "\"]")), body);
var nextPageLoaderDriver = loaderUniDriverFactory(base.$("[data-hook=\"".concat(dataHooks.nextPageLoader, "\"]")), body);
var searchDriver = searchUniDriverFactory(base.$("[data-hook=\"".concat(dataHooks.search, "\"]")), body);
var toggleAllCheckboxDriver = checkboxUniDriverFactory(base.$("[data-hook=\"".concat(dataHooks.toggleAllCheckbox, "\"]")), body);
var getList = function getList() {
return findInListByDataHook(dataHooks.list);
};
var getListContent = function getListContent() {
return findInListByDataHook(dataHooks.content);
};
var getSelectors = function getSelectors() {
return getList().$$("[data-hook=\"".concat(dataHooks.selector, "\"]"));
};
var selectorDriverAt = function selectorDriverAt(i) {
return selectorUniDriverFactory(getSelectors().get(i));
};
var emptyState = function emptyState() {
return findInListByDataHook(dataHooks.emptyState);
};
var noResultsFoundState = function noResultsFoundState() {
return findInListByDataHook(dataHooks.noResultsFoundState);
};
return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, {
/**
* Checks whether the main loader exists.
* @returns {Promise<boolean>} True if main loader exists; false otherwise.
*/
mainLoaderExists: function mainLoaderExists() {
return mainLoaderDriver.exists();
},
/**
* Checks whether the next page loader exists.
* @returns {Promise<boolean>} True if next page loader exists; false otherwise.
*/
nextPageLoaderExists: function nextPageLoaderExists() {
return nextPageLoaderDriver.exists();
},
/**
* Checks whether the search input exists.
* @returns {Promise<boolean>} True if search input exists; false otherwise.
*/
searchInputExists: function searchInputExists() {
return searchDriver.exists();
},
/**
* Focuses search input
* @returns {Promise<void>} Resolves when search input is focused.
*/
focusSearchInput: function focusSearchInput() {
return searchDriver.inputDriver.focus();
},
/**
* Changes search input value
* @param {string} value
* @returns {Promise<void>} Resolves when search input value changes.
*/
enterSearchValue: function enterSearchValue(value) {
return searchDriver.inputDriver.enterText(value);
},
/**
* Returns search input value
* @returns {Promise<string>} Search input string value.
*/
getSearchValue: function getSearchValue() {
return searchDriver.inputDriver.getValue();
},
/**
* Clicks on search input's clear button to clear value
* @returns {Promise<void>} Resolves when clear button was clicked.
*/
clickSearchInputClear: function clickSearchInputClear() {
return searchDriver.inputDriver.clickClear();
},
/**
* Checks whether the toggle-all checkbox exists.
* @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
* @returns {Promise<boolean>} True if toggle-all checkbox exists; false otherwise.
*/
toggleAllCheckboxExists: function toggleAllCheckboxExists() {
return toggleAllCheckboxDriver.exists();
},
/**
* Checks whether the toggle-all checkbox is checked.
* @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
* @returns {Promise<boolean>} True if toggle-all checkbox is checked; false otherwise.
*/
isToggleAllCheckboxChecked: function isToggleAllCheckboxChecked() {
return toggleAllCheckboxDriver.isChecked();
},
/**
* Returns toggle-all checkbox label text
* @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
* @returns {Promise<string>}
*/
getToggleAllCheckboxLabel: function getToggleAllCheckboxLabel() {
return toggleAllCheckboxDriver.getLabel();
},
/**
* Clicks on toggle-all checkbox to select/deselect all non-disabled items.
* @param {UniDriver<any>} checkboxContainer a unidriver of the checkbox's container
* @returns {Promise<void>} Resolves when toggle-all checkbox was clicked.
*/
clickToggleAllCheckbox: function clickToggleAllCheckbox() {
return toggleAllCheckboxDriver.click();
},
/**
* Checks whether empty state is shown.
* @returns {Promise<boolean>} True if empty state is shown; false otherwise.
*/
showsEmptyState: function showsEmptyState() {
return emptyState().exists();
},
/**
* Gets empty state.
* @returns {Promise<HTMLElement>}
*/
getEmptyState: function getEmptyState() {
return emptyState()._prop('firstChild');
},
/**
* Checks whether no results found state is shown.
* @returns {Promise<boolean>} True if no results found state is shown; false otherwise.
*/
showsNoResultsFoundState: function showsNoResultsFoundState() {
return noResultsFoundState().exists();
},
/**
* Gets no results found state.
* @returns {Promise<HTMLElement>}
*/
getNoResultsFoundState: function getNoResultsFoundState() {
return noResultsFoundState()._prop('firstChild');
},
/**
* Checks whether the list exists.
* @returns {Promise<boolean>} True if list exists; false otherwise.
*/
listExists: function listExists() {
return getList().exists();
},
/**
* Returns the number of items in the list.
* @returns {Promise<number>}
*/
numberOfItemsInList: function numberOfItemsInList() {
return getSelectors().count();
},
/**
* Toggles selector of the item at the passed index.
* @param {number} i Item index
* @returns {Promise<void>} Resolves when selector is toggled.
*/
toggleSelectorAt: function toggleSelectorAt(i) {
return selectorDriverAt(i).toggle();
},
/**
* Checks whether the selector of the item at the passed index is checked.
* @param {number} i Item index
* @returns {Promise<boolean>}
*/
isSelectorCheckedAt: function isSelectorCheckedAt(i) {
return selectorDriverAt(i).isChecked();
},
/**
* Checks whether the selector of the item at the passed index is disabled.
* @param {number} i Item index
* @returns {Promise<boolean>}
*/
isSelectorDisabledAt: function isSelectorDisabledAt(i) {
return selectorDriverAt(i).isDisabled();
},
/**
* Triggers "scroll" event on the list.
* @returns {Promise<boolean>}.
*/
scrollDown: function () {
var _scrollDown = _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 getListContent().getNative();
case 2:
return _context.abrupt("return", _context.sent.dispatchEvent(new Event('scroll')));
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function scrollDown() {
return _scrollDown.apply(this, arguments);
}
return scrollDown;
}()
});
};