From f7ddaf4de914e1a445a3c71d51d49e83c49eced2 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 27 Oct 2017 17:23:53 +0200 Subject: [PATCH] [FIX] mail: activate test of Discuss in mobile This test couldn't be executed within the classic JS web suite, because it relies on mobile specific files that are rejected in desktop. Now that a second web suite (for mobile) has been introduced (see 9bc500948), we can activate this test. --- .../tests/client_action_mobile_tests.js | 105 ++++++++++++++++++ .../mail/static/tests/client_action_tests.js | 88 --------------- addons/mail/views/mail_templates.xml | 7 +- 3 files changed, 111 insertions(+), 89 deletions(-) create mode 100644 addons/mail/static/tests/client_action_mobile_tests.js delete mode 100644 addons/mail/static/tests/client_action_tests.js diff --git a/addons/mail/static/tests/client_action_mobile_tests.js b/addons/mail/static/tests/client_action_mobile_tests.js new file mode 100644 index 00000000000..e781ae34fd3 --- /dev/null +++ b/addons/mail/static/tests/client_action_mobile_tests.js @@ -0,0 +1,105 @@ +odoo.define('mail.client_action_mobile_tests', function (require) { +"use strict"; + +var session = require('web.session'); +var testUtils = require('web.test_utils'); +var Widget = require('web.Widget'); + +var ChatAction = require('mail.chat_client_action'); +var chat_manager = require('mail.chat_manager'); + +QUnit.module('mail', {}, function () { + +QUnit.module('Discuss client action in mobile', { + beforeEach: function () { + this.data = { + 'mail.message': { + fields: {}, + }, + }; + this.createChatAction = function (params) { + var Parent = Widget.extend({ + do_push_state: function () {}, + }); + var parent = new Parent(); + testUtils.addMockEnvironment(parent, { + data: this.data, + archs: { + 'mail.message,false,search': '', + }, + session: params.session || {}, + intercepts: params.intercepts || {}, + }); + var chatAction = new ChatAction(parent, params); + chatAction.set_cp_bus(new Widget()); + chatAction.appendTo($('#qunit-fixture')); + + return chatAction; + }; + + }, +}); + +QUnit.test('mobile basic rendering', function (assert) { + // This is a very basic first test for the client action. However, with + // the chat_manager, it is hard to override RPCs (for instance, the + // /mail/client_action route is always called when the test suite is + // launched), and we must wait for this RPC to be done before starting to + // test the interface. This should be refactored to facilitate the testing. + assert.expect(9); + var done = assert.async(); + + var rpc = session.rpc; + + var chatAction = this.createChatAction({ + id: 1, + context: {}, + params: {}, + intercepts: { + get_session: function (ev) { + ev.data.callback({}); + }, + }, + session: { + rpc: function (route, args) { + if (args.method === 'message_fetch') { + return $.when([]); + } + return rpc.apply(this, arguments); + }, + }, + }); + + chat_manager.is_ready.then(function () { + // test basic rendering in mobile + assert.strictEqual(chatAction.$('.o_mail_chat_mobile_control_panel').length, 1, + "should have rendered a control panel"); + assert.strictEqual(chatAction.$('.o_mail_chat_content .o_mail_no_content').length, 1, + "should display the no content message"); + assert.strictEqual(chatAction.$('.o_mail_mobile_tabs').length, 1, + "should have rendered the tabs"); + assert.ok(chatAction.$('.o_mail_mobile_tab[data-type=channel_inbox]').hasClass('active'), + "should be in inbox tab"); + assert.strictEqual(chatAction.$('.o_mail_chat_mobile_inbox_buttons:visible').length, 1, + "inbox/starred buttons should be visible"); + assert.ok(chatAction.$('.o_mail_chat_mobile_inbox_buttons .o_channel_inbox_item[data-type=channel_inbox]').hasClass('btn-primary'), + "should be in inbox"); + + // move to DMs tab + chatAction.$('.o_mail_mobile_tab[data-type=dm]').click(); + assert.ok(chatAction.$('.o_mail_mobile_tab[data-type=dm]').hasClass('active'), + "should be in DMs tab"); + assert.strictEqual(chatAction.$('.o_mail_chat_content .o_mail_no_content').length, 0, + "should display the no content message"); + chatAction.$('.o_mail_chat_button_dm').click(); // click to add a channel + assert.strictEqual(chatAction.$('.o_mail_add_channel input:visible').length, 1, + "should display the input to add a channel"); + + chatAction.destroy(); + done(); + }); +}); + +}); + +}); diff --git a/addons/mail/static/tests/client_action_tests.js b/addons/mail/static/tests/client_action_tests.js deleted file mode 100644 index 378328037fd..00000000000 --- a/addons/mail/static/tests/client_action_tests.js +++ /dev/null @@ -1,88 +0,0 @@ -odoo.define('mail.client_action_test', function (require) { -"use strict"; - -var testUtils = require('web.test_utils'); -var Widget = require('web.Widget'); - -var ChatAction = require("mail.chat_client_action"); - -QUnit.module('mail', {}, function () { - -QUnit.module('Discuss client action', { - beforeEach: function () { - this.data = { - 'mail.message': { - fields: {}, - }, - }; - this.createChatAction = function (params) { - var parent = new Widget(); - testUtils.addMockEnvironment(parent, { - data: this.data, - archs: { - 'mail.message,false,search': '', - }, - config: {device: {isMobile: true}}, - }); - var chatAction = new ChatAction(parent, params); - chatAction.set_cp_bus(new Widget()); - chatAction.appendTo($('#qunit-fixture')); - - return chatAction; - }; - - }, -}); - -QUnit.skip('mobile basic rendering', function (assert) { - // Unfortunately, this test is skipped for now because there is no way to - // execute the whole test suite in mobile (it only works test by test), so - // as the client action include for mobile is rejected when we are not in - // mobile, it isn't possible to test it - // Moreover, RPCs done by the chat_manager (e.g. message_fetch) should be - // properly mocked. - assert.expect(11); - - var parent = new Widget(); - testUtils.addMockEnvironment(parent, { - data: this.data, - archs: { - 'mail.message,false,search': '', - }, - config: {device: {isMobile: true}}, - }); - - var params = { - id: 1, - context: {}, - params: {}, - }; - var chatAction = this.createChatAction(params); - - // test basic rendering in mobile - assert.equal(chatAction.$(".o_mail_chat_mobile_control_panel").length, 1, "Mobile control panel created"); - assert.equal(chatAction.$(".o_mail_mobile_tab").length, 4, "Four mobile tabs created"); - assert.equal(chatAction.$('.o_mail_chat_content').length, 1, "One default chat content pane created"); - assert.equal(chatAction.$(".o_mail_chat_tab_pane").length, 3, "Three mobile tab panes created"); - - // Inbox - assert.equal(chatAction.activeMobileTab, "channel_inbox", "'channel_inbox' is default active tab"); - assert.ok(chatAction.$(".o_channel_inbox_item:nth(0)").hasClass("btn-primary"), "Showing 'Inbox'"); - - // Starred - chatAction.$(".o_channel_inbox_item[data-type='channel_starred']").click(); - assert.ok(chatAction.$(".o_channel_inbox_item:nth(1)").hasClass("btn-primary"), "Clicked on 'Starred'"); - - assert.ok(chatAction.$(".o_mail_chat_content").is(":visible"), "Default main content pane visible"); - - chatAction.$(".o_mail_mobile_tab[data-type='dm']").click(); - assert.equal(chatAction.activeMobileTab, "dm", "After click on 'Conversation', is now active tab"); - - assert.ok(!chatAction.$(".o_mail_chat_content").is(":visible"), "none", "'Main' content pane is invisible"); - assert.ok(chatAction.$(".o_mail_chat_tab_pane:nth(0)").is(":visible"), "'Conversation' pane is visible"); - - chatAction.destroy(); -}); - -}); -}); diff --git a/addons/mail/views/mail_templates.xml b/addons/mail/views/mail_templates.xml index 63c403ba637..6eb98d58b1f 100644 --- a/addons/mail/views/mail_templates.xml +++ b/addons/mail/views/mail_templates.xml @@ -41,13 +41,18 @@ + +