Skip to content

Commit 588a95f

Browse files
committed
test: add test for onDragStateChanged
1 parent 1848921 commit 588a95f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Diff for: src/react-sortable-tree.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,51 @@ describe('<SortableTree />', () => {
338338
mount(<TouchWrapped treeData={[{ title: 'a' }]} onChange={() => {}} />)
339339
).toBeDefined();
340340
});
341+
342+
it('loads using SortableTreeWithoutDndContext', () => {
343+
const TestWrapped = DragDropContext(HTML5Backend)(
344+
SortableTreeWithoutDndContext
345+
);
346+
347+
const onDragStateChanged = jest.fn();
348+
const treeData = [{ title: 'a' }, { title: 'b' }];
349+
const wrapper = mount(
350+
<TestWrapped
351+
treeData={treeData}
352+
onDragStateChanged={onDragStateChanged}
353+
onChange={() => {}}
354+
/>
355+
);
356+
357+
// Obtain a reference to the backend
358+
const backend = wrapper
359+
.instance()
360+
.getManager()
361+
.getBackend();
362+
363+
// Retrieve our DnD-wrapped node component type
364+
const wrappedNodeType = wrapper
365+
.find(SortableTreeWithoutDndContext)
366+
.instance().nodeContentRenderer;
367+
368+
// And get the first such component
369+
const nodeInstance = wrapper
370+
.find(wrappedNodeType)
371+
.first()
372+
.instance();
373+
374+
backend.simulateBeginDrag([nodeInstance.getHandlerId()]);
375+
376+
expect(onDragStateChanged).toHaveBeenCalledWith({
377+
isDragging: true,
378+
draggedNode: treeData[0],
379+
});
380+
381+
backend.simulateEndDrag([nodeInstance.getHandlerId()]);
382+
383+
expect(onDragStateChanged).toHaveBeenCalledWith({
384+
isDragging: false,
385+
draggedNode: null,
386+
});
387+
});
341388
});

0 commit comments

Comments
 (0)