UNPKG

vue3-dnd

Version:

Drag and Drop for Vue Composition API

146 lines (145 loc) 5.97 kB
"use strict"; var _dragSourceImpl = require("../DragSourceImpl"); var _vitest = require("vitest"); (0, _vitest).describe("The Hooks DragSourceImpl", function() { var monitor = {}; var connector = {}; (0, _vitest).describe("canDrag()", function() { (0, _vitest).it("returns true by default", function() { var impl = new _dragSourceImpl.DragSourceImpl({}, monitor, connector); (0, _vitest).expect(impl.canDrag()).toEqual(true); }); (0, _vitest).it("returns the result of canDrag if it is a boolean", function() { var impl = new _dragSourceImpl.DragSourceImpl({ type: "box", canDrag: true }, monitor, connector); (0, _vitest).expect(impl.canDrag()).toEqual(true); impl = new _dragSourceImpl.DragSourceImpl({ type: "box", canDrag: false }, monitor, connector); (0, _vitest).expect(impl.canDrag()).toEqual(false); }); (0, _vitest).it("will invoke canDrag if it is a function", function() { var impl = new _dragSourceImpl.DragSourceImpl({ canDrag: function(m) { (0, _vitest).expect(m).toEqual(monitor); return true; } }, monitor, connector); (0, _vitest).expect(impl.canDrag()).toEqual(true); }); }); (0, _vitest).describe("beginDrag()", function() { (0, _vitest).it("returns a drag-item even if an item is not defined in the spec", function() { var impl = new _dragSourceImpl.DragSourceImpl({}, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual({}); }); (0, _vitest).it("returns the dragItem from the spec", function() { var item = {}; var impl = new _dragSourceImpl.DragSourceImpl({ type: "test", item: item }, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual(item); }); (0, _vitest).it("will return the result of item() if it is defined", function() { var item = {}; var impl = new _dragSourceImpl.DragSourceImpl({ type: "test", item: function() { return item; } }, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual(item); }); (0, _vitest).it("will return null if begin() returns a nullish value", function() { var impl = new _dragSourceImpl.DragSourceImpl({ type: "test", item: function() { return null; } }, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual(null); impl = new _dragSourceImpl.DragSourceImpl({ type: "test", item: function() { return undefined; } }, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual(null); }); (0, _vitest).it("will return an empty object if begin return a nullish value and item is nullish", function() { var impl = new _dragSourceImpl.DragSourceImpl({ begin: function() { return null; } }, monitor, connector); (0, _vitest).expect(impl.beginDrag()).toEqual({}); }); }); (0, _vitest).describe("isDragging()", function() { (0, _vitest).it("performs an ID check by default", function() { var globalMon = { getSourceId: function() { return "1"; } }; var impl = new _dragSourceImpl.DragSourceImpl({ type: "box" }, monitor, connector); (0, _vitest).expect(impl.isDragging(globalMon, "1")).toBeTruthy(); (0, _vitest).expect(impl.isDragging(globalMon, "2")).toBeFalsy(); }); (0, _vitest).it("will invoke isDragging()", function() { var impl = new _dragSourceImpl.DragSourceImpl({ type: "box", isDragging: function() { return true; } }, monitor, connector); (0, _vitest).expect(impl.isDragging(null, "1")).toBeTruthy(); impl = new _dragSourceImpl.DragSourceImpl({ type: "box", isDragging: function() { return false; } }, monitor, connector); (0, _vitest).expect(impl.isDragging(null, "1")).toBeFalsy(); }); }); (0, _vitest).describe("endDrag()", function() { (0, _vitest).it("will reconnect by default", function() { var reconnect = _vitest.vi.fn(); var impl = new _dragSourceImpl.DragSourceImpl({ type: "box" }, monitor, { reconnect: reconnect }); impl.endDrag(); (0, _vitest).expect(reconnect.mock.calls.length).toEqual(1); }); (0, _vitest).it("will invoke end() in spec before reconnecting ", function() { var reconnect = _vitest.vi.fn(); var end = _vitest.vi.fn(); var item = { x: 1 }; var impl = new _dragSourceImpl.DragSourceImpl({ type: "box", end: end }, { getItem: function() { return item; } }, { reconnect: reconnect }); impl.endDrag(); (0, _vitest).expect(reconnect.mock.calls.length).toEqual(1); (0, _vitest).expect(end.mock.calls.length).toEqual(1); (0, _vitest).expect(end.mock.calls[0][0]).toEqual(item); }); }); });