summaryrefslogtreecommitdiff
path: root/addons/mail_bot/static/tests
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-08-30 16:10:20 +0200
committerAlexandre Kühn <aku@odoo.com>2018-08-30 17:55:18 +0200
commitf80bbb4b2a1230ba543e97d3da01c7b2c52d24cc (patch)
tree34d27fbdab943be7a2ebd675095060bb6ea512b5 /addons/mail_bot/static/tests
parentf8e3aed20ba073294fa1453f86709d6cbce650f5 (diff)
[IMP] mail, mail_bot: improved push notifications permission response
This commit makes small improvements on the messaging menu with the new module `mail_bot`: [IMP] When OdooBot has a request, it now adds "+1" to the counter of the messaging menu. The related preview also has a bold title, and displays "(1)" next to the title. [REF] Static previews are no longer in mail_service. This was only used for "OdooBot has a request" preview. This logic has now been moved to the module `mail_bot` (was previously in `mail`). [FIX] Title of response of push notifications permission clearly states whether permission has been granted or denied (was displaying "[Object object]" before this commit). Task-ID 1877502
Diffstat (limited to 'addons/mail_bot/static/tests')
-rw-r--r--addons/mail_bot/static/tests/systray_messaging_menu_tests.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/addons/mail_bot/static/tests/systray_messaging_menu_tests.js b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js
new file mode 100644
index 00000000000..a04aba7056a
--- /dev/null
+++ b/addons/mail_bot/static/tests/systray_messaging_menu_tests.js
@@ -0,0 +1,107 @@
+odoo.define('mail_bot.systray.MessagingMenuTests', function (require) {
+"use strict";
+
+var MessagingMenu = require('mail.systray.MessagingMenu');
+var mailTestUtils = require('mail.testUtils');
+
+var MailBotService = require('mail_bot.MailBotService');
+
+var testUtils = require('web.test_utils');
+
+QUnit.module('mail_bot', {}, function () {
+QUnit.module('MessagingMenu', {
+ beforeEach: function () {
+ var self = this;
+
+ this.data = {
+ 'mail.channel': {
+ fields: {},
+ records: [],
+ },
+ 'mail.message': {
+ fields: {},
+ records: [],
+ },
+ };
+
+ // Patch mailbot_service so that it does do not do any RPC, and
+ // the detection of push notifications permissions can be simulated in
+ // the test cases. By default, shows 'OdooBot has a request'
+ this.hasMailbotRequest = true;
+ testUtils.patch(MailBotService, {
+ /**
+ * @override
+ */
+ start: function () {},
+ /**
+ * @override
+ * @returns {boolean}
+ */
+ hasRequest: function () {
+ return self.hasMailbotRequest;
+ },
+ });
+
+ this.services = _.extend({}, mailTestUtils.getMailServices(), {
+ mailbot_service: MailBotService
+ });
+ },
+ afterEach: function () {
+ // unpatch MailBotService
+ testUtils.unpatch(MailBotService);
+ }
+});
+
+QUnit.test('messaging menu widget: rendering with OdooBot has a request', function (assert) {
+ assert.expect(5);
+
+ var messagingMenu = new MessagingMenu();
+ testUtils.addMockEnvironment(messagingMenu, {
+ data: this.data,
+ services: this.services,
+ });
+ messagingMenu.appendTo($('#qunit-fixture'));
+
+ assert.strictEqual(messagingMenu.$('.o_notification_counter').length, 1,
+ "should display a notification counter next to the messaging menu");
+ assert.strictEqual(messagingMenu.$('.o_notification_counter').text(), '1',
+ "should display a counter of '1' next to the messaging menu");
+
+ messagingMenu.$('.dropdown-toggle').click();
+ assert.strictEqual(messagingMenu.$('.o_preview_info').length, 1,
+ "should display a preview in the messaging menu");
+ assert.strictEqual(messagingMenu.$('.o_preview_name').text().trim(),
+ 'OdooBot has a request',
+ "preview should display that OdooBot has a request");
+ assert.strictEqual(messagingMenu.$('.o_preview_counter').text().replace(/\s/g, ''),
+ '(1)', "should display an counter of '1' next to the preview");
+
+ messagingMenu.destroy();
+});
+
+QUnit.test('messaging menu widget: rendering without OdooBot has a request', function (assert) {
+ assert.expect(3);
+
+ this.hasMailbotRequest = false;
+
+ var messagingMenu = new MessagingMenu();
+ testUtils.addMockEnvironment(messagingMenu, {
+ data: this.data,
+ services: this.services,
+ });
+ messagingMenu.appendTo($('#qunit-fixture'));
+
+ assert.strictEqual(messagingMenu.$('.o_notification_counter').length, 1,
+ "should display a notification counter next to the messaging menu");
+ assert.strictEqual(messagingMenu.$('.o_notification_counter').text(), '0',
+ "should display a counter of '0' next to the messaging menu");
+ messagingMenu.$('.dropdown-toggle').click();
+ assert.strictEqual(messagingMenu.$('.o_preview_info').length, 0,
+ "should display no preview in the messaging menu");
+
+ messagingMenu.destroy();
+});
+
+
+});
+});