This commit makes a lot of small improvements of the JS of mail and
related modules.
A. Mail Manager
---------------
im_support:
- [REF] Slightly more robust way to determine a support
message, so that it more reliably falls back on
default kind of message (i.e. support channel UUID
should be clearly set).
mail:
- [REF] Improved method names for readability purposes.
Some examples:
- `fetchFromServer` becomes `fetchMailStateFromServer`
- `_initialize{*}` becomes `_update{*}FromServer`
- `_isModerator` becomes `_isMyselfModerator`
- [REF] Use 'template' pattern design to make Include on
Mail Manager much more robust. In particular,
the flow is always as follow:
1. Initialize internal state.
2. Listen on buses.
3. Fetch mail data from server.
- [REF] Improved workflow for thread window workflow
(Shorter & more readable).
B. Mail Tests
-------------
- [REF] Thread Window Tests crashes with clean message when
there are some thread windows open before running the
tests.
C. (Model) Message
------------------
- [REF] Improved method names for readability purposes
(e.g. `isAuthor` becomes `isMyselfAuthor`).
D. (Model) Thread
-----------------
- [REF] Improved `init` parameters on each kind of thread.
- [REF] 'Thread With Cache' has been renamed to 'Searchable
Thread': it embraces all kinds of threads that can
be used with the search view.
- [REF] 'DM' has been renamed to 'DM Chat' (for clarity).
- [IMP] New Livechat model in the backend.
- [REF] No more direct instances of the Channel class: public
and private channels are now 'Multi-User' channels,
while DM Chat and Livechat are 'Two-User' channels:
This change has been made so that instances of classes
always have direct classes as "leaf" in the Class
modeling. It eases making changes to a certain model
without being too constrained by another model.
- [REF] As a consequence of above changed, the method `isChat`
has been renamed to `isTwoUserThread`.
This is to avoid confusion with the terminology
'chat', which is more like a shortcut for 'quick real-
time conversation'. In other words, the property of
'chat' depends of the way to interact on a thread, not
of the intrinsic type of the thread.
Still, some parts have kept the terminology 'chat',
such as in the systray messagin menu.
- [IMP] Added `message_added` and `message_posted` hooks,
which may be useful to easily hook on those events.
E. Thread Widget
----------------
- [REF] Now uses a `mail.model.AbstractThread` for the
rendering of a thread, instead of a list of
`{mail.model.AbstractMessage}`.
- [FIX] Stick thread scroll height to bottom on new rendering,
if it was previously at the bottom of the thread.
- [REF] Option ORDER has its meaning changed: it now refers
to the chronological order of messages in the thread,
in which DESC means 'from top to bottom', while ASC
means 'from bottom to top'.
- [REF] Improved doc on templates, in particular with the
option `ORDER`.
F. Thread Window
----------------
- [REF] Moved more logic to thread windows, which were
previously in Mail Window Manager.
- [REF] Now hides the thread widget attribute. So instead of
`threadWindow.threadWidget.isAtBottom()`, it uses
`threadWindow.isAtBottom()`.
- [FIX] New received messages when not having focus on Odoo
tab should always make the corresponding thread
windows "passive" (i.e. windows that keep threads
unread until click on them).
- [FIX] Blank thread window (i.e. 'New message' TW) correctly
opens Discuss with 'Inbox' when clicking on 'Expand'
Button in the title
- [FIX] Do not display the composer for channels with property
'mass-mailing' set in thread windows.
G. (Website) Livechat
---------------------
- [REF] Some `trigger` have been turned into `trigger_up`.
- [REF] Some logic has been moved to models (e.g.
`{im_livechat.model.WebsiteLivechat}`), from
`{im_livechat.im_livechat.LivechatButton}`.
- [FIX] New messages should be received in real-time. The
longpolling was broken with a recent refactoring on
bus service (6448420c5d).
282 lines
10 KiB
JavaScript
282 lines
10 KiB
JavaScript
odoo.define('mail.document_thread_window_tests', function (require) {
|
|
"use strict";
|
|
|
|
var mailTestUtils = require('mail.testUtils');
|
|
var MessagingMenu = require('mail.systray.MessagingMenu');
|
|
|
|
var testUtils = require('web.test_utils');
|
|
|
|
QUnit.module('mail', {}, function () {
|
|
|
|
QUnit.module('ThreadWindow (Document Thread)', {
|
|
beforeEach: function () {
|
|
var partnerID = 44;
|
|
this.data = {
|
|
'mail.message': {
|
|
fields: {
|
|
body: {
|
|
string: "Contents",
|
|
type: 'html',
|
|
},
|
|
author_id: {
|
|
string: "Author",
|
|
type: 'many2one',
|
|
relation: 'res.partner',
|
|
},
|
|
channel_ids: {
|
|
string: "Channels",
|
|
type: 'many2many',
|
|
relation: 'mail.channel',
|
|
},
|
|
starred: {
|
|
string: "Starred",
|
|
type: 'boolean',
|
|
},
|
|
needaction: {
|
|
string: "Need Action",
|
|
type: 'boolean',
|
|
},
|
|
needaction_partner_ids: {
|
|
string: 'Needaction Partner IDs',
|
|
type: 'one2many',
|
|
relation: 'res.partner',
|
|
},
|
|
starred_partner_ids: {
|
|
string: "partner ids",
|
|
type: 'integer',
|
|
}
|
|
},
|
|
records: [{
|
|
id: 1,
|
|
author_id: [1, 'Me'],
|
|
body: '<p>Some Message on a document</p>',
|
|
channel_ids: [],
|
|
model: 'some.res.model',
|
|
record_name: "Some Record",
|
|
res_id: 1,
|
|
}, {
|
|
author_id: [2, "Demo"],
|
|
body: "<p>*MessageOnDocument*</p>",
|
|
id: 2,
|
|
model: 'some.res.model',
|
|
needaction: true,
|
|
needaction_partner_ids: [partnerID],
|
|
record_name: "Some Record",
|
|
res_id: 1,
|
|
}],
|
|
},
|
|
'some.res.model': {
|
|
fields: {
|
|
message_ids: {string: 'Messages', type: 'one2many'},
|
|
},
|
|
records: [{
|
|
id: 1,
|
|
message_ids: [1, 2],
|
|
}],
|
|
},
|
|
initMessaging: {
|
|
channel_slots: {
|
|
channel_channel: [],
|
|
},
|
|
},
|
|
};
|
|
this.session = {
|
|
partner_id: partnerID, // so that needaction messages are treated as needactions
|
|
};
|
|
this.services = mailTestUtils.getMailServices();
|
|
this.MailService = this.services.mail_service;
|
|
this.MailService.prototype.IS_STATIC_PREVIEW_ENABLED = false;
|
|
},
|
|
afterEach: function () {
|
|
this.MailService.prototype.IS_STATIC_PREVIEW_ENABLED = true;
|
|
}
|
|
});
|
|
|
|
QUnit.test('open a document thread in a thread window', function (assert) {
|
|
assert.expect(6);
|
|
|
|
var messagingMenu = new MessagingMenu();
|
|
testUtils.addMockEnvironment(messagingMenu, {
|
|
services: this.services,
|
|
data: this.data,
|
|
session: this.session,
|
|
mockRPC: function (route, args) {
|
|
if (args.method === 'read') {
|
|
assert.deepEqual(args.args, [[1], ['message_ids']],
|
|
"should read the message_ids on the document");
|
|
}
|
|
if (args.method === 'message_format') {
|
|
assert.deepEqual(args.args[0], [1],
|
|
"should only fetch the unknown message");
|
|
}
|
|
return this._super.apply(this, arguments);
|
|
},
|
|
});
|
|
messagingMenu.appendTo($('#qunit-fixture'));
|
|
|
|
// toggle the messaging menu and open the documentThread
|
|
messagingMenu.$('.dropdown-toggle').click();
|
|
assert.strictEqual(messagingMenu.$('.o_mail_preview').length, 1,
|
|
"should display one preview");
|
|
messagingMenu.$('.o_mail_preview').click();
|
|
|
|
assert.strictEqual($('.o_thread_window').length, 1,
|
|
"should have open the DocumentThread in a thread window");
|
|
assert.strictEqual($('.o_thread_window .o_thread_message').length, 2,
|
|
"should have fetched the history of the documentThread");
|
|
assert.strictEqual($('.o_thread_window_title').text().trim(), 'Some Record',
|
|
"should display the display_name of the record in the header");
|
|
|
|
messagingMenu.destroy();
|
|
});
|
|
|
|
QUnit.test('expand a document thread window', function (assert) {
|
|
assert.expect(4);
|
|
|
|
var messagingMenu = new MessagingMenu();
|
|
testUtils.addMockEnvironment(messagingMenu, {
|
|
services: this.services,
|
|
data: this.data,
|
|
session: this.session,
|
|
intercepts: {
|
|
do_action: function (ev) {
|
|
assert.deepEqual(ev.data.action, {
|
|
res_id: 1,
|
|
res_model: 'some.res.model',
|
|
type: 'ir.actions.act_window',
|
|
views: [[false, 'form']],
|
|
}, "should open the document in form view");
|
|
},
|
|
},
|
|
});
|
|
messagingMenu.appendTo($('#qunit-fixture'));
|
|
|
|
// toggle the messaging menu and open the documentThread
|
|
messagingMenu.$('.dropdown-toggle').click();
|
|
assert.strictEqual(messagingMenu.$('.o_mail_preview').length, 1,
|
|
"should display one preview");
|
|
messagingMenu.$('.o_mail_preview').click();
|
|
assert.strictEqual($('.o_thread_window').length, 1,
|
|
"should have open the DocumentThread in a thread window");
|
|
|
|
assert.strictEqual($('.o_thread_window .o_thread_window_expand').attr('title'),
|
|
'Open document', "button should have correct title");
|
|
|
|
// click to expand
|
|
$('.o_thread_window .o_thread_window_expand').click();
|
|
|
|
messagingMenu.destroy();
|
|
});
|
|
|
|
QUnit.test('post messages in a document thread window', function (assert) {
|
|
assert.expect(8);
|
|
|
|
var newMessageBody = 'Some message';
|
|
var newMessage = {
|
|
id: 6783,
|
|
author_id: [this.session.partner_id, 'Me'],
|
|
body: newMessageBody,
|
|
channel_ids: [],
|
|
model: 'some.res.model',
|
|
record_name: "Some Record",
|
|
res_id: 1,
|
|
};
|
|
var messagingMenu = new MessagingMenu();
|
|
testUtils.addMockEnvironment(messagingMenu, {
|
|
services: this.services,
|
|
data: this.data,
|
|
session: this.session,
|
|
mockRPC: function (route, args) {
|
|
if (args.method === 'message_post') {
|
|
assert.strictEqual(args.model, 'some.res.model',
|
|
"should post the message on the correct model");
|
|
assert.deepEqual(args.args, [1],
|
|
"should post the message on the correct record");
|
|
assert.strictEqual(args.kwargs.body, newMessageBody,
|
|
"should post correct message");
|
|
|
|
// add the message to the fake DB
|
|
this.data['mail.message'].records.push(newMessage);
|
|
this.data['some.res.model'].records[0].message_ids.push(6783);
|
|
return $.when(6783);
|
|
}
|
|
return this._super.apply(this, arguments);
|
|
},
|
|
});
|
|
testUtils.intercept(messagingMenu, 'call_service', function (ev) {
|
|
if (ev.data.service === 'local_storage' && ev.data.method === 'setItem' &&
|
|
ev.data.args[0] === 'mail.document_threads_last_message') {
|
|
assert.deepEqual(ev.data.args[1], newMessage,
|
|
"should write sent message in local storage, to share info with other tabs");
|
|
}
|
|
}, true);
|
|
messagingMenu.appendTo($('#qunit-fixture'));
|
|
|
|
// toggle the messaging menu and open the documentThread
|
|
messagingMenu.$('.dropdown-toggle').click();
|
|
assert.strictEqual(messagingMenu.$('.o_mail_preview').length, 1,
|
|
"should display one preview");
|
|
messagingMenu.$('.o_mail_preview').click();
|
|
assert.strictEqual($('.o_thread_window').length, 1,
|
|
"should have open the DocumentThread in a thread window");
|
|
assert.strictEqual($('.o_thread_window .o_thread_message').length, 2,
|
|
"should display 2 messages in the thread window");
|
|
|
|
// post a message
|
|
$('.o_thread_window .o_composer_text_field')
|
|
.val(newMessageBody)
|
|
.trigger($.Event('keydown', {which: $.ui.keyCode.ENTER}));
|
|
|
|
assert.strictEqual($('.o_thread_window .o_thread_message').length, 3,
|
|
"should display 3 messages in the thread window");
|
|
|
|
messagingMenu.destroy();
|
|
});
|
|
|
|
QUnit.test('open, fold, unfold and close a document thread window', function (assert) {
|
|
assert.expect(8);
|
|
|
|
var messagingMenu = new MessagingMenu();
|
|
testUtils.addMockEnvironment(messagingMenu, {
|
|
services: this.services,
|
|
data: this.data,
|
|
session: this.session,
|
|
});
|
|
testUtils.intercept(messagingMenu, 'call_service', function (ev) {
|
|
if (ev.data.service === 'local_storage' && ev.data.method === 'setItem') {
|
|
assert.step(ev.data.args);
|
|
}
|
|
}, true);
|
|
messagingMenu.appendTo($('#qunit-fixture'));
|
|
|
|
// toggle the messaging menu and open the documentThread
|
|
messagingMenu.$('.dropdown-toggle').click();
|
|
assert.strictEqual(messagingMenu.$('.o_mail_preview').length, 1,
|
|
"should display one preview");
|
|
messagingMenu.$('.o_mail_preview').click();
|
|
assert.strictEqual($('.o_thread_window').length, 1,
|
|
"should have open the DocumentThread in a thread window");
|
|
assert.strictEqual($('.o_thread_window .o_thread_message').length, 2,
|
|
"should display 2 messages in the thread window");
|
|
|
|
// fold and unfold thread window
|
|
$('.o_thread_window .o_thread_window_title').click();
|
|
$('.o_thread_window .o_thread_window_title').click();
|
|
|
|
// close thread window
|
|
$('.o_thread_window .o_thread_window_close').click();
|
|
|
|
assert.verifySteps([
|
|
['mail.document_threads_state', {"some.res.model_1": {"name": "Some Record", "windowState": "open"}}],
|
|
['mail.document_threads_state', {"some.res.model_1": {"name": "Some Record", "windowState": "folded"}}],
|
|
['mail.document_threads_state', {"some.res.model_1": {"name": "Some Record", "windowState": "open"}}],
|
|
['mail.document_threads_state', {"some.res.model_1": {"name": "Some Record", "windowState": "closed"}}],
|
|
]);
|
|
|
|
messagingMenu.destroy();
|
|
});
|
|
|
|
});
|
|
|
|
});
|