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

    const FormView = require('web.FormView');
    const testUtils = require('web.test_utils');

    const cpHelpers = testUtils.controlPanel;

    QUnit.module('Google Drive Integration', {
        beforeEach() {
            this.data = {
                partner: {
                    fields: {
                        display_name: { string: "Displayed name", type: "char", searchable: true },
                    },
                    records: [
                        { id: 1, display_name: "Locomotive Breath" },
                        { id: 2, display_name: "Hey Macarena" },
                    ],
                },
            };
        },
    }, function () {

        QUnit.module('Google Drive ActionMenus');

        QUnit.test('rendering of the google drive attachments in action menus', async function (assert) {
            assert.expect(3);

            const form = await testUtils.createView({
                actionMenusRegistry: true,
                arch:
                    `<form string="Partners">
                        <field name="display_name"/>
                    </form>`,
                data: this.data,
                async mockRPC(route, args) {
                    switch (route) {
                        case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
                            assert.deepEqual(args.args, ['partner', 1],
                                'The route to get google drive config should have been called');
                            return [{
                                id: 27,
                                name: 'Cyberdyne Systems',
                            }];
                        case '/web/dataset/call_kw/google.drive.config/search_read':
                            return [{
                                google_drive_resource_id: "T1000",
                                google_drive_client_id: "cyberdyne.org",
                                id: 1,
                            }];
                        case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
                            assert.deepEqual(args.args, [27, 1, 'T1000'],
                                'The route to get the Google url should have been called');
                            return; // do not return anything or it will open a new tab.
                    }
                },
                model: 'partner',
                res_id: 1,
                View: FormView,
                viewOptions: {
                    hasActionMenus: true,
                },
            });
            await cpHelpers.toggleActionMenu(form);

            assert.containsOnce(form, '.oe_share_gdoc_item',
                "The button to the google action should be present");

            await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");

            form.destroy();
        });

        QUnit.test("no google drive data", async function (assert) {
            assert.expect(1);

            const form = await testUtils.createView({
                actionMenusRegistry: true,
                arch:
                    `<form string="Partners">
                        <field name="display_name"/>
                    </form>`,
                data: this.data,
                model: 'partner',
                res_id: 1,
                View: FormView,
                viewOptions: {
                    hasActionMenus: true,
                    ids: [1, 2],
                    index: 0,
                },
            });

            assert.containsNone(form, ".o_cp_action_menus .o_embed_menu");

            form.destroy();
        });

        QUnit.test('click on the google drive attachments after switching records', async function (assert) {
            assert.expect(4);

            let currentRecordId = 1;
            const form = await testUtils.createView({
                actionMenusRegistry: true,
                arch:
                    `<form string="Partners">
                        <field name="display_name"/>
                    </form>`,
                data: this.data,
                async mockRPC(route, args) {
                    switch (route) {
                        case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
                            assert.deepEqual(args.args, ['partner', currentRecordId],
                                'The route to get google drive config should have been called');
                            return [{
                                id: 27,
                                name: 'Cyberdyne Systems',
                            }];
                        case '/web/dataset/call_kw/google.drive.config/search_read':
                            return [{
                                google_drive_resource_id: "T1000",
                                google_drive_client_id: "cyberdyne.org",
                                id: 1,
                            }];
                        case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
                            assert.deepEqual(args.args, [27, currentRecordId, 'T1000'],
                                'The route to get the Google url should have been called');
                            return; // do not return anything or it will open a new tab.
                    }
                },
                model: 'partner',
                res_id: 1,
                View: FormView,
                viewOptions: {
                    hasActionMenus: true,
                    ids: [1, 2],
                    index: 0,
                },
            });

            await cpHelpers.toggleActionMenu(form);
            await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");

            currentRecordId = 2;
            await cpHelpers.pagerNext(form);

            await cpHelpers.toggleActionMenu(form);
            await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");

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