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
|
odoo.define('hr_holidays/static/src/bugfix/bugfix_tests.js', function (require) {
'use strict';
/**
* This file allows introducing new QUnit test modules without contaminating
* other test files. This is useful when bug fixing requires adding new
* components for instance in stable versions of Odoo. Any test that is defined
* in this file should be isolated in its own file in master.
*/
QUnit.module('hr_holidays', {}, function () {
QUnit.module('bugfix', {}, function () {
QUnit.module('bugfix_tests.js', {
});
});
});
});
// FIXME move me in hr_holidays/static/src/components/thread_view/thread_view_tests.js
odoo.define('hr_holidays/static/src/components/thread_view/thread_view_tests.js', function (require) {
'use strict';
const components = {
ThreadView: require('mail/static/src/components/thread_view/thread_view.js'),
};
const {
afterEach,
beforeEach,
createRootComponent,
start,
} = require('mail/static/src/utils/test_utils.js');
QUnit.module('hr_holidays', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_view', {}, function () {
QUnit.module('thread_view_tests.js', {
beforeEach() {
beforeEach(this);
/**
* @param {mail.thread_view} threadView
* @param {Object} [otherProps={}]
*/
this.createThreadViewComponent = async (threadView, otherProps = {}) => {
const target = this.widget.el;
const props = Object.assign({ threadViewLocalId: threadView.localId }, otherProps);
await createRootComponent(this, components.ThreadView, { props, target });
};
this.start = async params => {
const { afterEvent, env, widget } = await start(Object.assign({}, params, {
data: this.data,
}));
this.afterEvent = afterEvent;
this.env = env;
this.widget = widget;
};
},
afterEach() {
afterEach(this);
},
});
QUnit.test('out of office message on direct chat with out of office partner', async function (assert) {
assert.expect(2);
// Returning date of the out of office partner, simulates he'll be back in a month
const returningDate = moment.utc().add(1, 'month');
// Needed partner & user to allow simulation of message reception
this.data['res.partner'].records.push({
id: 11,
name: "Foreigner partner",
out_of_office_date_end: returningDate.format("YYYY-MM-DD HH:mm:ss"),
});
this.data['mail.channel'].records = [{
channel_type: 'chat',
id: 20,
members: [this.data.currentPartnerId, 11],
}];
await this.start();
const thread = this.env.models['mail.thread'].findFromIdentifyingData({
id: 20,
model: 'mail.channel'
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
hasThreadView: true,
thread: [['link', thread]],
});
await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true });
assert.containsOnce(
document.body,
'.o_ThreadView_outOfOffice',
"should have an out of office alert on thread view"
);
const formattedDate = returningDate.toDate().toLocaleDateString(
this.env.messaging.locale.language.replace(/_/g,'-'),
{ day: 'numeric', month: 'short' }
);
assert.ok(
document.querySelector('.o_ThreadView_outOfOffice').textContent.includes(formattedDate),
"out of office message should mention the returning date"
);
});
});
});
});
});
|