From 831e59c1a74278d8896fc4b948f82170b2659ef4 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 2 Mar 2020 16:39:47 +0100 Subject: [PATCH] controlbox: Wait when saving while closing Otherwise we run into race conditions while testing --- spec/chatbox.js | 8 ++++---- src/converse-controlbox.js | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/chatbox.js b/spec/chatbox.js index bb5757b02..b470adfd0 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -321,15 +321,14 @@ chatview.delegateEvents(); controlview.el.querySelector('.close-chatbox-button').click(); - expect(controlview.close).toHaveBeenCalled(); + await new Promise(resolve => _converse.api.listen.once('chatBoxClosed', resolve)); expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); - expect(_converse.api.trigger.calls.count(), 1); - chatview.el.querySelector('.close-chatbox-button').click(); + chatview.el.querySelector('.close-chatbox-button').click(); expect(chatview.close).toHaveBeenCalled(); + await new Promise(resolve => _converse.api.listen.once('chatBoxClosed', resolve)); expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); - expect(_converse.api.trigger.calls.count(), 2); done(); })); @@ -381,6 +380,7 @@ spyOn(_converse.api, "trigger").and.callThrough(); test_utils.closeControlBox(); + await new Promise(resolve => _converse.api.listen.once('chatBoxClosed', resolve)); expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); expect(_converse.chatboxes.length).toEqual(1); expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']); diff --git a/src/converse-controlbox.js b/src/converse-controlbox.js index cd530b6b9..615ac8a04 100644 --- a/src/converse-controlbox.js +++ b/src/converse-controlbox.js @@ -297,7 +297,7 @@ converse.plugins.add('converse-controlbox', { await new Promise((resolve, reject) => { return this.model.save( {'closed': true}, - {'success': resolve, 'error': reject} + {'success': resolve, 'error': reject, 'wait': true} ); }); } else { @@ -341,9 +341,7 @@ converse.plugins.add('converse-controlbox', { }, show () { - _converse.controlboxtoggle.hide( - this.onControlBoxToggleHidden.bind(this) - ); + _converse.controlboxtoggle.hide(() => this.onControlBoxToggleHidden()); return this; },