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
|
odoo.define('mail/static/src/components/thread_preview/thread_preview_tests.js', function (require) {
'use strict';
const components = {
ThreadPreview: require('mail/static/src/components/thread_preview/thread_preview.js'),
};
const {
afterEach,
afterNextRender,
beforeEach,
createRootComponent,
start,
} = require('mail/static/src/utils/test_utils.js');
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_preview', {}, function () {
QUnit.module('thread_preview_tests.js', {
beforeEach() {
beforeEach(this);
this.createThreadPreviewComponent = async props => {
await createRootComponent(this, components.ThreadPreview, {
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('mark as read', async function (assert) {
assert.expect(8);
this.data['mail.channel'].records.push({
id: 11,
message_unread_counter: 1,
});
this.data['mail.message'].records.push({
channel_ids: [11],
id: 100,
model: 'mail.channel',
res_id: 11,
});
await this.start({
hasChatWindow: true,
async mockRPC(route, args) {
if (route.includes('channel_seen')) {
assert.step('channel_seen');
}
return this._super(...arguments);
},
});
const thread = this.env.models['mail.thread'].findFromIdentifyingData({
id: 11,
model: 'mail.channel',
});
await this.createThreadPreviewComponent({ threadLocalId: thread.localId });
assert.containsOnce(
document.body,
'.o_ThreadPreview_markAsRead',
"should have the mark as read button"
);
assert.containsOnce(
document.body,
'.o_ThreadPreview_counter',
"should have an unread counter"
);
await afterNextRender(() =>
document.querySelector('.o_ThreadPreview_markAsRead').click()
);
assert.verifySteps(
['channel_seen'],
"should have marked the thread as seen"
);
assert.hasClass(
document.querySelector('.o_ThreadPreview'),
'o-muted',
"should be muted once marked as read"
);
assert.containsNone(
document.body,
'.o_ThreadPreview_markAsRead',
"should no longer have the mark as read button"
);
assert.containsNone(
document.body,
'.o_ThreadPreview_counter',
"should no longer have an unread counter"
);
assert.containsNone(
document.body,
'.o_ChatWindow',
"should not have opened the thread"
);
});
});
});
});
});
|