[Representation] Add DnD service

Add service to communicate data after/during a drag-and-drop, to allow
drag contents to be checked during dragover, and to allow full JavaScript
objects to be passed during drags (within the same window.) WTD-988.
This commit is contained in:
Victor Woeltjen
2015-03-19 12:34:52 -07:00
parent d814c0fc18
commit 818510da14
6 changed files with 155 additions and 10 deletions

View File

@@ -0,0 +1,45 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/services/DndService"],
function (DndService) {
"use strict";
describe("The drag-and-drop service", function () {
var service;
beforeEach(function () {
var mockLog = jasmine.createSpyObj("$log", ['debug']);
service = new DndService(mockLog);
});
it("allows setting of arbitrary objects", function () {
var foo = {
bar: function () { return 42; }
};
service.setData('xyz', foo);
// Test that we can get back callable data, since this is
// a key reason for having a service separate from HTML5 DnD.
expect(service.getData('xyz').bar()).toEqual(42);
});
it("stores data under specified keys", function () {
service.setData('abc', 42);
service.setData('def', "some data");
expect(service.getData('abc')).toEqual(42);
expect(service.getData('def')).toEqual("some data");
});
it("removes data", function () {
service.setData('abc', 42);
service.removeData('abc');
expect(service.getData('abc')).toBeUndefined();
});
});
}
);