wix-style-react
Version:
345 lines (292 loc) • 11.6 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 { dataHooks } from './constants';
export var floatingNotificationDriverFactory = function floatingNotificationDriverFactory(base) {
var getByDataHook = function getByDataHook(dataHook) {
return base.$("[data-hook=\"".concat(dataHook, "\"]"));
};
var notificationButton = getByDataHook(dataHooks.button);
var notificationTextButton = getByDataHook(dataHooks.textButton);
var notificationCloseButton = getByDataHook(dataHooks.closeButton);
var notificationText = getByDataHook(dataHooks.notificationText);
return _objectSpread(_objectSpread({}, baseUniDriverFactory(base)), {}, {
/** Clicks notification button
* @returns {Promise<void>}
*/
clickButton: function () {
var _clickButton = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", notificationButton.click());
case 1:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function clickButton() {
return _clickButton.apply(this, arguments);
}
return clickButton;
}(),
/** Get the notification button's text
* @returns {Promise<string>}
*/
getButtonLabel: function () {
var _getButtonLabel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", notificationButton.text());
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function getButtonLabel() {
return _getButtonLabel.apply(this, arguments);
}
return getButtonLabel;
}(),
/** Clicks the notification text button
* @returns {Promise<void>}
*/
clickTextButton: function () {
var _clickTextButton = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", notificationTextButton.click());
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function clickTextButton() {
return _clickTextButton.apply(this, arguments);
}
return clickTextButton;
}(),
/** Get the notification text button's text
* @returns {Promise<string>}
*/
getTextButtonLabel: function () {
var _getTextButtonLabel = _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", notificationTextButton.text());
case 1:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
function getTextButtonLabel() {
return _getTextButtonLabel.apply(this, arguments);
}
return getTextButtonLabel;
}(),
/** Clicks the notification close button
* @returns {Promise<void>}
*/
clickCloseButton: function () {
var _clickCloseButton = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
return _context5.abrupt("return", notificationCloseButton.click());
case 1:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function clickCloseButton() {
return _clickCloseButton.apply(this, arguments);
}
return clickCloseButton;
}(),
/** Get the notification text
* @returns {Promise<string>}
*/
getText: function () {
var _getText = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
return _context6.abrupt("return", notificationText.text());
case 1:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function getText() {
return _getText.apply(this, arguments);
}
return getText;
}(),
/** Checks whether button with passed tag name exists
* @param {keyof HTMLElementTagNameMap} as Tag name
* @returns {Promise<boolean>}
*/
isButtonAs: function () {
var _isButtonAs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(as) {
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return base.$("".concat(as, "[data-hook=\"").concat(dataHooks.button, "\"]")).exists();
case 2:
return _context7.abrupt("return", _context7.sent);
case 3:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function isButtonAs(_x) {
return _isButtonAs.apply(this, arguments);
}
return isButtonAs;
}(),
/** Get the notification button href attribute's value
* @returns {Promise<string | null>}
*/
getButtonHref: function () {
var _getButtonHref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
return _context8.abrupt("return", notificationButton.attr('href'));
case 1:
case "end":
return _context8.stop();
}
}
}, _callee8);
}));
function getButtonHref() {
return _getButtonHref.apply(this, arguments);
}
return getButtonHref;
}(),
/** Get the notification button attribute's value by name
* @param {string} attrName Attribute name
* @returns {Promise<string | null>}
*/
getButtonAttr: function () {
var _getButtonAttr = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(attrName) {
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
return _context9.abrupt("return", notificationButton.attr(attrName));
case 1:
case "end":
return _context9.stop();
}
}
}, _callee9);
}));
function getButtonAttr(_x2) {
return _getButtonAttr.apply(this, arguments);
}
return getButtonAttr;
}(),
/** Checks whether text button with passed tag name exists
* @param {keyof HTMLElementTagNameMap} as Tag name
* @returns {Promise<boolean>}
*/
isTextButtonAs: function () {
var _isTextButtonAs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(as) {
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return base.$("".concat(as, "[data-hook=\"").concat(dataHooks.textButton, "\"]")).exists();
case 2:
return _context10.abrupt("return", _context10.sent);
case 3:
case "end":
return _context10.stop();
}
}
}, _callee10);
}));
function isTextButtonAs(_x3) {
return _isTextButtonAs.apply(this, arguments);
}
return isTextButtonAs;
}(),
/** Get the notification text button href attribute's value
* @returns {Promise<string | null>}
*/
getTextButtonHref: function () {
var _getTextButtonHref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
return _context11.abrupt("return", notificationTextButton.attr('href'));
case 1:
case "end":
return _context11.stop();
}
}
}, _callee11);
}));
function getTextButtonHref() {
return _getTextButtonHref.apply(this, arguments);
}
return getTextButtonHref;
}(),
/** Get the notification text button attribute's value by name
* @param {string} attrName Attribute name
* @returns {Promise<string | null>}
*/
getTextButtonAttr: function () {
var _getTextButtonAttr = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(attrName) {
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
return _context12.abrupt("return", notificationTextButton.attr(attrName));
case 1:
case "end":
return _context12.stop();
}
}
}, _callee12);
}));
function getTextButtonAttr(_x4) {
return _getTextButtonAttr.apply(this, arguments);
}
return getTextButtonAttr;
}()
});
};