summaryrefslogtreecommitdiff
path: root/addons/base_automation/static/tests/base_automation_error_dialog.js
blob: af2e9ff6d4d0690794c85b2e9ba17ffde081d3df (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('base_automation.BaseAutomatioErrorDialogTests', function (require) {
'use strict';

    const CrashManager = require('web.CrashManager').CrashManager;
    const session = require('web.session');

    QUnit.module('base_automation', {}, function () {

        QUnit.module('Error Dialog');

        QUnit.test('Error due to an automated action', async function (assert) {
            assert.expect(4);

            let baseAutomationName = 'Test base automation error dialog';
            let error = {
                type: 'Odoo Client Error',
                message: 'Message',
                data: {
                    debug: 'Traceback',
                    context: {
                        exception_class: 'base_automation',
                        base_automation: {
                            id: 1,
                            name: baseAutomationName,
                        },
                    },
                },
            };
            // Force the user session to be admin, to display the disable and edit action buttons,
            // then reset back to the origin value after the test.
            let isAdmin = session.is_admin;
            session.is_admin = true;

            let crashManager = new CrashManager();
            let dialog = crashManager.show_error(error);

            await dialog._opened;

            assert.containsOnce(document.body, '.modal .o_clipboard_button');
            assert.containsOnce(document.body, '.modal .o_disable_action_button');
            assert.containsOnce(document.body, '.modal .o_edit_action_button');
            assert.ok(dialog.$el.text().indexOf(baseAutomationName) !== -1);

            session.is_admin = isAdmin;
            crashManager.destroy();
        });

        QUnit.test('Error not due to an automated action', async function (assert) {
            assert.expect(3);

            let error = {
                type: 'Odoo Client Error',
                message: 'Message',
                data: {
                    debug: 'Traceback',
                },
            };
            let crashManager = new CrashManager();
            let dialog = crashManager.show_error(error);

            await dialog._opened;

            assert.containsOnce(document.body, '.modal .o_clipboard_button');
            assert.containsNone(document.body, '.modal .o_disable_action_button');
            assert.containsNone(document.body, '.modal .o_edit_action_button');

            crashManager.destroy();
        });

    });

});