controlbox: Wait when saving while closing

Otherwise we run into race conditions while testing
This commit is contained in:
JC Brand 2020-03-02 16:39:47 +01:00
parent 8aaa1a6417
commit 831e59c1a7
2 changed files with 6 additions and 8 deletions

View File

@ -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']);

View File

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