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
|
<!doctype html>
<html>
<head>
<script src="/web/static/lib/jquery/jquery.js"></script>
<link rel="stylesheet" href="/web/static/lib/qunit/qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="/web/static/lib/qunit/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();
}
/**
* Loads the template file, and executes all the test template in a
* qunit module $title
*/
function test(title, template) {
QUnit.module(title, {
setup: function () {
var self = this;
this.qweb = new QWeb2.Engine();
QUnit.stop();
this.qweb.add_template(template, function (_, doc) {
self.doc = doc;
QUnit.start();
})
}
});
QUnit.test('autotest', function (assert) {
var templates = this.qweb.templates;
for (var template in templates) {
if (!templates.hasOwnProperty(template)) { continue; }
// ignore templates whose name starts with _, they're
// helpers/internal
if (/^_/.test(template)) { continue; }
var params = this.doc.querySelector('params#' + template);
var args = params ? JSON.parse(params.textContent) : {};
var results = this.doc.querySelector('result#' + template);
assert.equal(
trim(this.qweb.render(template, args)),
trim(results.textContent),
template);
}
});
}
$(document).ready(function() {
test("Output", 'qweb-test-output.xml');
test("Context-setting", 'qweb-test-set.xml');
test("Conditionals", 'qweb-test-conditionals.xml');
test("Attributes manipulation", 'qweb-test-attributes.xml');
test("Template calling (to the faraway pages)",
'qweb-test-call.xml');
test("Foreach", 'qweb-test-foreach.xml');
test("Global", 'qweb-test-global.xml');
test('Template inheritance', 'qweb-test-extend.xml');
});
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
|