UNPKG

wix-style-react

Version:
108 lines 4.54 kB
import { nestableListBaseUniDriverFactory } from '../NestableListBase/NestableListBase.uni.driver'; import { DEPTH_THRESHOLD } from './constants'; import { textButtonDriverFactory } from '../TextButton/TextButton.uni.driver'; import { baseUniDriverFactory, findByHook, } from '../test-utils/utils/unidriver'; import { dataHooks } from '../NestableListBase/constants'; export const nestableListDriverFactory = (base, body) => { const nestableListBaseUniDriver = nestableListBaseUniDriverFactory(base, body); const getActionsWrapper = async (dataHook = 'nestable-list-root-actions') => { const container = await base.$$(`[data-hook="${dataHook}"]`); if ((await container.count()) === 1) { return container.get(0); } return null; }; const getActions = async (parentDataHook) => { const actionsContainer = await getActionsWrapper(parentDataHook); if (actionsContainer) { await hoverActionsContainer(parentDataHook); return actionsContainer.$$(`[data-hook="nestable-list-action"]`); } return null; }; const getActionTextButton = async (parentDataHook, index) => { const actions = await getActions(parentDataHook); if (actions) { const action = await actions.get(index); if (await action.exists()) { return textButtonDriverFactory(action); } } else { throw new Error(`Button doesn't exist at ${JSON.stringify({ parentDataHook, index })}`); } }; const hoverActionsContainer = async (dataHook) => { const actionsContainer = await getActionsWrapper(dataHook); if (actionsContainer) { await actionsContainer.hover(); } }; const dndProviderBase = findByHook(base, dataHooks.provider); return { ...baseUniDriverFactory(dndProviderBase, body), /** * reorder nestable list items by data-hook * @param {ReorderDataHooks} dataHooks { from: string, to: string } * @return {Promise<void>} */ reorder: async ({ dataHookFrom, dataHookTo }) => nestableListBaseUniDriver.reorder({ dataHookFrom: `${dataHookFrom}-item`, dataHookTo: `${dataHookTo}-item`, }), /** * get nestable list item position * @param itemDetails { dataHook: string } * @return {Promise<void>} */ getItemPosition: async ({ dataHook }) => nestableListBaseUniDriver.getItemPosition({ dataHook: `${dataHook}-item`, }), /** * get nestable list item depth * @param itemDetails { dataHook: string } * @return {Promise<void>} */ getItemDepth: async ({ dataHook }) => nestableListBaseUniDriver.getItemDepth({ dataHook: `${dataHook}-item`, }), /** * * @param dataHook - optional. data hook of parent item, if it's not provided means root of the three * @return {Promise<number>} */ async getActionsCount(dataHook) { const actions = await getActions(dataHook); if (actions) { return actions.count(); } return 0; }, /** * * @param dataHook - optional. data hook of parent item, if it's not provided means root of the three * @return {Promise<void>} */ hoverActionsContainer, getActionLabelAt: async ({ actionIndex, parentDataHook = 'nestable-list-root-actions', }) => { const textButtonDriver = await getActionTextButton(parentDataHook, actionIndex); return textButtonDriver.getButtonTextContent(); }, clickActionAt: async ({ actionIndex, parentDataHook = 'nestable-list-root-actions', }) => { const textButtonDriver = await getActionTextButton(parentDataHook, actionIndex); return textButtonDriver.click(); }, /** * change nestable list item depth * @param {NestableItemDetails} dataHooks { dataHook: string, depthLevel: number } * @return {Promise<void>} */ changeItemDepth: ({ dataHook, depthLevel }) => nestableListBaseUniDriver.changeItemDepth({ dataHook: `${dataHook}-item`, depthLevel, threshold: DEPTH_THRESHOLD, }), }; }; export default nestableListDriverFactory; //# sourceMappingURL=NestableList.uni.driver.js.map