[imp] added some tests, debugged some bugs

bzr revid: nicolas.vanhoren@openerp.com-20120224135027-axsjx7x0ajlzvolh
This commit is contained in:
niv-openerp 2012-02-24 14:50:27 +01:00
parent a2b9874378
commit 8a8da7973a
2 changed files with 31 additions and 8 deletions

View File

@ -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();
},

View File

@ -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);
});