Commit 06f8842e authored by Jérome Perrin's avatar Jérome Perrin

test for drag & drop

parent e0f254a5
......@@ -114,70 +114,77 @@
}
},
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(
{class_definition: sample_class_definition, graph: {node: {}, edge: {}} });
{class_definition: sample_class_definition, graph: {node: {}, edge: {}} }
);
QUnit.config.testTimeout = 5000;
rJS(window).ready(function (g) {
test("Sample graph can be loaded and output is equal to input", function () {
var jsplumb_gadget;
stop();
g.declareGadget("./index.html", {
element: document.querySelector("#qunit-fixture")
})
.then(function (new_gadget) {
jsplumb_gadget = new_gadget;
return jsplumb_gadget.render(sample_data_graph);
test("Sample graph can be loaded and output is equal to input",
function () {
var jsplumb_gadget;
stop();
g.declareGadget("./index.html", {
element: document.querySelector("#qunit-fixture")
})
.then(function () {
return jsplumb_gadget.getContent();
})
.then(function (content) {
equal(content, sample_data_graph);
})
.fail(console.error.bind(this))
.always(start);
.then(function (new_gadget) {
jsplumb_gadget = new_gadget;
return jsplumb_gadget.render(sample_data_graph);
})
.then(function () {
return jsplumb_gadget.getContent();
})
.then(function (content) {
equal(content, sample_data_graph);
})
.fail(console.error.bind(this))
.always(start);
});
test("New node can be drag & dropped", function () {
var jsplumb_gadget;
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", {
element: document.querySelector("#qunit-fixture")
})
.then(function (new_gadget) {
jsplumb_gadget = new_gadget;
return 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);
jsplumb_gadget.render(sample_data_empty_graph);
})
.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);
return RSVP.any([
jsplumb_gadget.startService(),
runTest()
]);
})
.fail(console.error.bind(this))
.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