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; },