UNPKG

@wix/design-system

Version:

@wix/design-system

62 lines 2.99 kB
import { baseUniDriverFactory, ReactBase } from '../utils/test-utils/unidriver'; 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 reactInput = ReactBase(base.$('input')); 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: () => reactInput.focus(), // Checks whether the checkbox is focused isFocused: () => reactInput.isFocus(), // blurs off the element. blur: () => reactInput.blur(), // Checks whether the checkbox is checked. isChecked, // Checks whether the checkbox is disabled. isDisabled: async () => (await input().attr('disabled')) === '', // Checks whether the checkbox is required. isRequired: async () => (await input().attr('required')) === '', // 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