[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.
This commit is contained in:
Aaron Bohy
2018-01-16 09:16:29 +01:00
parent 6139840796
commit f7ddaf4de9
3 changed files with 111 additions and 89 deletions
@@ -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': '<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();
});
});
});
});
@@ -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': '<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': '<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();
});
});
});
+6 -1
View File
@@ -41,13 +41,18 @@
<template id="qunit_suite" name="mail_tests" inherit_id="web.qunit_suite">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/mail/static/tests/client_action_tests.js"></script>
<script type="text/javascript" src="/mail/static/tests/chatter_tests.js"></script>
<script type="text/javascript" src="/mail/static/tests/systray_tests.js"></script>
<script type="text/javascript" src="/mail/static/tests/chat_window_test.js"></script>
</xpath>
</template>
<template id="qunit_mobile_suite" name="mail_mobile_tests" inherit_id="web.qunit_mobile_suite">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/mail/static/tests/client_action_mobile_tests.js"></script>
</xpath>
</template>
<template id="message_origin_link">
<p>This <t t-esc="self._description.lower()"/> has been <span t-if="edit">modified</span><span t-if="not edit">created</span> from:
<t t-foreach="origin" t-as="o">