Commit 3c480534 authored by Jérome Perrin's avatar Jérome Perrin

test for drag & drop

parent f6483640
...@@ -114,70 +114,77 @@ ...@@ -114,70 +114,77 @@
} }
}, },
sample_data_graph = JSON.stringify( sample_data_graph = JSON.stringify(
{class_definition: sample_class_definition, graph: sample_graph }), {class_definition: sample_class_definition, graph: sample_graph }
),
sample_data_empty_graph = JSON.stringify( sample_data_empty_graph = JSON.stringify(
{class_definition: sample_class_definition, graph: {node: {}, edge: {}} }); {class_definition: sample_class_definition, graph: {node: {}, edge: {}} }
);
QUnit.config.testTimeout = 5000; QUnit.config.testTimeout = 5000;
rJS(window).ready(function (g) { rJS(window).ready(function (g) {
test("Sample graph can be loaded and output is equal to input", function () { test("Sample graph can be loaded and output is equal to input",
var jsplumb_gadget; function () {
stop(); var jsplumb_gadget;
g.declareGadget("./index.html", { stop();
element: document.querySelector("#qunit-fixture") g.declareGadget("./index.html", {
}) element: document.querySelector("#qunit-fixture")
.then(function (new_gadget) {
jsplumb_gadget = new_gadget;
return jsplumb_gadget.render(sample_data_graph);
}) })
.then(function () { .then(function (new_gadget) {
return jsplumb_gadget.getContent(); jsplumb_gadget = new_gadget;
}) return jsplumb_gadget.render(sample_data_graph);
.then(function (content) { })
equal(content, sample_data_graph); .then(function () {
}) return jsplumb_gadget.getContent();
.fail(console.error.bind(this)) })
.always(start); .then(function (content) {
equal(content, sample_data_graph);
})
.fail(console.error.bind(this))
.always(start);
}); });
test("New node can be drag & dropped", function () { test("New node can be drag & dropped", function () {
var jsplumb_gadget; var jsplumb_gadget;
stop(); stop();
function runTest() {
return jsplumb_gadget.getContent().then(function () {
// fake a drop event
var e = new Event('drop');
e.dataTransfer = {
getData: function(type){
// make sure we are called properly
equal(type, 'application/json');
return JSON.stringify("Example.Node");
}
};
jsplumb_gadget.props.main.dispatchEvent(e);
})
.then(function () {
return jsplumb_gadget.getContent();
})
.then(function (content) {
var node, graph = JSON.parse(content).graph;
equal(1, Object.keys(graph.node).length);
node = graph.node[Object.keys(graph.node)[0]];
equal('Example.Node', node._class);
});
}
g.declareGadget("./index.html", { g.declareGadget("./index.html", {
element: document.querySelector("#qunit-fixture") element: document.querySelector("#qunit-fixture")
}) })
.then(function (new_gadget) { .then(function (new_gadget) {
jsplumb_gadget = new_gadget; jsplumb_gadget = new_gadget;
return jsplumb_gadget.render(sample_data_empty_graph); jsplumb_gadget.render(sample_data_empty_graph);
})
/* XXX if we start service then we wait for ever
.then(function () {
return jsplumb_gadget.startService();
}) */
.then(function () {
// fake a drop event
var event = new CustomEvent('drop',{
stopPropagation: function() {return;},
dataTransfer:{
getData: function(type){
// make sure we are called properly
equal(type, 'application/json');
return 'Example.Node';
}
}
});
jsplumb_gadget.props.element.dispatchEvent(event);
}) })
.then(function () { .then(function () {
return jsplumb_gadget.getContent(); return RSVP.any([
}) jsplumb_gadget.startService(),
.then(function (content) { runTest()
var node, graph = JSON.parse(content).graph; ]);
equal(1, Object.keys(graph.node).length);
node = graph.node[Object.keys(graph.node)[0]];
equal('Example.Node', node._class);
}) })
.fail(console.error.bind(this)) .fail(console.error.bind(this))
.always(start); .always(start);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment