[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.
This commit is contained in:
@@ -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': '<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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user