Commit fc941270 authored by JC Brand's avatar JC Brand

Fix failing tests

parent 393bbe02
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
} (this, function ($, jasmine, utils, converse, mock, test_utils) { } (this, function ($, jasmine, utils, converse, mock, test_utils) {
"use strict"; "use strict";
var _ = converse.env._; var _ = converse.env._;
var $iq = converse.env.$iq;
var $msg = converse.env.$msg; var $msg = converse.env.$msg;
var Strophe = converse.env.Strophe; var Strophe = converse.env.Strophe;
var moment = converse.env.moment; var moment = converse.env.moment;
...@@ -22,6 +23,12 @@ ...@@ -22,6 +23,12 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.openControlBox(); test_utils.openControlBox();
test_utils.openContactsPanel(_converse); test_utils.openContactsPanel(_converse);
...@@ -46,6 +53,7 @@ ...@@ -46,6 +53,7 @@
expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well'); expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well');
done(); done();
});
})); }));
it("is created when you click on a roster item", it("is created when you click on a roster item",
...@@ -527,7 +535,8 @@ ...@@ -527,7 +535,8 @@
describe("A Chat Message", function () { describe("A Chat Message", function () {
describe("when received from someone else", function () { describe("when received from someone else", function () {
it("can be received which will open a chatbox and be displayed inside it",
it("will open a chatbox and be displayed inside it",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -953,6 +962,13 @@ ...@@ -953,6 +962,13 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.openControlBox(); test_utils.openControlBox();
test_utils.openContactsPanel(_converse); test_utils.openContactsPanel(_converse);
...@@ -994,6 +1010,7 @@ ...@@ -994,6 +1010,7 @@
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text(); var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
expect(msg_txt).toEqual(msgtext); expect(msg_txt).toEqual(msgtext);
done(); done();
});
})); }));
it("will be discarded if it's a malicious message meant to look like a carbon copy", it("will be discarded if it's a malicious message meant to look like a carbon copy",
...@@ -1561,8 +1578,14 @@ ...@@ -1561,8 +1578,14 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
// Send a message from a different resource // Send a message from a different resource
spyOn(_converse, 'log'); spyOn(_converse, 'log');
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost'; var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -1596,6 +1619,7 @@ ...@@ -1596,6 +1619,7 @@
var status_text = $chat_content.find('.chat-info.chat-event').text(); var status_text = $chat_content.find('.chat-info.chat-event').text();
expect(status_text).toBe('Typing from another device'); expect(status_text).toBe('Typing from another device');
done(); done();
});
})); }));
}); });
...@@ -1702,8 +1726,14 @@ ...@@ -1702,8 +1726,14 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
// Send a message from a different resource // Send a message from a different resource
spyOn(_converse, 'log'); spyOn(_converse, 'log');
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost'; var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -1737,6 +1767,7 @@ ...@@ -1737,6 +1767,7 @@
var status_text = $chat_content.find('.chat-info.chat-event').text(); var status_text = $chat_content.find('.chat-info.chat-event').text();
expect(status_text).toBe('Stopped typing on the other device'); expect(status_text).toBe('Stopped typing on the other device');
done(); done();
});
})); }));
}); });
......
...@@ -546,8 +546,16 @@ ...@@ -546,8 +546,16 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () { return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
}).then(function () {
var view = _converse.chatboxviews.get('lounge@localhost'); var view = _converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var message = '/me is tired'; var message = '/me is tired';
......
...@@ -54,10 +54,16 @@ ...@@ -54,10 +54,16 @@
{ roster_groups: false }, { roster_groups: false },
function (done, _converse) { function (done, _converse) {
var contact, sent_stanza, IQ_id, stanza;
test_utils.waitUntilFeatureSupportConfirmed(_converse, 'vcard-temp')
.then(function () {
return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () {
/* The process by which a user subscribes to a contact, including /* The process by which a user subscribes to a contact, including
* the interaction between roster items and subscription states. * the interaction between roster items and subscription states.
*/ */
var contact, stanza, sent_stanza, IQ_id;
test_utils.openControlBox(_converse); test_utils.openControlBox(_converse);
var panel = _converse.chatboxviews.get('controlbox').contactspanel; var panel = _converse.chatboxviews.get('controlbox').contactspanel;
spyOn(panel, "addContactFromForm").and.callThrough(); spyOn(panel, "addContactFromForm").and.callThrough();
...@@ -65,6 +71,7 @@ ...@@ -65,6 +71,7 @@
spyOn(_converse.roster, "addContact").and.callThrough(); spyOn(_converse.roster, "addContact").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();
var sendIQ = _converse.connection.sendIQ; var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_stanza = iq; sent_stanza = iq;
...@@ -180,11 +187,10 @@ ...@@ -180,11 +187,10 @@
* *
* <presence to='contact@example.org' type='subscribe'/> * <presence to='contact@example.org' type='subscribe'/>
*/ */
return test_utils.waitUntil(function () {
test_utils.waitUntil(function () {
return sent_stanzas.length == 1; return sent_stanzas.length == 1;
}, 300).then(function () { }, 300);
}).then(function () {
expect(contact.subscribe).toHaveBeenCalled(); expect(contact.subscribe).toHaveBeenCalled();
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec) expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
"<presence to='contact@example.org' type='subscribe' xmlns='jabber:client'>"+ "<presence to='contact@example.org' type='subscribe' xmlns='jabber:client'>"+
...@@ -222,10 +228,11 @@ ...@@ -222,10 +228,11 @@
expect(_converse.roster.updateContact).toHaveBeenCalled(); expect(_converse.roster.updateContact).toHaveBeenCalled();
// Check that the user is now properly shown as a pending // Check that the user is now properly shown as a pending
// contact in the roster. // contact in the roster.
test_utils.waitUntil(function () {
return $('a:contains("Pending contacts")').length;
}, 300).then(function () {
return test_utils.waitUntil(function () {
return $('a:contains("Pending contacts")').length;
}, 300);
}).then(function () {
var $header = $('a:contains("Pending contacts")'); var $header = $('a:contains("Pending contacts")');
expect($header.length).toBe(1); expect($header.length).toBe(1);
expect($header.is(":visible")).toBeTruthy(); expect($header.is(":visible")).toBeTruthy();
...@@ -368,7 +375,6 @@ ...@@ -368,7 +375,6 @@
expect($contacts.hasClass('both')).toBeTruthy(); expect($contacts.hasClass('both')).toBeTruthy();
done(); done();
}); });
});
})); }));
it("Alternate Flow: Contact Declines Subscription Request", it("Alternate Flow: Contact Declines Subscription Request",
...@@ -403,7 +409,7 @@ ...@@ -403,7 +409,7 @@
/* We now assume the contact declines the subscription /* We now assume the contact declines the subscription
* requests. * requests.
* *
/* Upon receiving the presence stanza of type "unsubscribed" * Upon receiving the presence stanza of type "unsubscribed"
* addressed to the user, the user's server (1) MUST deliver * addressed to the user, the user's server (1) MUST deliver
* that presence stanza to the user and (2) MUST initiate a * that presence stanza to the user and (2) MUST initiate a
* roster push to all of the user's available resources that * roster push to all of the user's available resources that
......
...@@ -11,7 +11,27 @@ ...@@ -11,7 +11,27 @@
if (typeof window.Promise === 'undefined') { if (typeof window.Promise === 'undefined') {
waitUntilPromise.setPromiseImplementation(Promise); waitUntilPromise.setPromiseImplementation(Promise);
} }
utils.waitUntil = waitUntilPromise['default']; utils.waitUntil = waitUntilPromise.default;
utils.waitUntilFeatureSupportConfirmed = function (_converse, feature_name) {
var IQ_disco, stanza;
return utils.waitUntil(function () {
IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#info"]');
}).pop();
return !_.isUndefined(IQ_disco);
}, 300).then(function () {
var info_IQ_id = IQ_disco.nodeTree.getAttribute('id');
stanza = $iq({
'type': 'result',
'from': 'localhost',
'to': 'dummy@localhost/resource',
'id': info_IQ_id
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'})
.c('feature', {'var': feature_name});
_converse.connection._dataRecv(utils.createRequest(stanza));
});
}
utils.createRequest = function (iq) { utils.createRequest = function (iq) {
iq = typeof iq.tree == "function" ? iq.tree() : iq; iq = typeof iq.tree == "function" ? iq.tree() : iq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment