UNPKG

wix-style-react

Version:
67 lines 3.43 kB
import { baseUniDriverFactory } from '../../test-utils/utils/unidriver'; import { ProgressBarDataHooks, ProgressBarDataKeys, ProgressBarAriaKeys, ProgressBarInnerAriaKeys, } from './DataHooks'; const getNative = (base) => { if (base.type !== 'react') { throw new Error('Supported only in React/DOM.'); } return base.getNative(); }; export const linearProgressBarUniDriverFactory = (base) => { const byDataHook = (dataHook) => `[data-hook="${dataHook}"]`; const getValue = async () => { if (!(await base.exists())) { return null; } return base .$(byDataHook(ProgressBarDataHooks.progressPercentage)) .$('span') .text(); }; const getDataAttribute = async (key, parsingFunction) => { if (!(await base.exists()) || !(await base.attr(key))) { return null; } const value = await base.attr(key); return !!parsingFunction && parsingFunction instanceof Function ? parsingFunction(value) : value; }; return { ...baseUniDriverFactory(base), getWidth: async () => { const bar = base.$(byDataHook(ProgressBarDataHooks.foreground)); return (await getNative(bar)).style.width; }, isSuccessIconDisplayed: () => base.$(byDataHook(ProgressBarDataHooks.successIcon)).exists(), isErrorIconDisplayed: () => base.$(byDataHook(ProgressBarDataHooks.errorIcon)).exists(), isPercentagesProgressDisplayed: () => base.$(byDataHook(ProgressBarDataHooks.progressPercentage)).exists(), getValue: async () => getValue(), getNumericValue: () => getDataAttribute(ProgressBarDataKeys.value, Number), isCompleted: async () => // @ts-ignore (await getValue()) >= (await getDataAttribute(ProgressBarDataKeys.max)), hasError: async () => (await base.attr('data-error')) === 'true', getMinValue: () => getDataAttribute(ProgressBarDataKeys.min, Number), getMaxValue: () => getDataAttribute(ProgressBarDataKeys.max, Number), getAriaValueNow: () => getDataAttribute(ProgressBarAriaKeys.valuenow, Number), getAriaValueMax: () => getDataAttribute(ProgressBarAriaKeys.valuemax, Number), getAriaValueMin: () => getDataAttribute(ProgressBarAriaKeys.valuemin, Number), getAriaValueText: () => getDataAttribute(ProgressBarAriaKeys.valuetext), getRoleAttribute: () => getDataAttribute('role'), hasPrefixIndication: () => base.$(byDataHook(ProgressBarDataHooks.prefixIndicator)).exists(), hasSuffixIndication: () => base.$(byDataHook(ProgressBarDataHooks.suffixIndicator)).exists(), getSuffixIndicationText: () => base.$(byDataHook(ProgressBarDataHooks.suffixIndicator)).text(), hasPrefixAriaHidden: async () => (await base .$(byDataHook(ProgressBarDataHooks.prefixIndicator)) .attr(ProgressBarInnerAriaKeys.hidden)) === 'true', hasProgressIndicatorAriaHidden: async () => (await base .$(byDataHook(ProgressBarDataHooks.progressIndicator)) .attr(ProgressBarInnerAriaKeys.hidden)) === 'true', getAriaLabel: () => // @ts-ignore base .$(byDataHook(ProgressBarDataHooks.container)) .attr(ProgressBarInnerAriaKeys.label), }; }; //# sourceMappingURL=LinearProgressBarCore.uni.driver.js.map