summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components/thread_needaction_preview
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-09-22 16:30:09 +0000
committerSébastien Theys <seb@odoo.com>2020-09-23 10:35:56 +0000
commit201ba2518a5a1a95fdedfcd4235d93f64702a8ef (patch)
tree3eb019a24530f8eb4b04bcbc91e7335e0caf4e0f /addons/mail/static/src/components/thread_needaction_preview
parentf6e67650e8cb1f8f0be9e90dbaccf45692816c3e (diff)
[FIX] mail: allow to open record thread in chat window
task-2171885 closes odoo/odoo#58318 X-original-commit: af6e68c2c5bd819402af0126c87f375e096c8d0d Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/thread_needaction_preview')
-rw-r--r--addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js1
-rw-r--r--addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js117
2 files changed, 118 insertions, 0 deletions
diff --git a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js
index 24486cfc93c..2b6bede0909 100644
--- a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js
+++ b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview.js
@@ -105,6 +105,7 @@ class ThreadNeedactionPreview extends Component {
// handled in `_onClickMarkAsRead`
return;
}
+ this.thread.markNeedactionMessagesAsRead();
this.thread.open();
if (!this.env.messaging.device.isMobile) {
this.env.messaging.messagingMenu.close();
diff --git a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js
index 7f16eb68fb3..5c59a8f3d50 100644
--- a/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js
+++ b/addons/mail/static/src/components/thread_needaction_preview/thread_needaction_preview_tests.js
@@ -13,6 +13,8 @@ const {
start,
} = require('mail/static/src/utils/test_utils.js');
+const Bus = require('web.Bus');
+
QUnit.module('mail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('thread_needaction_preview', {}, function () {
@@ -84,6 +86,121 @@ QUnit.test('mark as read', async function (assert) {
);
});
+QUnit.test('click on preview should mark as read and open the thread', async function (assert) {
+ assert.expect(5);
+
+ await this.start({
+ hasChatWindow: true,
+ async mockRPC(route, args) {
+ if (route.includes('set_message_done')) {
+ assert.step('set_message_done');
+ }
+ return this._super(...arguments);
+ },
+ });
+ const thread = this.env.models['mail.thread'].create({
+ id: 11,
+ model: 'mail.channel',
+ });
+ this.env.models['mail.message'].create({
+ id: 21,
+ isNeedaction: true,
+ originThread: [['link', thread]],
+ });
+ await this.createThreadNeedactionPreviewComponent({
+ threadLocalId: thread.localId,
+ });
+ assert.containsOnce(
+ document.body,
+ '.o_ThreadNeedactionPreview',
+ "should have a preview initially"
+ );
+ assert.containsNone(
+ document.body,
+ '.o_ChatWindow',
+ "should have no chat window initially"
+ );
+
+ await afterNextRender(() =>
+ document.querySelector('.o_ThreadNeedactionPreview').click()
+ );
+ assert.verifySteps(
+ ['set_message_done'],
+ "should have marked the message as read on clicking on the preview"
+ );
+ assert.containsOnce(
+ document.body,
+ '.o_ChatWindow',
+ "should have opened the thread on clicking on the preview"
+ );
+});
+
+QUnit.test('click on expand from chat window should close the chat window and open the form view', async function (assert) {
+ assert.expect(8);
+
+ const bus = new Bus();
+ bus.on('do-action', null, payload => {
+ assert.step('do_action');
+ assert.strictEqual(
+ payload.action.res_id,
+ 11,
+ "should redirect to the id of the thread"
+ );
+ assert.strictEqual(
+ payload.action.res_model,
+ 'res.partner',
+ "should redirect to the model of the thread"
+ );
+ });
+ await this.start({
+ env: { bus },
+ hasChatWindow: true,
+ });
+ const thread = this.env.models['mail.thread'].create({
+ id: 11,
+ model: 'res.partner',
+ });
+ this.env.models['mail.message'].create({
+ id: 21,
+ isNeedaction: true,
+ originThread: [['link', thread]],
+ });
+ await this.createThreadNeedactionPreviewComponent({
+ threadLocalId: thread.localId,
+ });
+ assert.containsOnce(
+ document.body,
+ '.o_ThreadNeedactionPreview',
+ "should have a preview initially"
+ );
+ await afterNextRender(() =>
+ document.querySelector('.o_ThreadNeedactionPreview').click()
+ );
+ assert.containsOnce(
+ document.body,
+ '.o_ChatWindow',
+ "should have opened the thread on clicking on the preview"
+ );
+ assert.containsOnce(
+ document.body,
+ '.o_ChatWindowHeader_commandExpand',
+ "should have an expand button"
+ );
+
+ await afterNextRender(() =>
+ document.querySelector('.o_ChatWindowHeader_commandExpand').click()
+ );
+ assert.containsNone(
+ document.body,
+ '.o_ChatWindow',
+ "should have closed the chat window on clicking expand"
+ );
+ assert.verifySteps(
+ ['do_action'],
+ "should have done an action to open the form view"
+ );
+});
+
});
});
});