wix-style-react
Version:
93 lines (83 loc) • 2.94 kB
JavaScript
import ReactTestUtils from 'react-dom/test-utils';
import { dataHooks, THEMES, TYPE_POSITIONS_MAP } from './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(dataHooks.notificationContent);
};
var labelText = function labelText() {
return getElementByDataHook(dataHooks.notificationLabel);
};
var actionButton = function actionButton() {
return getElementByDataHook(dataHooks.notificationCtaButton);
};
var closeButton = function closeButton() {
return getElementByDataHook(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() === THEMES.standard;
},
isErrorNotification: function isErrorNotification() {
return getTheme() === THEMES.error;
},
isSuccessNotification: function isSuccessNotification() {
return getTheme() === THEMES.success;
},
isWarningNotification: function isWarningNotification() {
return getTheme() === THEMES.warning;
},
isPremiumNotification: function isPremiumNotification() {
return getTheme() === 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() === TYPE_POSITIONS_MAP.relative;
},
isFixedPositioned: function isFixedPositioned() {
return getType() === TYPE_POSITIONS_MAP.fixed;
},
isAbsolutePositioned: function isAbsolutePositioned() {
return getType() === TYPE_POSITIONS_MAP.absolute;
},
clickOnCloseButton: function clickOnCloseButton() {
return ReactTestUtils.Simulate.click(closeButton());
},
clickOnActionButton: function clickOnActionButton() {
return ReactTestUtils.Simulate.click(actionButton());
},
getZIndex: function getZIndex() {
return Number(element.style['z-index']);
}
};
};
export default notificationDriverFactory;