vue3-dnd
Version:
Drag and Drop for Vue Composition API
83 lines (82 loc) • 2.63 kB
JavaScript
import { DropTargetImpl } from "../DropTargetImpl";
import { describe, it, vi, expect } from "vitest";
describe("The Hooks DropTargetImpl", function() {
describe("canDrag()", function() {
it("can determine if a item can drag", function() {
var monitor = {
getItem: function() {
return {};
}
};
var impl = new DropTargetImpl({}, monitor);
expect(impl.canDrop()).toEqual(true);
impl = new DropTargetImpl({
canDrop: function canDrop(_item, mon) {
expect(mon).toEqual(monitor);
return false;
}
}, monitor);
expect(impl.canDrop()).toEqual(false);
});
});
describe("hover()", function() {
it("will not throw if spec.hover is not defined", function() {
var item = {};
var monitor = {
getItem: function() {
return item;
}
};
var impl = new DropTargetImpl({}, monitor);
impl.hover();
});
it("will invoke hover if it is defined", function() {
var item = {};
var monitor = {
getItem: function() {
return item;
}
};
var hover = vi.fn();
var impl = new DropTargetImpl({
hover: hover
}, monitor);
impl.hover();
expect(hover.mock.calls.length).toEqual(1);
expect(hover.mock.calls[0]).toEqual([
item,
monitor
]);
});
});
describe("drop()", function() {
it("will not throw if spec.drop is not defined", function() {
var item = {};
var monitor = {
getItem: function() {
return item;
}
};
var impl = new DropTargetImpl({}, monitor);
impl.drop();
});
it("will invoke drop if it is defined", function() {
var item = {};
var monitor = {
getItem: function() {
return item;
}
};
var drop = vi.fn();
var impl = new DropTargetImpl({
drop: drop
}, monitor);
impl.drop();
expect(drop.mock.calls.length).toEqual(1);
expect(drop.mock.calls[0]).toEqual([
item,
monitor
]);
});
});
});