react-dnd-test-utils
Version:
54 lines (53 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.simulateDragDrop = simulateDragDrop;
exports.simulateDragHover = simulateDragHover;
exports.simulateDrag = simulateDrag;
exports.getHandlerId = getHandlerId;
var _testUtils = require("react-dom/test-utils");
function simulateDragDrop(source, target, backend) {
const sourceHandlerId = getHandlerId(source);
const targetHandlerId = getHandlerId(target);
(0, _testUtils).act(()=>{
backend.simulateBeginDrag([
sourceHandlerId
]);
backend.simulateHover([
targetHandlerId
]);
backend.simulateDrop();
backend.simulateEndDrag();
});
}
function simulateDragHover(source, target, backend) {
const sourceHandlerId = getHandlerId(source);
const targetHandlerId = getHandlerId(target);
(0, _testUtils).act(()=>{
backend.simulateBeginDrag([
sourceHandlerId
]);
backend.simulateHover([
targetHandlerId
]);
});
}
function simulateDrag(source, backend) {
const sourceHandlerId = getHandlerId(source);
(0, _testUtils).act(()=>{
backend.simulateBeginDrag([
sourceHandlerId
]);
});
}
function getHandlerId(provider) {
if (typeof provider === 'string' || typeof provider === 'symbol') {
return provider;
} else if (typeof provider === 'function') {
return provider();
} else {
throw new Error('Could not get handlerId from DnD source');
}
}
//# sourceMappingURL=eventSimulation.js.map