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

const KanbanView = require('web.KanbanView');
const ListView = require('web.ListView');
const PivotView = require('web.PivotView');
const testUtils = require('web.test_utils');

const createView = testUtils.createView;

QUnit.module('Base Import Tests', {
    beforeEach: function () {
        this.data = {
            foo: {
                fields: {
                    foo: {string: "Foo", type: "char"},
                },
                records: [
                    {id: 1, foo: "yop"},
                ]
            },
        };
    }
});

QUnit.test('import in favorite dropdown in list', async function (assert) {
    assert.expect(2);

    const list = await createView({
        View: ListView,
        model: 'foo',
        data: this.data,
        arch: '<tree><field name="foo"/></tree>',
    });

    testUtils.mock.intercept(list, 'do_action', function () {
        assert.ok(true, "should have triggered a do_action");
    });

    await testUtils.dom.click(list.$('.o_favorite_menu button'));
    assert.containsOnce(list, '.o_import_menu');

    await testUtils.dom.click(list.$('.o_import_menu button'));

    list.destroy();
});

QUnit.test('import favorite dropdown item should not in list with create="0"', async function (assert) {
    assert.expect(1);

    const list = await createView({
        View: ListView,
        model: 'foo',
        data: this.data,
        arch: '<tree create="0"><field name="foo"/></tree>',
    });

    await testUtils.dom.click(list.$('.o_favorite_menu button'));
    assert.containsNone(list, '.o_import_menu');

    list.destroy();
});

QUnit.test('import favorite dropdown item should not in list with import="0"', async function (assert) {
    assert.expect(1);

    const list = await createView({
        View: ListView,
        model: 'foo',
        data: this.data,
        arch: '<tree import="0"><field name="foo"/></tree>',
    });

    await testUtils.dom.click(list.$('.o_favorite_menu button'));
    assert.containsNone(list, '.o_import_menu');

    list.destroy();
});

QUnit.test('import in favorite dropdown in kanban', async function (assert) {
    assert.expect(2);

    const kanban = await createView({
        View: KanbanView,
        model: 'foo',
        data: this.data,
        arch: `<kanban>
                <templates>
                    <t t-name="kanban-box">
                        <div><field name="foo"/></div>
                    </t>
                </templates>
            </kanban>`,
    });

    testUtils.mock.intercept(kanban, 'do_action', function () {
        assert.ok(true, "should have triggered a do_action");
    });

    await testUtils.dom.click(kanban.$('.o_favorite_menu button'));
    assert.containsOnce(kanban, '.o_import_menu');

    await testUtils.dom.click(kanban.$('.o_import_menu button'));

    kanban.destroy();
});

QUnit.test('import favorite dropdown item should not in list with create="0"', async function (assert) {
    assert.expect(1);

    const kanban = await createView({
        View: KanbanView,
        model: 'foo',
        data: this.data,
        arch: `<kanban create="0">
                <templates>
                    <t t-name="kanban-box">
                        <div><field name="foo"/></div>
                    </t>
                </templates>
            </kanban>`,
    });

    await testUtils.dom.click(kanban.$('.o_favorite_menu button'));
    assert.containsNone(kanban, '.o_import_menu');

    kanban.destroy();
});

QUnit.test('import dropdown favorite should not in kanban with import="0"', async function (assert) {
    assert.expect(1);

    const kanban = await createView({
        View: KanbanView,
        model: 'foo',
        data: this.data,
        arch: `<kanban import="0">
                <templates>
                    <t t-name="kanban-box">
                        <div><field name="foo"/></div>
                    </t>
                </templates>
            </kanban>`,
    });

    await testUtils.dom.click(kanban.$('.o_favorite_menu button'));
    assert.containsNone(kanban, '.o_import_menu');

    kanban.destroy();
});

QUnit.test('import should not available in favorite dropdown in pivot (other than kanban or list)', async function (assert) {
    assert.expect(1);

    this.data.foo.fields.foobar = { string: "Fubar", type: "integer", group_operator: 'sum' };

    const pivot = await createView({
        View: PivotView,
        model: 'foo',
        data: this.data,
        arch: '<pivot><field name="foobar" type="measure"/></pivot>',
    });

    await testUtils.dom.click(pivot.$('.o_favorite_menu button'));
    assert.containsNone(pivot, '.o_import_menu');

    pivot.destroy();
});

});