wix-style-react
Version:
wix-style-react
82 lines • 4.96 kB
JavaScript
import { uniTestkitFactoryCreator } from '@wix/wix-ui-test-utils/vanilla';
import { PopoverMenuDriver } from '../PopoverMenu/PopoverMenu.uni.driver';
import { tooltipLegacyDriverFactory } from '../Tooltip/Tooltip.driver';
import { dataHooks } from './constants';
import buttonDriverFactory from '../Button/Button.legacy.driver';
const popoverMenuTestkitFactory = uniTestkitFactoryCreator(PopoverMenuDriver);
const tableActionCellDriverFactory = ({ element, wrapper, eventTrigger }) => {
const visibleActions = () => element.querySelectorAll(`[data-hook="${dataHooks.visibleAction}"]`);
const getPrimaryActionButtonVisibility = () => element
.querySelector(`[data-hook="${dataHooks.primaryActionWrapper}"]`)
.getAttribute('data-display');
const getPrimaryActionButtonDriver = () => buttonDriverFactory({
element: element.querySelector(`[data-hook="${dataHooks.primaryAction}"]`),
});
const getVisibleActionTooltipDriver = actionIndex => tooltipLegacyDriverFactory({
element: element.querySelectorAll(`[data-hook="${dataHooks.visibleActionTooltip}"]`)[actionIndex],
eventTrigger,
});
const getVisibleActionByDataHookTooltipDriver = dataHook => tooltipLegacyDriverFactory({
element: element.querySelector(`[data-hook="${dataHook}"]`),
eventTrigger,
});
const getVisibleActionButtonDriver = actionIndex => buttonDriverFactory({
element: visibleActions()[actionIndex],
});
const getVisibleActionByDataHookButtonDriver = dataHook => buttonDriverFactory({
element: element.querySelector(`[data-hook="${dataHook}"]`),
});
const getHiddenActionsPopoverMenuDriver = () => popoverMenuTestkitFactory({
wrapper,
dataHook: dataHooks.popoverMenu,
});
return {
/** Get the element */
element: () => element,
/** Whether the element exists */
exists: () => !!element,
/** Get the driver of the primary action <Button/> from the action column */
getPrimaryActionButtonDriver,
/** Click the primary action button from the action column */
clickPrimaryActionButton: () => getPrimaryActionButtonDriver().click(),
/** Get whether the primary action button is disabled */
getIsPrimaryActionButtonDisabled: () => getPrimaryActionButtonDriver().isButtonDisabled(),
/**
* Gets primary action visibility value
* @returns {Promise<'onHover' | 'always'>}
*/
getPrimaryActionButtonVisibility,
/** Get whether the primary action button prefix icon exists */
primaryActionButtonPrefixIconExists: () => getPrimaryActionButtonDriver().isPrefixIconExists(),
/** Get whether the primary action button suffix icon exists */
primaryActionButtonSuffixIconExists: () => getPrimaryActionButtonDriver().isSuffixIconExists(),
/** Get the number of the visible secondary actions */
getVisibleActionsCount: () => visibleActions().length,
/** Get the number of hidden secondary actions (in the <PopoverMenu/>, requires it to be open) */
getHiddenActionsCount: () => getHiddenActionsPopoverMenuDriver().childrenCount(),
/** Get the driver of a specific visible secondary action <Tooltip/> */
getVisibleActionTooltipDriver,
/** Get the driver of a specific visible secondary action <Tooltip/> by its specified dataHook */
getVisibleActionByDataHookTooltipDriver,
/** Get the driver of a specific visible secondary action <Button/> */
getVisibleActionButtonDriver,
/** Get the driver of a specific visible secondary action <Button/> by its specified dataHook */
getVisibleActionByDataHookButtonDriver,
/** Get the driver of the hidden secondary action <PopoverMenu/> */
getHiddenActionsPopoverMenuDriver,
/** Click an a visible secondary action */
clickVisibleAction: actionIndex => getVisibleActionButtonDriver(actionIndex).click(),
/** Click an a visible secondary action by its specified dataHook */
clickVisibleActionByDataHook: actionDataHook => getVisibleActionByDataHookButtonDriver(actionDataHook).click(),
/** Click on the hidden secondary actions <PopoverMenu/> */
clickPopoverMenu: () => getHiddenActionsPopoverMenuDriver()
.getTriggerElement(dataHooks.triggerElement)
.click(),
/** Click on a hidden secondary action (requires the <PopoverMenu/> to be open) */
clickHiddenAction: actionIndex => getHiddenActionsPopoverMenuDriver().clickAtChild(actionIndex),
clickHiddenActionByDataHook: actionDataHook => getHiddenActionsPopoverMenuDriver().clickAtChildByDataHook(actionDataHook),
getMoreActionsTooltipText: () => element.getAttribute('data-more-actions-tooltip-text'),
};
};
export default tableActionCellDriverFactory;
//# sourceMappingURL=TableActionCell.driver.js.map