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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
odoo.define('sms/static/src/components/message/message_tests.js', function (require) {
'use strict';
const components = {
Message: require('mail/static/src/components/message/message.js'),
};
const { makeDeferred } = require('mail/static/src/utils/deferred/deferred.js');
const {
afterEach,
afterNextRender,
beforeEach,
createRootComponent,
start,
} = require('mail/static/src/utils/test_utils.js');
const Bus = require('web.Bus');
QUnit.module('sms', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('message', {}, function () {
QUnit.module('message_tests.js', {
beforeEach() {
beforeEach(this);
this.createMessageComponent = async (message, otherProps) => {
const props = Object.assign({ messageLocalId: message.localId }, otherProps);
await createRootComponent(this, components.Message, {
props,
target: this.widget.el,
});
};
this.start = async params => {
const { env, widget } = await start(Object.assign({}, params, {
data: this.data,
}));
this.env = env;
this.widget = widget;
};
},
afterEach() {
afterEach(this);
},
});
QUnit.test('Notification Sent', async function (assert) {
assert.expect(9);
await this.start();
const threadViewer = this.env.models['mail.thread_viewer'].create({
hasThreadView: true,
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'sms',
notifications: [['insert', {
id: 11,
notification_status: 'sent',
notification_type: 'sms',
partner: [['insert', { id: 12, name: "Someone" }]],
}]],
originThread: [['link', threadViewer.thread]]
});
await this.createMessageComponent(message, {
threadViewLocalId: threadViewer.threadView.localId
});
assert.containsOnce(
document.body,
'.o_Message',
"should display a message component"
);
assert.containsOnce(
document.body,
'.o_Message_notificationIconClickable',
"should display the notification icon container"
);
assert.containsOnce(
document.body,
'.o_Message_notificationIcon',
"should display the notification icon"
);
assert.hasClass(
document.querySelector('.o_Message_notificationIcon'),
'fa-mobile',
"icon should represent sms"
);
await afterNextRender(() => {
document.querySelector('.o_Message_notificationIconClickable').click();
});
assert.containsOnce(
document.body,
'.o_NotificationPopover',
"notification popover should be open"
);
assert.containsOnce(
document.body,
'.o_NotificationPopover_notificationIcon',
"popover should have one icon"
);
assert.hasClass(
document.querySelector('.o_NotificationPopover_notificationIcon'),
'fa-check',
"popover should have the sent icon"
);
assert.containsOnce(
document.body,
'.o_NotificationPopover_notificationPartnerName',
"popover should have the partner name"
);
assert.strictEqual(
document.querySelector('.o_NotificationPopover_notificationPartnerName').textContent.trim(),
"Someone",
"partner name should be correct"
);
});
QUnit.test('Notification Error', async function (assert) {
assert.expect(8);
const openResendActionDef = makeDeferred();
const bus = new Bus();
bus.on('do-action', null, payload => {
assert.step('do_action');
assert.strictEqual(
payload.action,
'sms.sms_resend_action',
"action should be the one to resend sms"
);
assert.strictEqual(
payload.options.additional_context.default_mail_message_id,
10,
"action should have correct message id"
);
openResendActionDef.resolve();
});
await this.start({ env: { bus } });
const threadViewer = this.env.models['mail.thread_viewer'].create({
hasThreadView: true,
thread: [['create', {
id: 11,
model: 'mail.channel',
}]],
});
const message = this.env.models['mail.message'].create({
id: 10,
message_type: 'sms',
notifications: [['insert', {
id: 11,
notification_status: 'exception',
notification_type: 'sms',
}]],
originThread: [['link', threadViewer.thread]]
});
await this.createMessageComponent(message, {
threadViewLocalId: threadViewer.threadView.localId
});
assert.containsOnce(
document.body,
'.o_Message',
"should display a message component"
);
assert.containsOnce(
document.body,
'.o_Message_notificationIconClickable',
"should display the notification icon container"
);
assert.containsOnce(
document.body,
'.o_Message_notificationIcon',
"should display the notification icon"
);
assert.hasClass(
document.querySelector('.o_Message_notificationIcon'),
'fa-mobile',
"icon should represent sms"
);
document.querySelector('.o_Message_notificationIconClickable').click();
await openResendActionDef;
assert.verifySteps(
['do_action'],
"should do an action to display the resend sms dialog"
);
});
});
});
});
});
|