From 8a8da7973a0e7ca62aafdee7a3eae7ed6f757f4a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:50:27 +0100 Subject: [PATCH] [imp] added some tests, debugged some bugs bzr revid: nicolas.vanhoren@openerp.com-20120224135027-axsjx7x0ajlzvolh --- addons/web/static/lib/nivjs/src/niv.js | 6 +---- addons/web/static/lib/nivjs/test/test.js | 33 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index 0106fceb5fd..e572edc73c1 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -340,8 +340,6 @@ niv = (function() { * for new components this argument should not be provided any more. */ init: function(parent) { - this._super(); - this.$element = $(document.createElement(this.tag_name)); this.setParent(parent); @@ -356,7 +354,7 @@ niv = (function() { if(this.$element != null) { this.$element.remove(); } - this._super(); + lib.GetterSetterMixin.destroy.call(this); }, /** * Renders the current widget and appends it to the given jQuery object or Widget. @@ -414,8 +412,6 @@ niv = (function() { }, _render_and_insert: function(insertion, target) { this.render_element(); - if (target instanceof openerp.web.Widget) - target = target.$element; insertion(target); return this.start(); }, diff --git a/addons/web/static/lib/nivjs/test/test.js b/addons/web/static/lib/nivjs/test/test.js index 1f4f379697d..c93dea99ac6 100644 --- a/addons/web/static/lib/nivjs/test/test.js +++ b/addons/web/static/lib/nivjs/test/test.js @@ -2,14 +2,20 @@ module("Class"); test("base", function() { - ok(!!niv.Class, "Class does not exist"); - ok(!!niv.Class.extend, "extend does not exist"); + ok(!!niv.Class, "Class does exist"); + ok(!!niv.Class.extend, "extend does exist"); var Claz = niv.Class.extend({ test: function() { return "ok"; } - }) + }); equal(new Claz().test(), "ok"); + var Claz2 = Claz.extend({ + test: function() { + return this._super() + "2"; + } + }); + equal(new Claz2().test(), "ok2"); }); module("DestroyableMixin"); @@ -93,3 +99,24 @@ test("base", function() { x.set({test: 2}); equal(tmp, 1); }); + +module("Widget"); + +test("base", function() { + var Claz = niv.Widget.extend({ + render_element: function() { + this.$element.attr("id", "testdiv"); + this.$element.html("test"); + } + }); + var x = new Claz(); + x.appendTo($("body")); + var $el = $("#testdiv"); + equal($el.length, 1); + equal($el.parents()[0], $("body")[0]); + equal($el.html(), "test"); + x.destroy(); + $el = $("#testdiv"); + equal($el.length, 0); +}); +