Commit 20838886 authored by Ivan Tyagov's avatar Ivan Tyagov

Do not register a gadget unless it defines a data-gadget attributes.

Use custom bindReady rather than hooks in tests.
Stop tests execution to allow RenderJs finish loading gadgets thus we
can really test when this is done.
parent cb263573
......@@ -51,9 +51,10 @@ var RenderJs = (function () {
bootstrap: function (root) {
/* initial load application gadget */
var gadget_id;
var gadget_id, is_gadget;
gadget_id = root.attr("id");
if (gadget_id!==undefined) {
is_gadget = root.attr("data-gadget")!==undefined;
if (is_gadget && gadget_id!==undefined ) {
// bootstart root gadget only if it is indeed a gadget
RenderJs.loadGadgetFromUrl(root);
}
......@@ -254,8 +255,10 @@ var RenderJs = (function () {
tab_container.append(html_string);
tab_gadget = tab_container.find(".gadget");
// render new gadget
RenderJs.loadGadgetFromUrl(tab_gadget);
RenderJs.bootstrap(tab_container);
// this will make RenderJs fire "ready" event when all gadgets are loaded.
RenderJs.setReady(false);
return tab_gadget;
......
......@@ -33,38 +33,46 @@ function setupRenderJSTest(){
module("GadgetIndex");
test('GadgetIndex', function () {
cleanUp();
$("#qunit-fixture").append('<div data-gadget="" id="new">X</div>');
$("#qunit-fixture").append('<div data-gadget="loading/test-gadget.html" id="new">X</div>');
RenderJs.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
stop();
RenderJs.bindReady(function (){
RenderJs.update($("#qunit-fixture"));
});
equal(RenderJs.GadgetIndex.getGadgetList().length, 2);
start();
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
equal($("#qunit-fixture").attr("id"), RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
equal(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"), RenderJs.GadgetIndex.getRootGadget());
equal("new", RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
// unregister gadget all gadgets from this test not to mess with rest of tests
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"));
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new"));
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
});
});
module("addGadget");
test('addGadget', function () {
cleanUp();
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
RenderJs.addGadget("qunit-fixture", "loading/test-gadget.html", "", "");
stop();
RenderJs.bindReady(function (){
start();
equal($("#qunit-fixture").children(".gadget").length, 1);
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
});
});
module("GadgetInitialization");
test('GadgetInitialization', function () {
cleanUp();
$("#qunit-fixture").append('<div data-gadget="" id="new-init" data-gadget-property="{&quot;name&quot;: &quot;Ivan&quot;, &quot;age&quot;: 33}">X</div>');
RenderJs.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){
RenderJs.bindReady(function (){
RenderJs.update($("#qunit-fixture"));
});
......@@ -81,7 +89,7 @@ function setupRenderJSTest(){
stop();
// we need to wait for all gadgets loading ...
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function () {
RenderJs.bindReady(function () {
start();
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
});
......@@ -94,7 +102,7 @@ function setupRenderJSTest(){
stop();
// we need to wait for all gadgets loading ...
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () {
RenderJs.bindReady(function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));
start();
equal(0, counter);
......
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