UNPKG

wix-style-react

Version:
42 lines (37 loc) 1.56 kB
import ReactTestUtils from 'react-dom/test-utils'; import DragDropContextProvider from '../DragDropContextProvider'; import DraggableSource from '../DragAndDrop/Draggable/components/DraggableSource'; import DraggableTarget from '../DragAndDrop/Draggable/components/DraggableTarget'; var findInstance = function findInstance(wrapper, cb) { var itemInstance = null; ReactTestUtils.findAllInRenderedTree(wrapper, function (ins) { var portalRoot = ins && (ins.portal || ins.tooltipContent); if (portalRoot && ReactTestUtils.isCompositeComponent(portalRoot)) { return ReactTestUtils.findAllInRenderedTree(portalRoot, function (insInPortal) { if (cb(insInPortal)) { itemInstance = insInPortal; } return Boolean(itemInstance); }); } else if (cb(ins)) { itemInstance = ins; } return Boolean(itemInstance); }); return itemInstance; }; export var getInstanceOfDraggableProvider = function getInstanceOfDraggableProvider(wrapper) { return findInstance(wrapper, function (ins) { return ins instanceof DragDropContextProvider; }); }; export var getInstanceOfDraggableSource = function getInstanceOfDraggableSource(wrapper, itemId) { return findInstance(wrapper, function (ins) { return ins instanceof DraggableSource && ins.props.id === itemId; }); }; export var getInstanceOfDraggableTarget = function getInstanceOfDraggableTarget(wrapper, itemId) { return findInstance(wrapper, function (ins) { return ins instanceof DraggableTarget && ins.props.id === itemId; }); };