UNPKG

wix-style-react

Version:
60 lines 2.84 kB
import { baseUniDriverFactory, ReactBase } from '../test-utils/utils/unidriver'; // @ts-expect-error import { textUniDriverFactory } from '../Text/Text.uni.driver'; import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver'; import { dataHooks } from './constants'; import * as DATA_ATTR from './DataAttr'; const getDataCheckType = (base) => base.attr(DATA_ATTR.DATA_CHECK_TYPE); export const checkboxUniDriverFactory = (base, body) => { const reactBase = ReactBase(base); const labelTextDriver = textUniDriverFactory(base.$(`[data-hook="${dataHooks.children}"]`)); const input = () => base.$('input'); const isChecked = async () => (await getDataCheckType(base)) === DATA_ATTR.CHECK_TYPES.CHECKED; const getTooltipDriver = async () => tooltipDriverFactory(base.$(`[data-hook="${dataHooks.boxTooltip}"]`), body); const getTooltipMessage = async () => { const tooltipDriver = await getTooltipDriver(); return tooltipDriver.getTooltipText(); }; const isTooltipEnabled = async () => { const tooltipDriver = await getTooltipDriver(); await tooltipDriver.mouseEnter(); return await tooltipDriver.tooltipExists(); }; return { ...baseUniDriverFactory(base), // Click on the component root element. click: async () => { // clicking on base in react env doesn't trigger change event // and if clicking on input in puppeteer throws error that the element is not visible if (base.type === 'react') { return (await input()).click(); } else { return base.click(); } }, // focuses the component. focus: () => reactBase.focus(), // Checks whether the checkbox is focused isFocused: () => reactBase.isFocus(), // blurs off the element. blur: () => reactBase.blur(), // Checks whether the checkbox is checked. isChecked, // /Checks whether the checkbox is disabled. isDisabled: async () => (await base.attr(DATA_ATTR.DATA_DISABLED)) === 'true', // Checks whether the checkbox's value is indeterminate. isIndeterminate: async () => (await getDataCheckType(base)) === DATA_ATTR.CHECK_TYPES.INDETERMINATE, // Checks whether the checkbox's tooltip is enabled. isTooltipEnabled, // Checks whether the checkbox hasError prop is true. hasError: async () => (await base.attr(DATA_ATTR.DATA_HAS_ERROR)) === 'true', // Gets the tooltip message. getTooltipContent: getTooltipMessage, // Gets checkbox's label. getLabel: labelTextDriver.getText, // Gets the label's size. getLabelSize: labelTextDriver.getSize, }; }; //# sourceMappingURL=Checkbox.uni.driver.js.map