Commit 9289dca0 authored by Ivan Tyagov's avatar Ivan Tyagov

Do not registerGadget more than once for an ID. Add tests for this.

parent 9f081612
...@@ -498,7 +498,10 @@ var RenderJs = (function () { ...@@ -498,7 +498,10 @@ var RenderJs = (function () {
/* /*
* Register gadget * Register gadget
*/ */
if (RenderJs.GadgetIndex.getGadgetById(gadget.id) === undefined) {
// register only if not already added
gadget_list.push(gadget); gadget_list.push(gadget);
}
}, },
unregisterGadget: function (gadget) { unregisterGadget: function (gadget) {
......
...@@ -62,12 +62,16 @@ function setupRenderJSTest(){ ...@@ -62,12 +62,16 @@ function setupRenderJSTest(){
dom = $("#qunit-fixture"); dom = $("#qunit-fixture");
deepEqual(["new"], RenderJs.GadgetIndex.getGadgetIdListFromDom(dom)); deepEqual(["new"], RenderJs.GadgetIndex.getGadgetIdListFromDom(dom));
// try register gadget twice and check it's registered once only
RenderJs.GadgetIndex.registerGadget(RenderJs.GadgetIndex.getGadgetById("new"));
// test unregister gadget // test unregister gadget
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("GadgetObject"); module("GadgetObject");
......
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