Rename the nick changed tests. updates #307
Test from a lower level (stanza request received by strophe) and also test the case where the server automatically changed the nick.
This commit is contained in:
parent
551a8842ce
commit
405351058a
11
converse.js
11
converse.js
@ -2493,6 +2493,7 @@
|
||||
},
|
||||
|
||||
getRoomJID: function () {
|
||||
var room = this.model.get('jid');
|
||||
var nick = this.model.get('nick');
|
||||
var node = Strophe.escapeNode(Strophe.getNodeFromJid(room));
|
||||
var domain = Strophe.getDomainFromJid(room);
|
||||
@ -2732,15 +2733,15 @@
|
||||
});
|
||||
$(x).find('status').each($.proxy(function (idx, stat) {
|
||||
var code = stat.getAttribute('code');
|
||||
if (is_self && _.contains(_.keys(this.newNicknameMessages), code)) {
|
||||
this.model.save({'nick': Strophe.getResourceFromJid($el.attr('from'))});
|
||||
var from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from')));
|
||||
if (is_self && code === "210") {
|
||||
msgs.push(__(this.newNicknameMessages[code], from_nick));
|
||||
} else if (is_self && code === "303") {
|
||||
msgs.push(__(this.newNicknameMessages[code], $item.attr('nick')));
|
||||
} else if (is_self && _.contains(_.keys(this.disconnectMessages), code)) {
|
||||
disconnect_msgs.push(this.disconnectMessages[code]);
|
||||
} else if (!is_self && _.contains(_.keys(this.actionInfoMessages), code)) {
|
||||
msgs.push(
|
||||
__(this.actionInfoMessages[code], Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from'))))
|
||||
);
|
||||
msgs.push(__(this.actionInfoMessages[code], from_nick));
|
||||
} else if (_.contains(_.keys(this.infoMessages), code)) {
|
||||
msgs.push(this.infoMessages[code]);
|
||||
} else if (code !== '110') {
|
||||
|
@ -2,12 +2,13 @@
|
||||
define([
|
||||
"jquery",
|
||||
"mock",
|
||||
"test_utils"
|
||||
], function ($, mock, test_utils) {
|
||||
return factory($, mock, test_utils);
|
||||
"test_utils",
|
||||
"utils"
|
||||
], function ($, mock, test_utils, utils) {
|
||||
return factory($, mock, test_utils, utils);
|
||||
}
|
||||
);
|
||||
} (this, function ($, mock, test_utils) {
|
||||
} (this, function ($, mock, test_utils, utils) {
|
||||
var $pres = converse_api.env.$pres;
|
||||
var $msg = converse_api.env.$msg;
|
||||
|
||||
@ -191,8 +192,38 @@
|
||||
* </x>
|
||||
* </presence>
|
||||
*/
|
||||
var __ = $.proxy(utils.__, converse);
|
||||
test_utils.openChatRoom('lounge', 'localhost', 'oldnick');
|
||||
var presence = $pres().attrs({
|
||||
var view = this.chatboxviews.get('lounge@localhost');
|
||||
var $chat_content = view.$el.find('.chat-content');
|
||||
spyOn(view, 'onChatRoomPresence').andCallThrough();
|
||||
|
||||
// The user has just entered the room and receives their own
|
||||
// presence from the server.
|
||||
// See example 24:
|
||||
// http://xmpp.org/extensions/xep-0045.html#enter-pres
|
||||
var presence = $pres({
|
||||
to:'dummy@localhost/pda',
|
||||
from:'lounge@localhost/oldnick',
|
||||
id:'DC352437-C019-40EC-B590-AF29E879AF97'
|
||||
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
|
||||
.c('item').attrs({
|
||||
affiliation: 'member',
|
||||
jid: 'dummy@localhost/pda',
|
||||
role: 'participant'
|
||||
}).up()
|
||||
.c('status').attrs({code:'110'}).up()
|
||||
.c('status').attrs({code:'210'}).nodeTree;
|
||||
|
||||
this.connection._dataRecv(test_utils.createRequest(presence));
|
||||
expect(view.onChatRoomPresence).toHaveBeenCalled();
|
||||
$participants = view.$('.participant-list');
|
||||
expect($participants.children().length).toBe(1);
|
||||
expect($participants.children().first(0).text()).toBe("oldnick");
|
||||
expect($chat_content.find('div.chat-info').length).toBe(1);
|
||||
expect($chat_content.find('div.chat-info').html()).toBe(__(view.newNicknameMessages["210"], "oldnick"));
|
||||
|
||||
presence = $pres().attrs({
|
||||
from:'lounge@localhost/oldnick',
|
||||
id:'DC352437-C019-40EC-B590-AF29E879AF98',
|
||||
to:'dummy@localhost/pda',
|
||||
@ -208,13 +239,13 @@
|
||||
.c('status').attrs({code:'303'}).up()
|
||||
.c('status').attrs({code:'110'}).nodeTree;
|
||||
|
||||
var view = this.chatboxviews.get('lounge@localhost');
|
||||
view.onChatRoomPresence(presence, {nick: 'oldnick', name: 'lounge@localhost'});
|
||||
var $chat_content = view.$el.find('.chat-content');
|
||||
expect($chat_content.find('div.chat-info').length).toBe(1);
|
||||
expect($chat_content.find('div.chat-info').html()).toBe('Your nickname has been changed to: <strong>newnick</strong>');
|
||||
this.connection._dataRecv(test_utils.createRequest(presence));
|
||||
expect(view.onChatRoomPresence).toHaveBeenCalled();
|
||||
expect($chat_content.find('div.chat-info').length).toBe(2);
|
||||
expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick"));
|
||||
$participants = view.$('.participant-list');
|
||||
expect($participants.children().length).toBe(0);
|
||||
|
||||
// The second presence shouldn't do anything...
|
||||
presence = $pres().attrs({
|
||||
from:'lounge@localhost/newnick',
|
||||
id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67',
|
||||
@ -227,9 +258,14 @@
|
||||
role: 'participant'
|
||||
}).up()
|
||||
.c('status').attrs({code:'110'}).nodeTree;
|
||||
view.onChatRoomPresence(presence, {nick: 'newnick', name: 'lounge@localhost'});
|
||||
expect($chat_content.find('div.chat-info').length).toBe(1);
|
||||
expect($chat_content.find('div.chat-info').html()).toBe('Your nickname has been changed to: <strong>newnick</strong>');
|
||||
|
||||
this.connection._dataRecv(test_utils.createRequest(presence));
|
||||
expect(view.onChatRoomPresence).toHaveBeenCalled();
|
||||
expect($chat_content.find('div.chat-info').length).toBe(2);
|
||||
expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick"));
|
||||
$participants = view.$('.participant-list');
|
||||
expect($participants.children().length).toBe(1);
|
||||
expect($participants.children().first(0).text()).toBe("newnick");
|
||||
}, converse));
|
||||
|
||||
it("informs users if they have been kicked out of the chat room", $.proxy(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user