summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/systray/systray_messaging_menu_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/tests/systray/systray_messaging_menu_tests.js')
-rw-r--r--addons/mail/static/tests/systray/systray_messaging_menu_tests.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js
index b31b12f15b3..610e689ae4a 100644
--- a/addons/mail/static/tests/systray/systray_messaging_menu_tests.js
+++ b/addons/mail/static/tests/systray/systray_messaging_menu_tests.js
@@ -920,5 +920,62 @@ QUnit.test('messaging menu widget: expand on thread preview', async function (as
messagingMenu.destroy();
});
+QUnit.test('messaging menu widget: click twice preview on slow message_fetch should open chat window once', async function (assert) {
+ // This test assumes that a condition for opening chat window is to
+ // successfully fetch messages beforehand.
+ assert.expect(1);
+
+ const self = this;
+ // Used to pause `message_fetch` after opening the messaging menu.
+ // This is necessary `message_fetch` on mailbox_inbox is required to
+ // display the previews.
+ let lockMessageFetch = false;
+ const messageFetchProm = testUtils.makeTestPromise();
+
+ const messagingMenu = new MessagingMenu();
+ testUtils.addMockEnvironment(messagingMenu, {
+ services: this.services,
+ data: this.data,
+ session: { partner_id: 1 },
+ async mockRPC(route, args) {
+ if (args.method === 'message_fetch' && lockMessageFetch) {
+ const _super = this._super.bind(this);
+ await messageFetchProm;
+ return _super(route, args);
+ }
+ if (args.method === 'channel_minimize') {
+ // called to detach thread in chat window
+ // simulate longpolling response with new chat window state
+ const channelInfo = {
+ ...self.data['mail.channel'].records[0],
+ is_minimized: true,
+ state: 'open',
+ };
+ const notifications = [ [['myDB', 'res.partner'], channelInfo] ];
+ messagingMenu.call('bus_service', 'trigger', 'notification', notifications);
+ }
+ return this._super(...arguments);
+ },
+ });
+ await messagingMenu.appendTo($('#qunit-fixture'));
+
+ // Opening chat window 1st time from messaging menu (pending from `messageFetchDef`)
+ await testUtils.dom.click(messagingMenu.$('.dropdown-toggle'));
+ lockMessageFetch = true;
+ await testUtils.dom.click(messagingMenu.$('.o_mail_preview'));
+ // Click again on preview to open chat window
+ await testUtils.dom.click(messagingMenu.$('.dropdown-toggle'));
+ await testUtils.dom.click(messagingMenu.$('.o_mail_preview'));
+ messageFetchProm.resolve();
+ await testUtils.nextTick();
+
+ assert.containsOnce(
+ $,
+ '.o_thread_window',
+ "should only display a single chat window");
+
+ messagingMenu.destroy();
+});
+
});
});