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