summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/thread_window/basic_thread_window_tests.js
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2018-11-21 14:10:35 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2018-11-22 10:11:56 +0000
commitd798c27f273bfc93deb5f3ff866ca6005bde634f (patch)
tree13a60fef5e3266af1fe71d1dd64ce3f802f81fc3 /addons/mail/static/tests/thread_window/basic_thread_window_tests.js
parent6cfa158b4ddd174d2287b1639ec9149145a86211 (diff)
[FIX] mail: no autofocus when spawning a livechat window
Have a user A having the focus on the search bar, minding his own business Have a user B send a direct message to user A Before this commit, the chat window on user A's browser took the focus manu militari After this commit, the focus stays on user A's search bar OPW 1911553 closes odoo/odoo#28915
Diffstat (limited to 'addons/mail/static/tests/thread_window/basic_thread_window_tests.js')
-rw-r--r--addons/mail/static/tests/thread_window/basic_thread_window_tests.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js
index 4b8935e81cf..8e454dced18 100644
--- a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js
+++ b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js
@@ -3,6 +3,7 @@ odoo.define('mail.basicThreadWindowTests', function (require) {
var mailTestUtils = require('mail.testUtils');
+var FormView = require('web.FormView');
var framework = require('web.framework');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
@@ -428,6 +429,99 @@ QUnit.test('show document link of message linked to a document', function (asser
parent.destroy();
});
+QUnit.test('do not autofocus chat window on receiving new direct message', function (assert) {
+ // Receiving a message doesn't make other input loose focus
+ assert.expect(3);
+
+ this.data.partner = {
+ fields: {
+ display_name: { string: "Displayed name", type: "char" },
+ },
+ records: [{
+ id: 1,
+ display_name: "first record",
+ }],
+ };
+
+ this.data['mail.channel'] = {
+ fields: {
+ name: {
+ string: "Name",
+ type: "char",
+ required: true,
+ },
+ channel_type: {
+ string: "Channel Type",
+ type: "selection",
+ },
+ channel_message_ids: {
+ string: "Messages",
+ type: "many2many",
+ relation: 'mail.message'
+ },
+ message_unread_counter: {
+ string: "Amount of Unread Messages",
+ type: "integer"
+ },
+ },
+ records: [{
+ id: 2,
+ name: "DM",
+ channel_type: "chat",
+ message_unread_counter: 0,
+ direct_partner: [{ id: 666, name: 'DemoUser1', im_status: '' }],
+ }],
+ };
+
+ var form = testUtils.createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="display_name" />' +
+ '</form>',
+ res_id: 1,
+ services: mailTestUtils.getMailServices(),
+ viewOptions: {
+ mode: 'edit',
+ },
+ mockRPC: function (route, args) {
+ if (args.method === 'channel_join_and_get_info') {
+ return $.when(this.data['mail.channel'].records[0]);
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ var $formInput = form.$('input');
+ $formInput.focus();
+
+ assert.equal(document.activeElement, $formInput[0],
+ 'The form input should have the focus');
+
+ // simulate receiving message from someone else
+ var messageData = {
+ author_id: [5, "Someone else"],
+ body: "<p>Test message</p>",
+ id: 2,
+ model: 'mail.channel',
+ res_id: 1,
+ channel_ids: [2],
+ };
+
+ this.data['mail.message'].records.push(messageData);
+ var notification = [[false, 'mail.channel', 2], messageData];
+ form.call('bus_service', 'trigger', 'notification', [notification]);
+
+ assert.ok($('.o_thread_window.o_in_home_menu').length,
+ 'Chat window is opened');
+
+ assert.equal(document.activeElement, $formInput[0],
+ 'The form input should have kept the focus on message received');
+
+ form.destroy();
+});
+
});
});
});