Commit 6c31f764 authored by JC Brand's avatar JC Brand

Refactor other tests. All tests pass now again. updates #307

parent 40535105
...@@ -2523,9 +2523,10 @@ ...@@ -2523,9 +2523,10 @@
}, },
leave: function(exit_msg) { leave: function(exit_msg) {
var presenceid = converse.connection.getUniqueId();
var presence = $pres({ var presence = $pres({
type: "unavailable", type: "unavailable",
id: converse.connection.getUniqueId(), id: presenceid,
from: converse.connection.jid, from: converse.connection.jid,
to: this.getRoomJID() to: this.getRoomJID()
}); });
...@@ -2772,10 +2773,10 @@ ...@@ -2772,10 +2773,10 @@
return this.scrollDown(); return this.scrollDown();
}, },
showErrorMessage: function ($error, room) { showErrorMessage: function ($error) {
// We didn't enter the room, so we must remove it from the MUC // We didn't enter the room, so we must remove it from the MUC
// add-on // add-on
delete converse.connection.muc[room.name]; delete converse.connection.muc[this.model.get('jid')]; // XXX: Still needed?
if ($error.attr('type') == 'auth') { if ($error.attr('type') == 'auth') {
if ($error.find('not-authorized').length) { if ($error.find('not-authorized').length) {
this.renderPasswordForm(); this.renderPasswordForm();
...@@ -2810,7 +2811,7 @@ ...@@ -2810,7 +2811,7 @@
var nick = this.model.get('nick'); var nick = this.model.get('nick');
if ($presence.attr('type') === 'error') { if ($presence.attr('type') === 'error') {
this.model.set('connected', false); this.model.set('connected', false);
this.showErrorMessage($presence.find('error'), room); this.showErrorMessage($presence.find('error'));
} else { } else {
is_self = ($presence.find("status[code='110']").length) || is_self = ($presence.find("status[code='110']").length) ||
($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick)); ($presence.attr('from') == this.model.get('id')+'/'+Strophe.escapeNode(nick));
......
...@@ -23,30 +23,54 @@ ...@@ -23,30 +23,54 @@
it("shows users currently present in the room", $.proxy(function () { it("shows users currently present in the room", $.proxy(function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var chatroomview = this.chatboxviews.get('lounge@localhost'), var name;
$participant_list; var view = this.chatboxviews.get('lounge@localhost'),
var roster = {}, room = {}, i; $participants = view.$('.participant-list');
for (i=0; i<mock.chatroom_names.length-1; i++) { spyOn(view, 'onChatRoomPresence').andCallThrough();
roster[mock.chatroom_names[i]] = {}; var room = {}, i, role;
chatroomview.onChatRoomRoster(roster, room); for (i=0; i<mock.chatroom_names.length; i++) {
$participant_list = chatroomview.$el.find('.participant-list'); name = mock.chatroom_names[i];
expect($participant_list.find('li').length).toBe(1+i); console.log(name);
expect($($participant_list.find('li')[i]).text()).toBe(mock.chatroom_names[i]); role = mock.chatroom_roles[name].role;
// See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
var presence = $pres({
to:'dummy@localhost/pda',
from:'lounge@localhost/'+name
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
.c('item').attrs({
affiliation: mock.chatroom_roles[name].affiliation,
jid: 'dummy@localhost/pda',
role: role
}).up()
.c('status').attrs({code:'110'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence));
expect(view.onChatRoomPresence).toHaveBeenCalled();
expect($participants.find('li').length).toBe(1+i);
expect($($participants.find('li')[i]).text()).toBe(mock.chatroom_names[i]);
expect($($participants.find('li')[i]).hasClass('moderator')).toBe(role === "moderator");
} }
roster[converse.bare_jid] = {};
chatroomview.onChatRoomRoster(roster, room);
}, converse)); }, converse));
it("indicates moderators by means of a special css class and tooltip", $.proxy(function () { it("indicates moderators by means of a special css class and tooltip", $.proxy(function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy'); test_utils.openChatRoom('lounge', 'localhost', 'dummy');
var chatroomview = this.chatboxviews.get('lounge@localhost'); var view = this.chatboxviews.get('lounge@localhost');
var roster = {}, idx = mock.chatroom_names.length-1;
roster[mock.chatroom_names[idx]] = {}; var presence = $pres({
roster[mock.chatroom_names[idx]].role = 'moderator'; to:'dummy@localhost/pda',
chatroomview.onChatRoomRoster(roster, {}); from:'lounge@localhost/moderatorman'
var occupant = chatroomview.$el.find('.participant-list').find('li'); }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
.c('item').attrs({
affiliation: 'admin',
jid: 'dummy@localhost/pda',
role: 'moderator',
}).up()
.c('status').attrs({code:'110'}).nodeTree;
this.connection._dataRecv(test_utils.createRequest(presence));
var occupant = view.$el.find('.participant-list').find('li');
expect(occupant.length).toBe(1); expect(occupant.length).toBe(1);
expect($(occupant).text()).toBe(mock.chatroom_names[idx]); expect($(occupant).text()).toBe("moderatorman");
expect($(occupant).attr('class')).toBe('moderator'); expect($(occupant).attr('class')).toBe('moderator');
expect($(occupant).attr('title')).toBe('This user is a moderator'); expect($(occupant).attr('title')).toBe('This user is a moderator');
}, converse)); }, converse));
...@@ -371,7 +395,7 @@ ...@@ -371,7 +395,7 @@
var view = this.chatboxviews.get('lounge@localhost'), chatroom = view.model, $el; var view = this.chatboxviews.get('lounge@localhost'), chatroom = view.model, $el;
spyOn(view, 'close').andCallThrough(); spyOn(view, 'close').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(converse.connection.muc, 'leave'); spyOn(view, 'leave');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
runs(function () { runs(function () {
view.$el.find('.close-chatbox-button').click(); view.$el.find('.close-chatbox-button').click();
...@@ -379,7 +403,7 @@ ...@@ -379,7 +403,7 @@
waits(50); waits(50);
runs(function () { runs(function () {
expect(view.close).toHaveBeenCalled(); expect(view.close).toHaveBeenCalled();
expect(this.connection.muc.leave).toHaveBeenCalled(); expect(view.leave).toHaveBeenCalled();
expect(this.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object)); expect(this.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
}.bind(converse)); }.bind(converse));
}, converse)); }, converse));
......
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
mock.chatroom_names = [ mock.chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher' 'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
]; ];
// TODO: need to also test other roles and affiliations
mock.chatroom_roles = {
'Anne Ebersbacher': { affiliation: "owner", role: "moderator" },
'Dirk Theissen': { affiliation: "admin", role: "moderator" },
'Dyon van de Wege': { affiliation: "member", role: "participant" },
'Felix Hofmann': { affiliation: "member", role: "participant" },
'Ka Lek': { affiliation: "member", role: "participant" },
'Thomas Kalb': { affiliation: "member", role: "participant" }
};
mock.event = { mock.event = {
'preventDefault': function () {} 'preventDefault': function () {}
......
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