summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/services/crash_manager_tests.js
blob: edbc74f2e6cd73803103c25cecede28d3a857bab (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
odoo.define('web.crash_manager_tests', function (require) {
    "use strict";
    const CrashManager = require('web.CrashManager').CrashManager;
    const Bus = require('web.Bus');
    const testUtils = require('web.test_utils');
    const core = require('web.core');
    const createActionManager = testUtils.createActionManager;
    
QUnit.module('Services', {}, function() {

    QUnit.module('CrashManager');

    QUnit.test("Execute an action and close the RedirectWarning when clicking on the primary button", async function (assert) {
        assert.expect(4);

        var dummy_action_name = "crash_manager_tests_dummy_action";
        var dummy_action = function() {
                assert.step('do_action');
            };
        core.action_registry.add(dummy_action_name, dummy_action);

        // What we want to test is a do-action triggered by the crashManagerService
        // the intercept feature of testUtilsMock is not fit for this, because it is too low in the hierarchy
        const bus = new Bus();
        bus.on('do-action', null, payload => {
            const { action, options } = payload;
            actionManager.doAction(action, options);
        });

        var actionManager = await createActionManager({
            actions: [dummy_action],
            services: {
                crash_manager: CrashManager,
            },
            bus
        });
        actionManager.call('crash_manager', 'rpc_error', {
            code: 200,
            data: {
                name: "odoo.exceptions.RedirectWarning",
                arguments: [
                    "crash_manager_tests_warning_modal_text",
                    dummy_action_name,
                    "crash_manager_tests_button_text",
                    null,
                ]
            }
        });
        await testUtils.nextTick();

        var modal_selector = 'div.modal:contains("crash_manager_tests_warning_modal_text")';
        assert.containsOnce($, modal_selector, "Warning Modal should be opened");

        await testUtils.dom.click($(modal_selector).find('button.btn-primary'));

        assert.containsNone($, modal_selector, "Warning Modal should be closed");
        assert.verifySteps(['do_action'], "Warning Modal Primary Button Action should be executed");
        
        actionManager.destroy();
    });
});
});