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 () {
|
getRoomJID: function () {
|
||||||
|
var room = this.model.get('jid');
|
||||||
var nick = this.model.get('nick');
|
var nick = this.model.get('nick');
|
||||||
var node = Strophe.escapeNode(Strophe.getNodeFromJid(room));
|
var node = Strophe.escapeNode(Strophe.getNodeFromJid(room));
|
||||||
var domain = Strophe.getDomainFromJid(room);
|
var domain = Strophe.getDomainFromJid(room);
|
||||||
@ -2732,15 +2733,15 @@
|
|||||||
});
|
});
|
||||||
$(x).find('status').each($.proxy(function (idx, stat) {
|
$(x).find('status').each($.proxy(function (idx, stat) {
|
||||||
var code = stat.getAttribute('code');
|
var code = stat.getAttribute('code');
|
||||||
if (is_self && _.contains(_.keys(this.newNicknameMessages), code)) {
|
var from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from')));
|
||||||
this.model.save({'nick': 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')));
|
msgs.push(__(this.newNicknameMessages[code], $item.attr('nick')));
|
||||||
} else if (is_self && _.contains(_.keys(this.disconnectMessages), code)) {
|
} else if (is_self && _.contains(_.keys(this.disconnectMessages), code)) {
|
||||||
disconnect_msgs.push(this.disconnectMessages[code]);
|
disconnect_msgs.push(this.disconnectMessages[code]);
|
||||||
} else if (!is_self && _.contains(_.keys(this.actionInfoMessages), code)) {
|
} else if (!is_self && _.contains(_.keys(this.actionInfoMessages), code)) {
|
||||||
msgs.push(
|
msgs.push(__(this.actionInfoMessages[code], from_nick));
|
||||||
__(this.actionInfoMessages[code], Strophe.unescapeNode(Strophe.getResourceFromJid($el.attr('from'))))
|
|
||||||
);
|
|
||||||
} else if (_.contains(_.keys(this.infoMessages), code)) {
|
} else if (_.contains(_.keys(this.infoMessages), code)) {
|
||||||
msgs.push(this.infoMessages[code]);
|
msgs.push(this.infoMessages[code]);
|
||||||
} else if (code !== '110') {
|
} else if (code !== '110') {
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"mock",
|
"mock",
|
||||||
"test_utils"
|
"test_utils",
|
||||||
], function ($, mock, test_utils) {
|
"utils"
|
||||||
return factory($, mock, test_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 $pres = converse_api.env.$pres;
|
||||||
var $msg = converse_api.env.$msg;
|
var $msg = converse_api.env.$msg;
|
||||||
|
|
||||||
@ -102,7 +103,7 @@
|
|||||||
expect(converse.chatboxes.models.length).toBe(1);
|
expect(converse.chatboxes.models.length).toBe(1);
|
||||||
expect(converse.chatboxes.models[0].id).toBe("controlbox");
|
expect(converse.chatboxes.models[0].id).toBe("controlbox");
|
||||||
converse.chatboxes.onInvite(message);
|
converse.chatboxes.onInvite(message);
|
||||||
expect(window.confirm).toHaveBeenCalledWith(
|
expect(window.confirm).toHaveBeenCalledWith(
|
||||||
name + ' has invited you to join a chat room: '+ room_jid +
|
name + ' has invited you to join a chat room: '+ room_jid +
|
||||||
', and left the following reason: "'+reason+'"');
|
', and left the following reason: "'+reason+'"');
|
||||||
expect(converse.chatboxes.models.length).toBe(2);
|
expect(converse.chatboxes.models.length).toBe(2);
|
||||||
@ -178,7 +179,7 @@
|
|||||||
* <status code='110'/>
|
* <status code='110'/>
|
||||||
* </x>
|
* </x>
|
||||||
* </presence>
|
* </presence>
|
||||||
*
|
*
|
||||||
* <presence
|
* <presence
|
||||||
* from='coven@localhost/oldhag'
|
* from='coven@localhost/oldhag'
|
||||||
* id='5B4F27A4-25ED-43F7-A699-382C6B4AFC67'
|
* id='5B4F27A4-25ED-43F7-A699-382C6B4AFC67'
|
||||||
@ -191,8 +192,38 @@
|
|||||||
* </x>
|
* </x>
|
||||||
* </presence>
|
* </presence>
|
||||||
*/
|
*/
|
||||||
|
var __ = $.proxy(utils.__, converse);
|
||||||
test_utils.openChatRoom('lounge', 'localhost', 'oldnick');
|
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',
|
from:'lounge@localhost/oldnick',
|
||||||
id:'DC352437-C019-40EC-B590-AF29E879AF98',
|
id:'DC352437-C019-40EC-B590-AF29E879AF98',
|
||||||
to:'dummy@localhost/pda',
|
to:'dummy@localhost/pda',
|
||||||
@ -208,13 +239,13 @@
|
|||||||
.c('status').attrs({code:'303'}).up()
|
.c('status').attrs({code:'303'}).up()
|
||||||
.c('status').attrs({code:'110'}).nodeTree;
|
.c('status').attrs({code:'110'}).nodeTree;
|
||||||
|
|
||||||
var view = this.chatboxviews.get('lounge@localhost');
|
this.connection._dataRecv(test_utils.createRequest(presence));
|
||||||
view.onChatRoomPresence(presence, {nick: 'oldnick', name: 'lounge@localhost'});
|
expect(view.onChatRoomPresence).toHaveBeenCalled();
|
||||||
var $chat_content = view.$el.find('.chat-content');
|
expect($chat_content.find('div.chat-info').length).toBe(2);
|
||||||
expect($chat_content.find('div.chat-info').length).toBe(1);
|
expect($chat_content.find('div.chat-info').last().html()).toBe(__(view.newNicknameMessages["303"], "newnick"));
|
||||||
expect($chat_content.find('div.chat-info').html()).toBe('Your nickname has been changed to: <strong>newnick</strong>');
|
$participants = view.$('.participant-list');
|
||||||
|
expect($participants.children().length).toBe(0);
|
||||||
|
|
||||||
// The second presence shouldn't do anything...
|
|
||||||
presence = $pres().attrs({
|
presence = $pres().attrs({
|
||||||
from:'lounge@localhost/newnick',
|
from:'lounge@localhost/newnick',
|
||||||
id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67',
|
id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67',
|
||||||
@ -227,9 +258,14 @@
|
|||||||
role: 'participant'
|
role: 'participant'
|
||||||
}).up()
|
}).up()
|
||||||
.c('status').attrs({code:'110'}).nodeTree;
|
.c('status').attrs({code:'110'}).nodeTree;
|
||||||
view.onChatRoomPresence(presence, {nick: 'newnick', name: 'lounge@localhost'});
|
|
||||||
expect($chat_content.find('div.chat-info').length).toBe(1);
|
this.connection._dataRecv(test_utils.createRequest(presence));
|
||||||
expect($chat_content.find('div.chat-info').html()).toBe('Your nickname has been changed to: <strong>newnick</strong>');
|
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));
|
}, converse));
|
||||||
|
|
||||||
it("informs users if they have been kicked out of the chat room", $.proxy(function () {
|
it("informs users if they have been kicked out of the chat room", $.proxy(function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user