wix-style-react
Version:
65 lines (52 loc) • 2.31 kB
JavaScript
import buttonDriverFactory from '../Button/Button.legacy.driver';
import { dataHooks } from './constants';
import { getFormattedDataHooks, isClassExists } from '../../test/utils';
import ReactTestUtils from 'react-dom/test-utils';
import { tooltipDriverFactory } from 'wix-ui-core/dist/src/components/tooltip/Tooltip.driver';
const fDataHooks = getFormattedDataHooks(dataHooks);
export const baseModalLayoutDriverFactory = ({ element, eventTrigger }) => {
const getButtonDriver = dataHook =>
buttonDriverFactory({
element: element.querySelector(`[data-hook="${dataHook}"]`),
});
const tooltipTestkit = tooltipDriverFactory({
element: element.querySelector(fDataHooks.primaryButtonTooltip),
eventTrigger,
});
return {
exists: () => !!element,
_hasClass: className => isClassExists(element, className),
_closeButtonExists: () => !!element.querySelector(fDataHooks.closeButton),
_helpButtonExists: () => !!element.querySelector(fDataHooks.helpButton),
/** Returns the modal theme */
getTheme: () => element.getAttribute('data-theme'),
/** Click the modal close-button */
clickCloseButton: () =>
ReactTestUtils.Simulate.click(
element.querySelector(fDataHooks.closeButton),
),
clickHelpButton: () =>
ReactTestUtils.Simulate.click(
element.querySelector(fDataHooks.helpButton),
),
/** Checks that a node with the provided dataHook exists */
childExists: dataHook =>
!!element.querySelector(`[data-hook="${dataHook}"]`),
/** Get the title's text */
getTitleText: () =>
element.querySelector(fDataHooks.headerTitle).textContent,
/** Get the subtitle's text */
getSubtitleText: () =>
element.querySelector(fDataHooks.headerSubtitle).textContent,
/** Return the secondary button driver*/
getSecondaryButtonDriver: () =>
getButtonDriver(dataHooks.footerSecondaryButton),
/** Return the secondary button driver */
getPrimaryButtonDriver: () =>
getButtonDriver(dataHooks.footerPrimaryButton),
/** Return the primary button tooltip's content */
getPrimaryButtonTooltipContent: () => tooltipTestkit.getTooltipText(),
getIllustrationSrc: () =>
element.querySelector(fDataHooks.illustrationSrc).getAttribute('src'),
};
};