@wix/design-system
Version:
@wix/design-system
59 lines • 3.61 kB
JavaScript
import { baseUniDriverFactory, findByHook, } from '../utils/test-utils/unidriver';
import { dropdownLayoutDriverFactory } from '../DropdownLayout/DropdownLayout.uni.driver';
import { popoverUniDriverFactory } from '../Popover/Popover.uni.driver';
import { DATA_HOOKS } from '../DropdownLayout/DataAttr';
export const dropdownBaseDriverFactory = (base, body) => {
const byDataHook = (dataHook) => base.$(`[data-hook="${dataHook}"]`);
const getTargetElement = (dataHook) => byDataHook(dataHook);
const getContentElement = async () => popoverUniDriverFactory(base, body).getContentElementUniDriver();
const createDropdownLayoutDriver = async () => dropdownLayoutDriverFactory((await getContentElement()).$(`[data-hook="dropdown-base-dropdownlayout"]`), body);
return {
...baseUniDriverFactory(base),
/** Returns the list type prop value */
getListType: async (dataHook) => {
const dropdownBaseRootElement = await body.$(`[data-hook="${dataHook}"]`);
return dropdownBaseRootElement.attr('data-list-type');
},
/** Returns the target element */
clickTargetElement: (dataHook) => getTargetElement(dataHook).click(),
/** Hover the target element */
hoverTargetElement: (dataHook) => getTargetElement(dataHook).hover(),
/** Returns `true` if the dropdown is being shown */
isDropdownShown: () => popoverUniDriverFactory(base, body).isContentElementExists(),
/** Select a specific option (requires the DropdownBase to be opened) */
selectOption: async (index) => (await createDropdownLayoutDriver()).clickAtOption(index),
/** Select a specific option by its data hook (requires the DropdownBase to be opened) */
selectOptionByDataHook: async (dataHook) => (await createDropdownLayoutDriver()).clickAtOptionByDataHook(dataHook),
/** Click outside of the component */
clickOutside: () => popoverUniDriverFactory(base, body).clickOutside(),
/** Options count (requires the DropdownBase to be opened) */
optionsCount: async () => (await createDropdownLayoutDriver()).optionsLength(),
optionContentAt: async (position) => {
const dropdownLayoutDriver = await createDropdownLayoutDriver();
const optionsDrivers = await dropdownLayoutDriver.options();
const optionElement = await optionsDrivers[position].element();
const option = await findByHook(optionElement, DATA_HOOKS.OPTION);
/*
Option content can be
1. node - <div>some text</div>
2. text - some text
*/
const nodeContent = option.$$(':first-child');
const contentIsNode = (await nodeContent.count()) > 0;
if (contentIsNode) {
// eslint-disable-next-line no-restricted-properties
return await nodeContent.get(0).getNative();
}
else {
return option.text();
}
},
/** Returns the selected option (requires the DropdownBase to be opened)*/
getSelectedOptionId: async () => (await createDropdownLayoutDriver()).getSelectedOptionId(),
/** Returns the marked option (requires the DropdownBase to be opened)*/
getMarkedOption: async () => (await createDropdownLayoutDriver()).markedOption(),
mouseEnter: () => popoverUniDriverFactory(base, body).mouseEnter(),
mouseLeave: () => popoverUniDriverFactory(base, body).mouseLeave(),
};
};
//# sourceMappingURL=DropdownBase.uni.driver.js.map