Fix failing test and use async/await

This commit is contained in:
JC Brand 2018-11-12 12:04:56 +01:00
parent affafc746c
commit 9e33279fc2

View File

@ -1187,29 +1187,24 @@
it("can have their requests accepted by the user",
mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
async function (done, _converse) {
test_utils.openControlBox();
test_utils.createContacts(_converse, 'requesting').openControlBox();
test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find('.roster-group li').length;
}, 700).then(function () {
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length)
// TODO: Testing can be more thorough here, the user is
// actually not accepted/authorized because of
// mock_connection.
var name = mock.req_names.sort()[0];
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
var contact = _converse.roster.get(jid);
spyOn(_converse.roster, 'sendContactAddIQ').and.callFake(function (jid, fullname, groups, callback) {
callback();
});
spyOn(contact, 'authorize').and.callFake(function () { return contact; });
const jid = mock.req_names.sort()[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const contact = _converse.roster.get(jid);
spyOn(contact, 'authorize').and.callFake(() => contact);
spyOn(_converse.roster, 'sendContactAddIQ').and.callFake(() => Promise.resolve());
$(_converse.rosterview.el).find(".req-contact-name:contains('"+name+"')")
.parent().parent().find('.accept-xmpp-request')[0].click();
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
await test_utils.waitUntil(() => contact.authorize.calls.count());
expect(contact.authorize).toHaveBeenCalled();
done();
});
}));
it("can have their requests denied by the user",