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 () {
/*
* Register gadget
*/
gadget_list.push(gadget);
if (RenderJs.GadgetIndex.getGadgetById(gadget.id) === undefined) {
// register only if not already added
gadget_list.push(gadget);
}
},
unregisterGadget: function (gadget) {
......
......@@ -62,12 +62,16 @@ function setupRenderJSTest(){
dom = $("#qunit-fixture");
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
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);
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
});
});
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