UNPKG

@wix/design-system

Version:

@wix/design-system

55 lines 2.92 kB
import { testkit as inputUniDriverFactory } from '../Input/Input.uni.driver'; import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver'; import { ReactBase } from '../utils/test-utils/unidriver'; import { dropdownLayoutDriverProxy } from './InputWithOptions.proxy.driver'; import { popoverNextUniDriverFactory } from '../PopoverNext/PopoverNext.uni.driver'; export const inputWithOptionsUniDriverFactory = (base, body) => { const inputWrapperSelector = '[data-input-parent]'; const inputWrapper = base.$(inputWrapperSelector); const inputDriver = inputUniDriverFactory(base.$(`${inputWrapperSelector} > *:first-child `), body); const popoverTestkit = () => popoverNextUniDriverFactory(base, body); const dropdownLayoutFromBase = () => dropdownLayoutDriverFactory(base, body); const dropdownLayoutTestkit = async () => { const content = await popoverTestkit().getContentElementUniDriver(); if (!content) { return undefined; } return dropdownLayoutDriverFactory(content.$(`[data-hook="inputwithoptions-dropdownlayout"]`), body); }; const dropdownLayoutDriver = dropdownLayoutDriverProxy(dropdownLayoutFromBase, dropdownLayoutTestkit, popoverTestkit, inputDriver); const driver = { ...base, /** Select an option by id. (If dropdown options is not opened yet, this will open it and click on the option) */ selectOptionById: async (id) => { const nativeSelect = base.$('[data-hook=native-select]'); if (await nativeSelect.exists()) { const dataHookPrefix = `native-option-${id}`; const option = base.$(`[data-hook*=${dataHookPrefix}]`); const selectedIndex = await option.attr('data-index'); return await ReactBase(nativeSelect).select(selectedIndex); } const isPopoverShown = await popoverTestkit().isContentElementExists(); if (!isPopoverShown) { await inputDriver.click(); } await (await (await dropdownLayoutTestkit())?.optionById(id))?.click(); }, isReadOnly: inputDriver.getReadOnly, isEditable: async () => !(await inputDriver.getReadOnly()) && !(await inputDriver.getDisabled()), isDisabled: inputDriver.getDisabled, /** @deprecated Should be private */ inputWrapper: inputWrapper.getNative, focus: inputDriver.focus, blur: async () => (await dropdownLayoutTestkit())?.mouseClickOutside(), pressKey: async (key) => inputDriver.keyDown({ key }), outsideClick: popoverTestkit().clickOutside, isFocus: async () => !!(await inputDriver.isFocus()), }; return { exists: driver.exists, driver, inputDriver, dropdownLayoutDriver, }; }; //# sourceMappingURL=InputWithOptions.uni.driver.js.map