[FIX] tests: update jquery link, fix broken searchview test following merge
[odoo/odoo.git] / addons / web / static / test / class.js
1 $(document).ready(function () {
2     var openerp;
3     module('web-class', {
4         setup: function () {
5             openerp = window.openerp.init([]);
6             window.openerp.web.corelib(openerp);
7         }
8     });
9     test('Basic class creation', function () {
10         var C = openerp.web.Class.extend({
11             foo: function () {
12                 return this.somevar;
13             }
14         });
15         var instance = new C();
16         instance.somevar = 3;
17
18         ok(instance instanceof C);
19         strictEqual(instance.foo(), 3);
20     });
21     test('Class initialization', function () {
22         var C1 = openerp.web.Class.extend({
23             init: function () {
24                 this.foo = 3;
25             }
26         });
27         var C2 = openerp.web.Class.extend({
28             init: function (arg) {
29                 this.foo = arg;
30             }
31         });
32
33         var i1 = new C1(),
34             i2 = new C2(42);
35
36         strictEqual(i1.foo, 3);
37         strictEqual(i2.foo, 42);
38     });
39     test('Inheritance', function () {
40         var C0 = openerp.web.Class.extend({
41             foo: function () {
42                 return 1;
43             }
44         });
45         var C1 = C0.extend({
46             foo: function () {
47                 return 1 + this._super();
48             }
49         });
50         var C2 = C1.extend({
51             foo: function () {
52                 return 1 + this._super();
53             }
54         });
55
56         strictEqual(new C0().foo(), 1);
57         strictEqual(new C1().foo(), 2);
58         strictEqual(new C2().foo(), 3);
59     });
60     test('In-place extension', function () {
61         var C0 = openerp.web.Class.extend({
62             foo: function () {
63                 return 3;
64             },
65             qux: function () {
66                 return 3;
67             },
68             bar: 3
69         });
70         C0.include({
71             foo: function () {
72                 return 5;
73             },
74             qux: function () {
75                 return 2 + this._super();
76             },
77             bar: 5,
78             baz: 5
79         });
80
81         strictEqual(new C0().bar, 5);
82         strictEqual(new C0().baz, 5);
83         strictEqual(new C0().foo(), 5);
84         strictEqual(new C0().qux(), 5);
85     });
86     test('In-place extension and inheritance', function () {
87         var C0 = openerp.web.Class.extend({
88             foo: function () { return 1; },
89             bar: function () { return 1; }
90         });
91         var C1 = C0.extend({
92             foo: function () { return 1 + this._super(); }
93         });
94         strictEqual(new C1().foo(), 2);
95         strictEqual(new C1().bar(), 1);
96
97         C1.include({
98             foo: function () { return 2 + this._super(); },
99             bar: function () { return 1 + this._super(); }
100         });
101         strictEqual(new C1().foo(), 4);
102         strictEqual(new C1().bar(), 2);
103     });
104     test('In-place extensions alter existing instances', function () {
105         var C0 = openerp.web.Class.extend({
106             foo: function () { return 1; },
107             bar: function () { return 1; }
108         });
109         var instance = new C0();
110         strictEqual(instance.foo(), 1);
111         strictEqual(instance.bar(), 1);
112
113         C0.include({
114             foo: function () { return 2; },
115             bar: function () { return 2 + this._super(); }
116         });
117         strictEqual(instance.foo(), 2);
118         strictEqual(instance.bar(), 3);
119     });
120     test('In-place extension of subclassed types', function () {
121         var C0 = openerp.web.Class.extend({
122             foo: function () { return 1; },
123             bar: function () { return 1; }
124         });
125         var C1 = C0.extend({
126             foo: function () { return 1 + this._super(); },
127             bar: function () { return 1 + this._super(); }
128         });
129         var instance = new C1();
130         strictEqual(instance.foo(), 2);
131         C0.include({
132             foo: function () { return 2; },
133             bar: function () { return 2 + this._super(); }
134         });
135         strictEqual(instance.foo(), 3);
136         strictEqual(instance.bar(), 4);
137     });
138 });