diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-11-23 12:11:32 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-11-23 12:11:32 +0100 |
| commit | 7a0243ec15d916102ec4502db01ae5e70d6912cd (patch) | |
| tree | 29c940dcab4e9f7c834b8a5e899e394d8f821794 /addons/mail/static/tests/thread_window/basic_thread_window_tests.js | |
| parent | 75477052a03530df791348cdcf819f5bedd46284 (diff) | |
| parent | b3052b690fad15feb3211525666d4962bc1a24ac (diff) | |
[MERGE] forward port branch 12.0 up to b3052b690fa
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.js | 94 |
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 b820972bef8..3b066b154cc 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(); +}); + }); }); }); |
