Commit dcd1a847 authored by JC Brand's avatar JC Brand

Fix failing tests.

We now need to mock some extra XMPP stanzas being received when a user enters a chat
room in tests.
parent f56b85cf
......@@ -171,7 +171,7 @@
});
it("shows users currently present in the room", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
var name;
var view = this.chatboxviews.get('lounge@localhost'),
$occupants = view.$('.occupant-list');
......@@ -194,9 +194,9 @@
converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($occupants.find('li').length).toBe(1+i);
expect($($occupants.find('li')[i]).text()).toBe(mock.chatroom_names[i]);
expect($($occupants.find('li')[i]).hasClass('moderator')).toBe(role === "moderator");
expect($occupants.find('li').length).toBe(2+i);
expect($($occupants.find('li')[i+1]).text()).toBe(mock.chatroom_names[i]);
expect($($occupants.find('li')[i+1]).hasClass('moderator')).toBe(role === "moderator");
}
// Test users leaving the room
......@@ -217,13 +217,13 @@
}).nodeTree;
converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($occupants.find('li.online').length).toBe(i);
expect($occupants.find('li.online').length).toBe(i+1);
}
}.bind(converse));
it("indicates moderators by means of a special css class and tooltip", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var view = this.chatboxviews.get('lounge@localhost');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost');
var presence = $pres({
to:'dummy@localhost/pda',
......@@ -236,13 +236,14 @@
}).up()
.c('status').attrs({code:'110'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence));
converse.connection._dataRecv(test_utils.createRequest(presence));
var occupant = view.$el.find('.occupant-list').find('li');
expect(occupant.length).toBe(1);
expect($(occupant).text()).toBe("moderatorman");
expect($(occupant).attr('class').indexOf('moderator')).not.toBe(-1);
expect($(occupant).attr('title')).toBe('This user is a moderator');
}.bind(converse));
expect(occupant.length).toBe(2);
expect($(occupant).first().text()).toBe("dummy");
expect($(occupant).last().text()).toBe("moderatorman");
expect($(occupant).last().attr('class').indexOf('moderator')).not.toBe(-1);
expect($(occupant).last().attr('title')).toBe('This user is a moderator');
});
it("will use the user's reserved nickname, if it exists", function () {
var sent_IQ, IQ_id;
......@@ -269,7 +270,6 @@
"type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
"<query xmlns='http://jabber.org/protocol/disco#info' node='x-roomuser-item'/></iq>"
);
/* <iq from='coven@chat.shakespeare.lit'
* id='getnick1'
* to='hag66@shakespeare.lit/pda'
......@@ -397,7 +397,7 @@
}.bind(converse));
it("shows sent groupchat messages", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
spyOn(converse, 'emit');
var view = converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
......@@ -405,7 +405,11 @@
view.$el.find('.chat-textarea').text(text);
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
expect(converse.emit).toHaveBeenCalledWith('messageSend', text);
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.find('.chat-message').length).toBe(1);
// Let's check that if we receive the same message again, it's
// not shown.
var message = $msg({
from: 'lounge@localhost/dummy',
to: 'dummy@localhost.com',
......@@ -413,7 +417,6 @@
id: view.model.messages.at(0).get('msgid')
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.find('.chat-message').length).toBe(1);
expect($chat_content.find('.chat-msg-content').last().text()).toBe(text);
// We don't emit an event if it's our own message
......@@ -422,7 +425,7 @@
it("will cause the chat area to be scrolled down only if it was at the bottom already", function () {
var message = 'This message is received while the chat area is scrolled up';
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'scrollDown').andCallThrough();
runs(function () {
......@@ -465,6 +468,8 @@
});
it("shows received chatroom subject messages", function () {
test_utils.openAndEnterChatRoom('jdev', 'conference.jabber.org', 'jc');
var text = 'Jabber/XMPP Development | RFCs and Extensions: http://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
var stanza = Strophe.xmlHtmlNode(
'<message xmlns="jabber:client" to="jc@opkode.com/converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm">'+
......@@ -472,7 +477,6 @@
' <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>'+
' <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>'+
'</message>').firstChild;
test_utils.openChatRoom('jdev', 'conference.jabber.org', 'jc');
converse.connection._dataRecv(test_utils.createRequest(stanza));
var view = converse.chatboxviews.get('jdev@conference.jabber.org');
var $chat_content = view.$el.find('.chat-content');
......@@ -517,7 +521,7 @@
* </presence>
*/
var __ = utils.__.bind(converse);
test_utils.openChatRoom('lounge', 'localhost', 'oldnick');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'oldnick');
var view = this.chatboxviews.get('lounge@localhost');
var $chat_content = view.$el.find('.chat-content');
spyOn(view, 'onChatRoomPresence').andCallThrough();
......@@ -613,7 +617,7 @@
* </x>
* </presence>
*/
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
var presence = $pres().attrs({
from:'lounge@localhost/dummy',
to:'dummy@localhost/pda',
......
......@@ -46,7 +46,7 @@
});
it("is shown when you are mentioned in a chat room", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var no_notification = false;
......@@ -104,7 +104,7 @@
describe("A notification sound", function () {
it("is played when the current user is mentioned in a chat room", function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
converse.play_sounds = true;
spyOn(converse, 'playSoundNotification');
var view = this.chatboxviews.get('lounge@localhost');
......
......@@ -7,6 +7,8 @@
return factory($, mock);
});
}(this, function ($, mock) {
var $pres = converse_api.env.$pres;
var $iq = converse_api.env.$iq;
var Strophe = converse_api.env.Strophe;
var utils = {};
......@@ -113,6 +115,41 @@
this.closeControlBox();
};
utils.openAndEnterChatRoom = function (room, server, nick) {
var IQ_id, sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
utils.openChatRoom(room, server);
var view = converse.chatboxviews.get(room+'@'+server);
// The XMPP server returns the reserved nick for this user.
var stanza = $iq({
'type': 'result',
'id': IQ_id,
'from': view.model.get('jid'),
'to': converse.connection.jid
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'})
.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'});
converse.connection._dataRecv(utils.createRequest(stanza));
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
var presence = $pres({
to: converse.connection.jid,
from: room+'@'+server+'/'+nick,
id: 'DC352437-C019-40EC-B590-AF29E879AF97'
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
.c('item').attrs({
affiliation: 'member',
jid: converse.bare_jid,
role: 'occupant'
}).up()
.c('status').attrs({code:'110'});
converse.connection._dataRecv(utils.createRequest(presence));
};
utils.removeRosterContacts = function () {
var model;
while (converse.rosterview.model.length) {
......
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