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
|
odoo.define('web/static/tests/report/client_action_tests', function (require) {
"use strict";
const ControlPanel = require('web.ControlPanel');
const ReportClientAction = require('report.client_action');
const testUtils = require("web.test_utils");
const { createActionManager, dom, mock } = testUtils;
QUnit.module('Client Action Report', {}, () => {
QUnit.test("mounted is called once when returning on 'Client Action Report' from breadcrumb", async assert => {
// This test can be removed as soon as we don't mix legacy and owl layers anymore.
assert.expect(7);
let mountCount = 0;
// patch the report client action to override its iframe's url so that
// it doesn't trigger an RPC when it is appended to the DOM (for this
// usecase, using removeSRCAttribute doesn't work as the RPC is
// triggered as soon as the iframe is in the DOM, even if its src
// attribute is removed right after)
mock.patch(ReportClientAction, {
start: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
self._rpc({route: self.iframe.getAttribute('src')});
self.iframe.setAttribute('src', 'about:blank');
});
}
});
ControlPanel.patch('test.ControlPanel', T => {
class ControlPanelPatchTest extends T {
mounted() {
mountCount = mountCount + 1;
this.__uniqueId = mountCount;
assert.step(`mounted ${this.__uniqueId}`);
super.mounted(...arguments);
}
willUnmount() {
assert.step(`willUnmount ${this.__uniqueId}`);
super.mounted(...arguments);
}
}
return ControlPanelPatchTest;
});
const actionManager = await createActionManager({
actions: [
{
id: 42,
name: "Client Action Report",
tag: 'report.client_action',
type: 'ir.actions.report',
report_type: 'qweb-html',
},
{
id: 43,
type: "ir.actions.act_window",
res_id: 1,
res_model: "partner",
views: [
[false, "form"],
],
}
],
archs: {
'partner,false,form': '<form><field name="display_name"/></form>',
'partner,false,search': '<search></search>',
},
data: {
partner: {
fields: {
display_name: { string: "Displayed name", type: "char" },
},
records: [
{id: 1, display_name: "Genda Swami"},
],
},
},
mockRPC: function (route) {
if (route === '/report/html/undefined?context=%7B%7D') {
return Promise.resolve('<a action="go_to_details">Go to detail view</a>');
}
return this._super.apply(this, arguments);
},
intercepts: {
do_action: ev => actionManager.doAction(ev.data.action, ev.data.options),
},
});
await actionManager.doAction(42);
// simulate an action as we are not able to reproduce a real doAction using 'Client Action Report'
await actionManager.doAction(43);
await dom.click(actionManager.$('.breadcrumb-item:first'));
actionManager.destroy();
assert.verifySteps([
'mounted 1',
'willUnmount 1',
'mounted 2',
'willUnmount 2',
'mounted 3',
'willUnmount 3',
]);
ControlPanel.unpatch('test.ControlPanel');
mock.unpatch(ReportClientAction);
});
});
});
|