-
Notifications
You must be signed in to change notification settings - Fork 8
/
qweb-test.js.html
270 lines (257 loc) · 12.7 KB
/
qweb-test.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.2.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="qweb2.js"></script>
<script>
QWeb = new QWeb2.Engine();
function trim(s) {
return s.replace(/(^\s+|\s+$)/g, '');
}
function render(template, context) {
return trim(QWeb.render(template, context)).toLowerCase();
}
$(document).ready(function() {
module("Basic output tests", {
setup: function () {
QWeb.add_template('qweb-test-output.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test("Basic escaped output", function () {
equals(render('esc-literal', {}), "ok", "Render a literal string");
equals(render('esc-variable', {ok: 'ok'}), "ok", "Render a string variable");
equals(render('esc-toescape', {ok: '<ok>'}), "<ok>", "Render a string with data to escape");
});
test("Formatted escaped output", function () {
equals(render('escf-noformat-literal', {}), "ok", "Render a literal string");
equals(render('escf-simpleformat-variable', {value: 'ok'}), "ok",
"Only render an interpolated variable");
equals(render('escf-format-variable', {value: 'ok'}), "[ok]",
"Actually formatted variable");
equals(render('escf-format-variable-with-escapes', {value: '<ok>'}), '[<ok>]',
"Render a formatted string with data to escape");
});
test("Basic unescaped output", function () {
equals(render('raw-literal', {}), "ok", "Render a literal string");
equals(render('raw-variable', {ok: 'ok'}), "ok", "Render a string variable");
equals(render('raw-notescaped', {ok: '<ok>'}), "<ok>", "Render a string with data not escaped");
});
test("Formatted unescaped output", function () {
equals(render('rawf-noformat-literal', {}), "ok", "Render a literal string");
equals(render('rawf-simpleformat-variable', {value: 'ok'}), "ok",
"Only render an interpolated variable");
equals(render('rawf-format-variable', {value: 'ok'}), "[ok]",
"Actually formatted variable");
equals(render('rawf-format-variable-notescaped', {value: '<ok>'}), '[<ok>]',
"Render a formatted string with data not escaped");
});
module("Context-setting tests", {
setup: function () {
QWeb.add_template('qweb-test-set.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test("Set literal value", function () {
equals(render('set-from-attribute-literal', {}), "ok",
"Set a literal value via @t-value");
equals(render('set-from-body-literal', {}), "ok",
"Set a literal value via @t-set body");
});
test("Set value looked up from context", function () {
equals(render('set-from-attribute-lookup', {value: 'ok'}), "ok",
"Set a value looked up in context via @t-value");
equals(render('set-from-body-lookup', {value: 'ok'}), 'ok',
"Set a value looked up in context via @t-set body and @t-esc");
});
module("Conditionals", {
setup: function () {
QWeb.add_template('qweb-test-conditionals.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test('Basic (single boolean) conditionals', function () {
equals(render('literal-conditional', {}), 'ok',
"Test on a literal value");
equals(render('boolean-value-conditional', {value: true}), 'ok',
"Test on a truthy variable value");
equals(render('boolean-value-conditional-false', {value: false}), '',
"Test on a falsy variable value");
});
test('Boolean expressions in conditionals', function () {
equals(render('negify', {}), 'ok',
"Negative");
equals(render('equality', {}), 'ok',
"Equality");
equals(render('difference', {}), 'ok',
"Difference");
equals(render('and', {}), 'ok',
"Boolean and");
equals(render('and-js', {}), 'ok',
"Boolean and via manually escaped JS operator");
equals(render('or', {}), 'ok',
"Boolean or");
equals(render('or-js', {}), 'ok',
"Boolean or using JS operator");
});
test('Comparison boolean tests in conditionals', function () {
equals(render('greater', {}), 'ok',
"Greater");
equals(render('greater-js', {}), 'ok',
"Greater, JS operator");
equals(render('lower', {}), 'ok',
"Lower");
equals(render('lower-js', {}), 'ok',
"Lower, JS operator");
equals(render('greater-or-equal', {}), 'ok',
"Greater or Equal");
equals(render('greater-or-equal-js', {}), 'ok',
"Greater or Equal, JS operator");
equals(render('lower-or-equal', {}), 'ok',
"Lower or Equal");
equals(render('lower-or-equal-js', {}), 'ok',
"Lower or Equal, JS operator");
});
module("Attributes manipulation", {
setup: function () {
QWeb.add_template('qweb-test-attributes.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test('Fixed-name attributes', function () {
equals(render('fixed-literal', {}), '<div foo="bar"/>',
"Fixed name and literal attribute value");
equals(render('fixed-variable', {value: 'ok'}), '<div foo="ok"/>',
"Fixed name and variable attribute value");
});
test('Tuple-based attributes', function () {
equals(render('tuple-literal', {}), '<div foo="bar"/>',
"Tuple-based literal attributes");
equals(render('tuple-variable', {att: ['foo', 'bar']}), '<div foo="bar"/>',
"Tuple-based variable attributes");
});
test('Fixed name, formatted value attributes', function () {
equals(render('format-literal', {}), '<div foo="bar"/>',
"Literal format");
equals(render('format-value', {value:'a'}), '<div foo="bar"/>',
"Valued format");
});
module("Template calling (including)", {
setup: function () {
QWeb.add_template('qweb-test-call.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test('Trivial call invocation', function () {
equals(render('basic-caller', {}), 'ok',
"Direct call of a second template");
});
test('Call invocation with body', function () {
equals(render('with-unused-body', {}), 'ok',
"Call of a second template with body unused");
equals(render('with-unused-setbody', {}), 'ok',
"Call of a second template with body directives unused");
});
test('Call invocation with body (used by callee)', function () {
equals(render('with-used-body', {}), 'ok',
"Call of a second template with body used");
});
test('Call invocation with parameters set (in body)', function () {
equals(render('with-used-setbody', {}), 'ok',
"Call of a second template with parameters");
});
test('Call invocation in-context (via import)', function () {
equals(render('in-context-import', {}), 'ok',
"Call with t-import (calls in current context)");
});
module("Foreach", {
setup: function () {
QWeb.add_template('qweb-test-foreach.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
var seq = [4,3,2,1,0];
test('Basic foreach repetition', function () {
equals(QWeb.render('repetition-text-content', {seq:seq}), '*****',
"Repetition of text content via foreach");
equals(QWeb.render('repetition-dom-content', {seq:seq}).toLowerCase(), '<b/><b/><b/><b/><b/>',
"Repetition of node content via foreach");
equals(QWeb.render('repetition-self', {seq:seq}).toLowerCase(), '<b/><b/><b/><b/><b/>',
"A node with a foreach repeats itself");
});
test("Foreach scope content", function () {
equals(QWeb.render('scope-self', {seq:seq}), '43210',
"each value of the sequence is available via the sequence name");
equals(QWeb.render('scope-value', {seq:seq}), '43210',
"each value of the sequence is also via the _value");
equals(QWeb.render('scope-index', {seq:seq}), '01234',
"the current 0-based index is available via _index");
equals(QWeb.render('scope-first', {seq:seq}), 'true false false false false ',
"_first says whether the current item is the first of the sequence");
equals(QWeb.render('scope-last', {seq:seq}), 'false false false false true ',
"_last says whether the current item is the last of the sequence");
equals(QWeb.render('scope-parity', {seq:seq}), 'even odd even odd even ',
"the parity (odd/even) of the current row is available via _parity");
equals(QWeb.render('scope-size', {seq:seq}), '5 5 5 5 5 ',
"the total length of the sequence is available through _size");
});
test('Name aliasing via t-as', function () {
equals(QWeb.render('aliasing', {seq:seq}), '43210',
"the inner value can be re-bound via t-as");
equals(QWeb.render('loopvars-aliasing', {seq:seq}), 'even odd even odd even ',
"inner loop variables should be rebound as well");
});
module("Template inheritance tests", {
setup: function () {
QWeb.add_template('qweb-test-extend.xml');
},
teardown: function () {
QWeb.templates = [];
QWeb.tag = {};
QWeb.att = {};
}
});
test("jQuery extend", function () {
equals(render('jquery-extend', {}), '<hr/><ul class="main"><li>1</li><li>2</li><li>3</li></ul><footer><b>[[end]]</b></footer>',
"Extend template with jQuery");
equals(render('jquery-extend-clone', {}), '<ul><li>one</li><li>[[cloned template]]</li></ul>',
"Clone template");
});
});
</script>
</head>
<body>
<h1 id="qunit-header">QWeb test suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>