Commit 5b0ca42e authored by Jérome Perrin's avatar Jérome Perrin

graph editor: test for dialog edition

parent b45cb38b
...@@ -528,13 +528,17 @@ ...@@ -528,13 +528,17 @@
return fieldset_gadget[0]; return fieldset_gadget[0];
}) })
.push(function (fieldset_gadget) { .push(function (fieldset_gadget) {
return RSVP.any([ // Expose the dialog handling promise so that we can wait for it in
// test.
gadget.props.dialog_promise = RSVP.any([
save_promise(fieldset_gadget, node_id), save_promise(fieldset_gadget, node_id),
delete_promise delete_promise
]); ]);
return gadget.props.dialog_promise;
}) })
.push(function () { .push(function () {
node_edit_popup.popup('close'); node_edit_popup.popup('close');
delete gadget.props.dialog_promise;
}); });
} }
......
/*global rJS, JSON, QUnit, jQuery, RSVP, console*/ /*global rJS, JSON, QUnit, jQuery, RSVP, console, setTimeout*/
(function (rJS, JSON, QUnit, RSVP, $) { (function (rJS, JSON, QUnit, RSVP, $) {
"use strict"; "use strict";
...@@ -262,21 +262,50 @@ ...@@ -262,21 +262,50 @@
stop(); stop();
function runTest() { function runTest() {
return jsplumb_gadget.getContent().then(function () { return jsplumb_gadget.getContent().then( function() {
$("div[title='Node 1']").simulate("dblclick"); // click on a node to see display the popup
$("div[title='Node 1']").simulate('dblclick');
// XXX popup not displayed
$("input[name='name']").val("Modified Name"); // Promises that handle the dialog actions are not available
$("input[value='Validate']").click(); // immediately after clicking.
}) var promise = RSVP.Promise( function (resolve) {
.then(function () { var fillDialog = function() {
return jsplumb_gadget.getContent(); if (! jsplumb_gadget.props.dialog_promise ) {
}) // Dialog not ready. Let's retry later.
.then(function (content) { // XXX this condition is actually incorrect. We need to wait
var graph = JSON.parse(content).graph, // for the event listener to have been registered for the
node = graph.node.N1; // dialog buttons. This setTimeout is good enough for now.
equal(node.name, "Modified Name"); return setTimeout(fillDialog, 1000);
}
// check displayed values
equal($("input[name='id']").val(), "N1");
equal($("input[name='name']").val(), "Node 1");
equal($("input[name='shape']").val(), "square");
// change the name
$("input[name='name']").val("Modified Name");
// and save
$("input[value='Validate']").click();
// resolve our test promise once the dialog handling promise is
// finished.
jsplumb_gadget.props.dialog_promise.then(resolve);
};
fillDialog();
} );
return promise.then( function () {
return jsplumb_gadget.getContent().then(function (content) {
var graph = JSON.parse(content).graph,
node = graph.node.N1;
// check the data is well modified.
equal("Modified Name", node.name);
});
}); });
});
} }
g.declareGadget("./index.html", { g.declareGadget("./index.html", {
...@@ -290,7 +319,7 @@ ...@@ -290,7 +319,7 @@
return RSVP.any([ return RSVP.any([
jsplumb_gadget.startService(), jsplumb_gadget.startService(),
runTest() runTest()
]); ]);
}) })
.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