UNPKG

wix-style-react

Version:
104 lines (90 loc) 3.31 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _testUtils = _interopRequireDefault(require("react-dom/test-utils")); var _constants = require("./constants"); var notificationDriverFactory = function notificationDriverFactory(_ref) { var element = _ref.element; var getElementByDataHook = function getElementByDataHook(dataHook) { return element.querySelector("[data-hook=\"".concat(dataHook, "\"]")); }; var notificationContent = function notificationContent() { return getElementByDataHook(_constants.dataHooks.notificationContent); }; var labelText = function labelText() { return getElementByDataHook(_constants.dataHooks.notificationLabel); }; var actionButton = function actionButton() { return getElementByDataHook(_constants.dataHooks.notificationCtaButton); }; var closeButton = function closeButton() { return getElementByDataHook(_constants.dataHooks.notificationCloseButton); }; var getTheme = function getTheme() { return element.getAttribute('data-theme'); }; var getType = function getType() { return element.getAttribute('data-type'); }; return { exists: function exists() { return !!element; }, visible: function visible() { return !!notificationContent(); }, hasTheme: function hasTheme() { return !!getTheme(); }, isStandardNotification: function isStandardNotification() { return getTheme() === _constants.THEMES.standard; }, isErrorNotification: function isErrorNotification() { return getTheme() === _constants.THEMES.error; }, isSuccessNotification: function isSuccessNotification() { return getTheme() === _constants.THEMES.success; }, isWarningNotification: function isWarningNotification() { return getTheme() === _constants.THEMES.warning; }, isPremiumNotification: function isPremiumNotification() { return getTheme() === _constants.THEMES.premium; }, getLabelText: function getLabelText() { return labelText().textContent; }, hasActionButton: function hasActionButton() { return !!actionButton(); }, getActionButtonText: function getActionButtonText() { return actionButton().textContent; }, hasCloseButton: function hasCloseButton() { return !!closeButton(); }, isRelativelyPositioned: function isRelativelyPositioned() { return getType() === _constants.TYPE_POSITIONS_MAP.relative; }, isFixedPositioned: function isFixedPositioned() { return getType() === _constants.TYPE_POSITIONS_MAP.fixed; }, isAbsolutePositioned: function isAbsolutePositioned() { return getType() === _constants.TYPE_POSITIONS_MAP.absolute; }, clickOnCloseButton: function clickOnCloseButton() { return _testUtils["default"].Simulate.click(closeButton()); }, clickOnActionButton: function clickOnActionButton() { return _testUtils["default"].Simulate.click(actionButton()); }, getZIndex: function getZIndex() { return Number(element.style['z-index']); } }; }; var _default = notificationDriverFactory; exports["default"] = _default;