summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/views/qweb_tests.js
blob: 19acf9b06c35631ca093ccc23bff1849f1e765f8 (plain)
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
odoo.define('web.qweb_view_tests', function (require) {
"use strict";

var utils = require('web.test_utils');

QUnit.module("Views", {

}, function () {
    QUnit.module("QWeb");
    QUnit.test("basic", async function (assert) {
        assert.expect(14);
        var am = await utils.createActionManager({
            data: {
                test: {
                    fields: {},
                    records: [],
                }
            },
            archs: {
                'test,5,qweb': '<div id="xxx"><t t-esc="ok"/></div>',
                'test,false,search': '<search/>'
            },
            mockRPC: function (route, args) {
                if (/^\/web\/dataset\/call_kw/.test(route)) {
                    switch (_.str.sprintf('%(model)s.%(method)s', args)) {
                    case 'test.qweb_render_view':
                        assert.step('fetch');
                        assert.equal(args.kwargs.view_id, 5);
                        return Promise.resolve(
                            '<div>foo' +
                                '<div data-model="test" data-method="wheee" data-id="42" data-other="5">' +
                                    '<a type="toggle" class="fa fa-caret-right">Unfold</a>' +
                                '</div>' +
                            '</div>'
                        );
                    case 'test.wheee':
                        assert.step('unfold');
                        assert.deepEqual(args.args, [42]);
                        assert.deepEqual(args.kwargs, {other: 5});
                        return Promise.resolve('<div id="sub">ok</div>');
                    }
                }
                return this._super.apply(this, arguments);
            }
        });
        try {
            var resolved = false;
            am.doAction({
                type: 'ir.actions.act_window',
                views: [[false, 'qweb']],
                res_model: 'test',
            }).then(function () { resolved = true; });
            assert.ok(!resolved, "Action cannot be resolved synchronously");

            await utils.nextTick();
            assert.ok(resolved, "Action is resolved asynchronously");

            var $content = am.$('.o_content');
            assert.ok(/^\s*foo/.test($content.text()));
            await utils.dom.click($content.find('[type=toggle]'));
            assert.equal($content.find('div#sub').text(), 'ok', 'should have unfolded the sub-item');
            await utils.dom.click($content.find('[type=toggle]'));
            assert.equal($content.find('div#sub').length, 0, "should have removed the sub-item");
            await utils.dom.click($content.find('[type=toggle]'));

            assert.verifySteps(['fetch', 'unfold', 'unfold']);
        } finally {
            am.destroy();
        }
    });
});
});