wix-style-react
Version:
wix-style-react
50 lines • 2.7 kB
JavaScript
import { colorInputDriverFactory as publicDriverFactory } from './ColorInput.uni.driver';
import { swatchesPrivateDriverFactory } from '../Swatches/test/Swatches.private.uni.driver';
import DATA_HOOKS from './DataHooks';
import inputUniDriverFactory from '../Input/Input.uni.driver';
import { popoverUniDriverFactory } from '../Popover/Popover.uni.driver';
export const colorInputPrivateDriverFactory = (base, body) => {
const swatchesHook = `[data-hook="${DATA_HOOKS.COLOR_PICKER_SWATCHES}"]`;
const swatchesDriver = swatchesPrivateDriverFactory(base.$(swatchesHook));
const colorViewerPopoverHook = `[data-hook="${DATA_HOOKS.COLOR_INPUT_POPOVER}"]`;
const colorViewerPopoverTestkit = popoverUniDriverFactory(base.$(colorViewerPopoverHook), body);
const isHashDisabled = async () => (await base
.$(`[data-hook="${DATA_HOOKS.COLOR_INPUT_HASH}"]`)
.attr('data-disabled')) === 'true';
const getViewerSize = () => base.$(`[data-hook="${DATA_HOOKS.COLOR_INPUT_VIEWER}"]`).attr('data-size');
const inputTestkit = inputUniDriverFactory(base);
return {
...publicDriverFactory(base, body),
isHashDisabled,
isViewerNull: async () => await base
.$(`[data-hook="${DATA_HOOKS.COLOR_INPUT_VIEWER_LINE}"]`)
.exists(),
getViewerSize,
getSwatch: async (index) => swatchesDriver.getSwatch(index),
getSwatchCount: async () => swatchesDriver.getSwatchCount(),
/** Private Swatches driver function to test if swatch is transparent at given index */
isSwatchTransparentAt: async (index) => swatchesDriver.isSwatchTransparentAt(index),
keyDown: async (event) => {
if (typeof event === 'string') {
await inputTestkit.keyDown({ key: event });
}
else {
await inputTestkit.keyDown(event);
}
},
blur: inputTestkit.blur,
focus: inputTestkit.focus,
clickOutside: async () => colorViewerPopoverTestkit.clickOutside(),
hasPrefix: inputTestkit.hasPrefix,
// TODO: this is because of a bug - clicking on ColorInput input field triggers onConfirm
// introducing private drivers with focus() instead of click() so our tests would't break
// remove this and use public unidriver once https://wix.monday.com/boards/2436042988/pulses/5145825887 is fixed
click: async () => inputTestkit.focus(),
enterText: async (text) => {
await inputTestkit.focus();
await inputTestkit.enterText(text);
},
};
};
export default colorInputPrivateDriverFactory;
//# sourceMappingURL=ColorInput.private.uni.driver.js.map