wix-style-react
Version:
wix-style-react
33 lines • 1.56 kB
JavaScript
import { baseUniDriverFactory, findByHook, } from '../test-utils/utils/unidriver';
import { tooltipDriverFactory } from '../Tooltip/Tooltip.uni.driver';
import { dataHooks } from './constants';
export const checkToggleDriverFactory = (base, body) => {
const getTooltipDriver = () => tooltipDriverFactory(findByHook(base, dataHooks.tooltip), body);
return {
...baseUniDriverFactory(base),
// Checks whether CheckToggle is checked
isChecked: () => findByHook(base, dataHooks.toggle)._prop('checked'),
// Clicks on the element
click: async () => {
const input = await findByHook(base, dataHooks.toggle);
// eslint-disable-next-line no-restricted-properties
const isDisabled = await input._prop('disabled');
// In order to simulate a real user event, we need to check if the input is disabled before clicking.
if (!isDisabled)
await input.click();
},
// Gets the tooltip content, throws an error if content is not provided.
getTooltipContent: async () => {
const tooltipDriver = getTooltipDriver();
if (await tooltipDriver.exists()) {
await tooltipDriver.mouseEnter();
const text = await tooltipDriver.getTooltipText();
if (typeof text === 'string') {
return text;
}
}
throw new Error(`Message was not provided`);
},
};
};
//# sourceMappingURL=CheckToggle.uni.driver.js.map