vue3-dnd
Version:
Drag and Drop for Vue Composition API
57 lines (56 loc) • 2.3 kB
JavaScript
import { DragSourceMonitorImpl } from "../DragSourceMonitorImpl";
import { createDragDropManager } from "dnd-core";
import { TestBackend } from "react-dnd-test-backend";
import { describe, it, vi, expect } from "vitest";
describe("The DragSourceMonitorImpl", function() {
it("can be constructed", function() {
var manager = createDragDropManager(TestBackend);
var monitor = new DragSourceMonitorImpl(manager);
expect(monitor).toBeDefined();
});
it("uses the monitor for canDrag", function() {
var canDragSource = vi.fn();
var manager = createDragDropManager(TestBackend);
manager.getMonitor().canDragSource = canDragSource;
var monitor = new DragSourceMonitorImpl(manager);
monitor.canDragSource("123");
expect(canDragSource.mock.calls).toHaveLength(1);
expect(canDragSource.mock.calls[0]).toEqual([
"123"
]);
});
it("throws if canDrag is used in a loop", function() {
var manager = createDragDropManager(TestBackend);
var monitor = new DragSourceMonitorImpl(manager);
manager.getMonitor().canDragSource = function(a) {
return monitor.canDrag(a);
};
expect(function() {
return monitor.canDragSource("123");
}).toThrow("You may not call monitor.canDrag() inside your canDrag() implementation. Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor");
});
it("thunks to monitor methods", function() {
var manager = createDragDropManager(TestBackend);
var monitor = new DragSourceMonitorImpl(manager);
var THUNK_METHODS = [
"getTargetIds",
"isSourcePublic",
"getSourceId",
"getItemType",
"getItem",
"getDropResult",
"didDrop",
"getInitialClientOffset",
"getInitialSourceClientOffset",
"getSourceClientOffset",
"getClientOffset",
"getDifferenceFromInitialOffset",
];
THUNK_METHODS.forEach(function(method) {
var mock = vi.fn();
manager.getMonitor()[method] = mock;
monitor[method]();
expect(mock.mock.calls).toHaveLength(1);
});
});
});