Fix failing tests

This commit is contained in:
JC Brand 2018-03-27 19:07:55 +02:00
parent 08ab2e5416
commit ce849aaffc
4 changed files with 33 additions and 22 deletions

View File

@ -69,7 +69,7 @@
var cbview = _converse.chatboxviews.get('controlbox'); var cbview = _converse.chatboxviews.get('controlbox');
spyOn(_converse.roster, "addAndSubscribe").and.callThrough(); spyOn(_converse.roster, "addAndSubscribe").and.callThrough();
spyOn(_converse.roster, "addContact").and.callThrough(); spyOn(_converse.roster, "addContactToRoster").and.callThrough();
spyOn(_converse.roster, "sendContactAddIQ").and.callThrough(); spyOn(_converse.roster, "sendContactAddIQ").and.callThrough();
spyOn(_converse.api.vcard, "get").and.callThrough(); spyOn(_converse.api.vcard, "get").and.callThrough();
@ -100,7 +100,7 @@
*/ */
expect(modal.addContactFromForm).toHaveBeenCalled(); expect(modal.addContactFromForm).toHaveBeenCalled();
expect(_converse.roster.addAndSubscribe).toHaveBeenCalled(); expect(_converse.roster.addAndSubscribe).toHaveBeenCalled();
expect(_converse.roster.addContact).toHaveBeenCalled(); expect(_converse.roster.addContactToRoster).toHaveBeenCalled();
/* _converse request consists of sending an IQ /* _converse request consists of sending an IQ
* stanza of type='set' containing a <query/> element qualified by * stanza of type='set' containing a <query/> element qualified by

View File

@ -584,26 +584,33 @@
var name = mock.pend_names[0]; var name = mock.pend_names[0];
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
var contact = _converse.roster.get(jid); var contact = _converse.roster.get(jid);
var sent_IQ;
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(contact, 'unauthorize').and.callFake(function () { return contact; }); spyOn(contact, 'unauthorize').and.callFake(function () { return contact; });
spyOn(contact, 'removeFromRoster'); spyOn(contact, 'removeFromRoster').and.callThrough();
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
if (typeof callback === "function") { return callback(); }
});
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')").length; return $(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')").length;
}, 700).then(function () { }, 700).then(function () {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_IQ = iq;
callback();
});
$(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')") $(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')")
.parent().siblings('.remove-xmpp-contact')[0].click(); .parent().siblings('.remove-xmpp-contact')[0].click();
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')").length === 0 return $(_converse.rosterview.el).find(".pending-contact-name:contains('"+name+"')").length === 0
}, 700) }, 1000)
}).then(function () { }).then(function () {
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(_converse.connection.sendIQ).toHaveBeenCalled();
expect(contact.removeFromRoster).toHaveBeenCalled(); expect(contact.removeFromRoster).toHaveBeenCalled();
expect(_converse.connection.sendIQ).toHaveBeenCalled(); expect(sent_IQ.toLocaleString()).toBe(
"<iq type='set' xmlns='jabber:client'>"+
"<query xmlns='jabber:iq:roster'>"+
"<item jid='suleyman.van.beusichem@localhost' subscription='remove'/>"+
"</query>"+
"</iq>");
done(); done();
}); });
})); }));
@ -771,6 +778,7 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
var sent_IQ;
_addContacts(_converse); _addContacts(_converse);
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return $(_converse.rosterview.el).find('li').length; return $(_converse.rosterview.el).find('li').length;
@ -779,15 +787,21 @@
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
var contact = _converse.roster.get(jid); var contact = _converse.roster.get(jid);
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(contact, 'removeFromRoster'); spyOn(contact, 'removeFromRoster').and.callThrough();
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
if (typeof callback === "function") { return callback(); } var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_IQ = iq;
callback();
}); });
$(_converse.rosterview.el).find(".open-chat:contains('"+name+"')") $(_converse.rosterview.el).find(".open-chat:contains('"+name+"')")
.parent().find('.remove-xmpp-contact')[0].click(); .parent().find('.remove-xmpp-contact')[0].click();
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(_converse.connection.sendIQ).toHaveBeenCalled(); expect(sent_IQ.toLocaleString()).toBe(
"<iq type='set' xmlns='jabber:client'>"+
"<query xmlns='jabber:iq:roster'><item jid='max.frankfurter@localhost' subscription='remove'/></query>"+
"</iq>");
expect(contact.removeFromRoster).toHaveBeenCalled(); expect(contact.removeFromRoster).toHaveBeenCalled();
expect($(_converse.rosterview.el).find(".open-chat:contains('"+name+"')").length).toEqual(0); expect($(_converse.rosterview.el).find(".open-chat:contains('"+name+"')").length).toEqual(0);
done(); done();
@ -812,7 +826,7 @@
return $(_converse.rosterview.el).find('.roster-group:visible li').length; return $(_converse.rosterview.el).find('.roster-group:visible li').length;
}, 700).then(function () { }, 700).then(function () {
spyOn(window, 'confirm').and.returnValue(true); spyOn(window, 'confirm').and.returnValue(true);
spyOn(contact, 'removeFromRoster'); spyOn(contact, 'removeFromRoster').and.callThrough();
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback) {
if (typeof callback === "function") { return callback(); } if (typeof callback === "function") { return callback(); }
}); });

View File

@ -1034,7 +1034,7 @@
} }
}, },
removeFromRoster (callback) { removeFromRoster (callback, errback) {
/* Instruct the XMPP server to remove this contact from our roster /* Instruct the XMPP server to remove this contact from our roster
* Parameters: * Parameters:
* (Function) callback * (Function) callback
@ -1042,7 +1042,7 @@
const iq = $iq({type: 'set'}) const iq = $iq({type: 'set'})
.c('query', {xmlns: Strophe.NS.ROSTER}) .c('query', {xmlns: Strophe.NS.ROSTER})
.c('item', {jid: this.get('jid'), subscription: "remove"}); .c('item', {jid: this.get('jid'), subscription: "remove"});
_converse.connection.sendIQ(iq, callback, callback); _converse.connection.sendIQ(iq, callback, errback);
return this; return this;
} }
}); });

View File

@ -495,10 +495,7 @@
if (!_converse.allow_contact_removal) { return; } if (!_converse.allow_contact_removal) { return; }
const result = confirm(__("Are you sure you want to remove this contact?")); const result = confirm(__("Are you sure you want to remove this contact?"));
if (result === true) { if (result === true) {
const iq = $iq({type: 'set'}) this.model.removeFromRoster(
.c('query', {xmlns: Strophe.NS.ROSTER})
.c('item', {jid: this.model.get('jid'), subscription: "remove"});
_converse.connection.sendIQ(iq,
(iq) => { (iq) => {
this.model.destroy(); this.model.destroy();
this.remove(); this.remove();