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 () { ...@@ -51,9 +51,10 @@ var RenderJs = (function () {
bootstrap: function (root) { bootstrap: function (root) {
/* initial load application gadget */ /* initial load application gadget */
var gadget_id; var gadget_id, is_gadget;
gadget_id = root.attr("id"); 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 // bootstart root gadget only if it is indeed a gadget
RenderJs.loadGadgetFromUrl(root); RenderJs.loadGadgetFromUrl(root);
} }
...@@ -254,8 +255,10 @@ var RenderJs = (function () { ...@@ -254,8 +255,10 @@ var RenderJs = (function () {
tab_container.append(html_string); tab_container.append(html_string);
tab_gadget = tab_container.find(".gadget"); tab_gadget = tab_container.find(".gadget");
// render new gadget // render new gadget
RenderJs.loadGadgetFromUrl(tab_gadget); RenderJs.bootstrap(tab_container);
// this will make RenderJs fire "ready" event when all gadgets are loaded. // this will make RenderJs fire "ready" event when all gadgets are loaded.
RenderJs.setReady(false); RenderJs.setReady(false);
return tab_gadget; return tab_gadget;
......
...@@ -33,30 +33,38 @@ function setupRenderJSTest(){ ...@@ -33,30 +33,38 @@ function setupRenderJSTest(){
module("GadgetIndex"); module("GadgetIndex");
test('GadgetIndex', function () { test('GadgetIndex', function () {
cleanUp(); 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.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){ stop();
RenderJs.bindReady(function (){
RenderJs.update($("#qunit-fixture")); RenderJs.update($("#qunit-fixture"));
}); start();
equal(RenderJs.GadgetIndex.getGadgetList().length, 2); equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded()); equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
equal($("#qunit-fixture").attr("id"), RenderJs.GadgetIndex.getRootGadget().getDom().attr("id")); equal("new", RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
equal(RenderJs.GadgetIndex.getGadgetById("qunit-fixture"), RenderJs.GadgetIndex.getRootGadget()); equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
// unregister gadget all gadgets from this test not to mess with rest of tests // 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.getGadgetList().length, 1); equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget()); RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new"));
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new")); equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
equal(RenderJs.GadgetIndex.getGadgetList().length, 0); });
}); });
module("addGadget"); module("addGadget");
test('addGadget', function () { test('addGadget', function () {
cleanUp(); cleanUp();
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
RenderJs.addGadget("qunit-fixture", "loading/test-gadget.html", "", ""); RenderJs.addGadget("qunit-fixture", "loading/test-gadget.html", "", "");
equal($("#qunit-fixture").children(".gadget").length, 1); stop();
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
RenderJs.bindReady(function (){
start();
equal($("#qunit-fixture").children(".gadget").length, 1);
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
});
}); });
module("GadgetInitialization"); module("GadgetInitialization");
...@@ -64,7 +72,7 @@ function setupRenderJSTest(){ ...@@ -64,7 +72,7 @@ function setupRenderJSTest(){
cleanUp(); 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>'); $("#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.bootstrap($("#qunit-fixture"));
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function (){ RenderJs.bindReady(function (){
RenderJs.update($("#qunit-fixture")); RenderJs.update($("#qunit-fixture"));
}); });
...@@ -81,7 +89,7 @@ function setupRenderJSTest(){ ...@@ -81,7 +89,7 @@ function setupRenderJSTest(){
stop(); stop();
// we need to wait for all gadgets loading ... // we need to wait for all gadgets loading ...
RenderJs.GadgetIndex.getRootGadget().getDom().one("ready", function () { RenderJs.bindReady(function () {
start(); start();
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded()); equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
}); });
...@@ -94,7 +102,7 @@ function setupRenderJSTest(){ ...@@ -94,7 +102,7 @@ function setupRenderJSTest(){
stop(); stop();
// we need to wait for all gadgets loading ... // we need to wait for all gadgets loading ...
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () { RenderJs.bindReady(function () {
RenderJs.InteractionGadget.bind($("#main-interactor")); RenderJs.InteractionGadget.bind($("#main-interactor"));
start(); start();
equal(0, counter); 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