From 9f2ec57a7e2dc8eb8eb87905ff50ab04e8bd8ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 14 Feb 2018 14:59:03 +0100 Subject: [PATCH] [FIX] mail: tests: add basic rendering test for discuss This commit adds a first test of discuss, which checks that the essential DOM elements are present when we create a discuss widget. In particular, there should be a sidebar that contains links to channel_inbox and channel_starred. --- addons/mail/static/tests/discuss_tests.js | 73 ++++++++----------- .../mail/static/tests/helpers/test_utils.js | 3 +- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js index 7f48e3b0450..6c90cf802f7 100644 --- a/addons/mail/static/tests/discuss_tests.js +++ b/addons/mail/static/tests/discuss_tests.js @@ -1,11 +1,10 @@ odoo.define('mail.discuss_test', function (require) { "use strict"; -var testUtils = require('web.test_utils'); -var Widget = require('web.Widget'); - +var ChatManager = require('mail.ChatManager'); var mailTestUtils = require('mail.testUtils'); +var createBusService = mailTestUtils.createBusService; var createDiscuss = mailTestUtils.createDiscuss; QUnit.module('mail', {}, function () { @@ -17,57 +16,43 @@ QUnit.module('Discuss client action', { fields: {}, }, }; + this.services = [ChatManager, createBusService()]; }, }); -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); +QUnit.test('basic rendering', function (assert) { + assert.expect(5); + var done = assert.async(); - var parent = new Widget(); - testUtils.addMockEnvironment(parent, { - data: this.data, - archs: { - 'mail.message,false,search': '', - }, - config: {device: {isMobile: true}}, - }); - - var params = { + createDiscuss({ id: 1, context: {}, params: {}, - }; - var discuss = createDiscuss(params); + data: this.data, + services: this.services, + }) + .then(function (discuss) { + // test basic rendering + var $sidebar = discuss.$('.o_mail_chat_sidebar'); + assert.strictEqual($sidebar.length, 1, + "should have rendered a sidebar"); - // test basic rendering in mobile - assert.equal(discuss.$(".o_mail_chat_mobile_control_panel").length, 1, "Mobile control panel created"); - assert.equal(discuss.$(".o_mail_mobile_tab").length, 4, "Four mobile tabs created"); - assert.equal(discuss.$('.o_mail_chat_content').length, 1, "One default chat content pane created"); - assert.equal(discuss.$(".o_mail_chat_tab_pane").length, 3, "Three mobile tab panes created"); + var $nocontent = discuss.$('.o_mail_chat_content'); + assert.strictEqual($nocontent.length, 1, + "should have rendered the content"); + assert.strictEqual($nocontent.find('.o_mail_no_content').length, 1, + "should display no content message"); - // Inbox - assert.equal(discuss.activeMobileTab, "channel_inbox", "'channel_inbox' is default active tab"); - assert.ok(discuss.$(".o_channel_inbox_item:nth(0)").hasClass("btn-primary"), "Showing 'Inbox'"); + var $inbox = $sidebar.find('.o_mail_chat_channel_item[data-channel-id=channel_inbox]'); + assert.strictEqual($inbox.length, 1, + "should have the channel item 'channel_inbox' in the sidebar"); - // Starred - discuss.$(".o_channel_inbox_item[data-type='channel_starred']").click(); - assert.ok(discuss.$(".o_channel_inbox_item:nth(1)").hasClass("btn-primary"), "Clicked on 'Starred'"); - - assert.ok(discuss.$(".o_mail_chat_content").is(":visible"), "Default main content pane visible"); - - discuss.$(".o_mail_mobile_tab[data-type='dm']").click(); - assert.equal(discuss.activeMobileTab, "dm", "After click on 'Conversation', is now active tab"); - - assert.ok(!discuss.$(".o_mail_chat_content").is(":visible"), "none", "'Main' content pane is invisible"); - assert.ok(discuss.$(".o_mail_chat_tab_pane:nth(0)").is(":visible"), "'Conversation' pane is visible"); - - discuss.destroy(); + var $starred = $sidebar.find('.o_mail_chat_channel_item[data-channel-id=channel_starred]'); + assert.strictEqual($starred.length, 1, + "should have the channel item 'channel_starred' in the sidebar"); + discuss.destroy(); + done(); + }); }); }); diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index 05ffc12e7de..095da27be58 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -74,7 +74,8 @@ function createDiscuss(params) { })); var discuss = new Discuss(parent, params); discuss.set_cp_bus(new Widget()); - discuss.appendTo($('#qunit-fixture')); + var selector = params.debug ? 'body' : '#qunit-fixture'; + discuss.appendTo($(selector)); return discuss.call('chat_manager', 'isReady').then(function () { return discuss;