UNPKG

@wix/design-system

Version:

@wix/design-system

68 lines 3.16 kB
import inputDriverFactory from '../Input/Input.driver'; import dropdownLayoutDriverFactory from '../DropdownLayout/DropdownLayout.driver'; import { popoverNextLegacyDriverFactory } from '../PopoverNext/PopoverNext.driver'; const inputWithOptionsDriverFactory = ({ element, eventTrigger }) => { const dropdownDataHook = "inputwithoptions-dropdownlayout"; const dropdownLayoutSelector = `[data-hook="${dropdownDataHook}"]`; const inputWrapperSelector = '[data-input-parent]'; const popoverTestkit = () => popoverNextLegacyDriverFactory({ element }); const inputWrapper = () => element && element.querySelector(`${inputWrapperSelector} > *:first-child `); const dropdownLayoutMain = () => document.body.querySelector(dropdownLayoutSelector); const inputDriver = inputDriverFactory({ element: inputWrapper(), wrapper: inputWrapper(), eventTrigger, }); const dropdownLayoutTestkit = () => dropdownLayoutDriverFactory({ element: dropdownLayoutMain(), }); const driver = { exists: () => !!element, element: () => element, /** Select an option by id. (If dropdown options is not opened yet, this will open it and click on the option) */ selectOptionById: id => { inputDriver.click(); dropdownLayoutTestkit().optionById(id).click(); }, isReadOnly: () => inputDriver.getReadOnly() && inputWrapper().className.includes('readOnly'), isEditable: () => !inputDriver.getReadOnly() && !inputDriver.getDisabled(), isDisabled: () => !!inputDriver.getDisabled(), inputWrapper: () => inputWrapper(), focus: () => inputDriver.focus(), blur: () => dropdownLayoutTestkit().mouseClickOutside(), pressKey: key => inputDriver.keyDown(key), isMenuOpen: () => popoverTestkit().isContentElementExists(), outsideClick: () => popoverTestkit().clickOutside(), }; const dropdownLayoutDummy = dropdownLayoutDriverFactory({ element: document.body, dataHook: dropdownDataHook }); return { exists: () => driver.exists(), driver, inputDriver, dropdownLayoutDriver: Object.keys(dropdownLayoutDummy).reduce((prev, current) => { return { ...prev, [current]: args => { if (current === 'isShown' || current === 'exists') { return popoverTestkit().isContentElementExists(); } if (current === 'getDropdown' || current === 'getDropdownItem') { return popoverTestkit().isContentElementExists() ? dropdownLayoutTestkit()[current](args) : undefined; } !(popoverTestkit().isContentElementExists()) && inputDriver.click(); return dropdownLayoutTestkit()[current](args); }, }; }, {}), }; }; export default inputWithOptionsDriverFactory; //# sourceMappingURL=InputWithOptions.driver.js.map