summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/thread_window/moderation_thread_window_tests.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-10-10 11:39:08 +0000
committerAlexandre Kühn <aku@odoo.com>2018-10-16 07:29:07 +0000
commitc0c2590a40594ef749aeda3dfdc4c6754572a218 (patch)
tree60820e4c5fcddff665aca488787bb928912491c8 /addons/mail/static/tests/thread_window/moderation_thread_window_tests.js
parent510065ab67bf8c3c413991de937b4447f9f915a9 (diff)
[FIX] mail: no moderation in chat window
Before this commit, a moderator of a moderated channel could see commands on 'pending moderation' messages in a chat window, although none of them work in chat windows. Those commands only work in Discuss. Making them work in chat windows is not trivial, because some code must be redesigned for this. This commit disables moderation commands in chat window. Moderators of such channel now see 'Pending moderation' on such messages in chat window, and mouse-hovering on this annotation tells the user to moderate those messages in the Discuss app. Task-ID 1887963
Diffstat (limited to 'addons/mail/static/tests/thread_window/moderation_thread_window_tests.js')
-rw-r--r--addons/mail/static/tests/thread_window/moderation_thread_window_tests.js137
1 files changed, 137 insertions, 0 deletions
diff --git a/addons/mail/static/tests/thread_window/moderation_thread_window_tests.js b/addons/mail/static/tests/thread_window/moderation_thread_window_tests.js
new file mode 100644
index 00000000000..4a8cc9e2af0
--- /dev/null
+++ b/addons/mail/static/tests/thread_window/moderation_thread_window_tests.js
@@ -0,0 +1,137 @@
+odoo.define('mail.moderationThreadWindowTests', function (require) {
+"use strict";
+
+var mailTestUtils = require('mail.testUtils');
+
+var testUtils = require('web.test_utils');
+var Widget = require('web.Widget');
+
+QUnit.module('mail', {}, function () {
+QUnit.module('Thread Window', {}, function () {
+QUnit.module('Moderation', {
+ beforeEach: function () {
+ var self = this;
+
+ // define channel to link to chat window
+ this.data = {
+ 'mail.message': {
+ fields: {
+ author_id: {
+ string: "Author",
+ relation: 'res.partner',
+ },
+ channel_ids: {
+ string: "Channels",
+ type: 'many2many',
+ relation: 'mail.channel',
+ },
+ model: {
+ string: "Related Document model",
+ type: 'char',
+ },
+ res_id: {
+ string: "Related Document ID",
+ type: 'integer',
+ },
+ need_moderation: {
+ string: "Need moderation",
+ type: 'boolean',
+ },
+ moderation_status: {
+ string: "Moderation Status",
+ type: 'integer',
+ selection: [
+ ['pending_moderation', 'Pending Moderation'],
+ ['accepted', 'Accepted'],
+ ['rejected', 'Rejected']
+ ],
+ },
+ },
+ records: [],
+ },
+ initMessaging: {
+ channel_slots: {
+ channel_channel: [{
+ id: 1,
+ channel_type: "channel",
+ name: "general",
+ }],
+ },
+ },
+ };
+ this.services = mailTestUtils.getMailServices();
+ this.ORIGINAL_THREAD_WINDOW_APPENDTO = this.services.mail_service.prototype.THREAD_WINDOW_APPENDTO;
+
+ this.createParent = function (params) {
+ var widget = new Widget();
+
+ // in non-debug mode, append thread windows in qunit-fixture
+ // note that it does not hide thread window because it uses fixed
+ // position, and qunit-fixture uses absolute...
+ if (params.debug) {
+ self.services.mail_service.prototype.THREAD_WINDOW_APPENDTO = 'body';
+ } else {
+ self.services.mail_service.prototype.THREAD_WINDOW_APPENDTO = '#qunit-fixture';
+ }
+
+ testUtils.addMockEnvironment(widget, params);
+ return widget;
+ };
+ },
+ afterEach: function () {
+ // reset thread window append to body
+ this.services.mail_service.prototype.THREAD_WINDOW_APPENDTO = this.ORIGINAL_THREAD_WINDOW_APPENDTO;
+ },
+});
+
+QUnit.test('moderator: moderated channel with pending moderation message', function (assert) {
+ assert.expect(5);
+
+ this.data.initMessaging = {
+ channel_slots: {
+ channel_channel: [{
+ id: 1,
+ channel_type: "channel",
+ name: "general",
+ moderation: true,
+ }],
+ },
+ is_moderator: true,
+ moderation_counter: 1,
+ moderation_channel_ids: [1],
+ };
+ this.data['mail.message'].records = [{
+ author_id: [2, "Someone"],
+ body: "<p>test</p>",
+ id: 100,
+ model: 'mail.channel',
+ moderation_status: 'pending_moderation',
+ need_moderation: true,
+ res_id: 1,
+ }];
+
+ var parent = this.createParent({
+ data: this.data,
+ services: this.services,
+ });
+
+ // detach channel 1, so that it opens corresponding thread window.
+ parent.call('mail_service', 'getChannel', 1).detach();
+
+ assert.strictEqual($('.o_thread_message ').length, 1,
+ "should display a message in the thread window");
+ assert.strictEqual($('.o_thread_author').text().trim(), "Someone",
+ "should be a message of 'Someone'");
+ assert.strictEqual($('.o_thread_icons').text().trim(), "Pending moderation",
+ "should be pending moderation");
+ assert.strictEqual($('.o_thread_message_moderation').length, 0,
+ "should not display any contextual moderation decisions next to the message");
+ assert.strictEqual($('.moderation_checkbox').length, 0,
+ "should not display any moderation checkbox next to the message");
+
+ parent.destroy();
+});
+
+});
+});
+});