summaryrefslogtreecommitdiff
path: root/addons/mrp/static/tests/mrp_tests.js
blob: f05a5b420affc5affdfa89f0523fe6906fc72468 (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
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
odoo.define('mrp.tests', function (require) {
"use strict";

var FormView = require('web.FormView');
var testUtils = require("web.test_utils");

var createView = testUtils.createView;

QUnit.module('mrp', {
    beforeEach: function () {
        this.data = {
            partner: {
                fields: {
                    state: {
                        string: "State",
                        type: "selection",
                        selection: [['waiting', 'Waiting'], ['chilling', 'Chilling']],
                    },
                    duration: {string: "Duration", type: "float"},
                },
                records: [{
                    id: 1,
                    state: 'waiting',
                    duration: 6000,
                }],
                onchanges: {},
            },
        };
    },
}, function () {

    QUnit.test("bullet_state: basic rendering", async function (assert) {
        assert.expect(2);

        var form = await createView({
            View: FormView,
            model: 'partner',
            data: this.data,
            res_id: 1,
            arch:
                '<form>' +
                    '<field name="state" widget="bullet_state" options="{\'classes\': {\'waiting\': \'danger\'}}"/>' +
                '</form>',
        });

        assert.strictEqual(form.$('.o_field_widget').text(), "Waiting Materials",
            "the widget should be correctly named");
        assert.containsOnce(form, '.o_field_widget .badge-danger',
            "the badge should be danger");

        form.destroy();
    });

    QUnit.test("mrp_time_counter: basic rendering", async function (assert) {
        assert.expect(2);
        var data = {
            foo: {
                fields: { duration: { string: "Duration", type: "float" } },
                records: [{id: 1, duration:150.5}]
            },
        };
        var form = await createView({
            View: FormView,
            model: 'foo',
            data: data,
            res_id: 1,
            arch:
                '<form>' +
                    '<field name="duration" widget="mrp_time_counter"/>' +
                '</form>',
            mockRPC: function (route, args) {
                if (args.method === 'search_read' && args.model === 'mrp.workcenter.productivity') {
                    assert.ok(true, "the widget should fetch the mrp.workcenter.productivity");
                    return Promise.resolve([]);
                }
                return this._super.apply(this, arguments);
            },
        });

        assert.strictEqual(form.$('.o_field_widget[name="duration"]').text(), "150:30",
            "the timer should be correctly set");

        form.destroy();
    });

    QUnit.test("embed_viewer rendering in form view", async function (assert) {
        assert.expect(8);
        var data = {
            foo: {
                fields: { char_url: { string: "URL", type: "char" } },
                records: [{ id: 1 }]
            },
        };

        var form = await createView({
            View: FormView,
            model: 'foo',
            data: data,
            arch:
                '<form>' +
                '<field name="char_url" widget="embed_viewer"/>' +
                '</form>',
            res_id: 1,
            mockRPC: function (route) {
                if (route === ('http://example.com')) {
                    return Promise.resolve();
                }
                return this._super.apply(this, arguments);
            }
        });

        assert.isNotVisible(form.$('iframe.o_embed_iframe'), "there should be an invisible iframe readonly mode");
        assert.strictEqual(_.has(form.$('iframe.o_embed_iframe')[0].attributes, "src"), false,
            "src attribute is not set if there are no values");
        await testUtils.form.clickEdit(form);
        assert.isNotVisible(form.$('iframe.o_embed_iframe'), "there should be an invisible iframe in edit mode");
        await testUtils.fields.editAndTrigger(form.$('.o_field_char'), 'http://example.com', ['input', 'change', 'focusout']);
        assert.strictEqual(form.$('iframe.o_embed_iframe').attr('src'), 'http://example.com',
            "src should updated on the iframe");
        assert.isVisible(form.$('iframe.o_embed_iframe'), "there should be a visible iframe in edit mode");
        await testUtils.form.clickSave(form);
        assert.isVisible(form.$('iframe.o_embed_iframe'), "there should be a visible iframe in readonly mode");
        assert.strictEqual(form.$('iframe.o_embed_iframe').attr('data-src'), 'http://example.com',
            "should have updated src in readonly mode");

        // In readonly mode, we are not displaying the URL, only iframe will be there.
        assert.strictEqual(form.$('.iframe.o_embed_iframe').siblings().length, 0,
            "there shouldn't be any siblings of iframe in readonly mode");

        form.destroy();
    });
});
});