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

Split ChatRooms tests out into their own spec file

parent fc06d46b
(function (root, factory) {
define("mock",
['converse'],
function() {
return factory();
});
}(this, function (converse) {
var mock_connection = {
'muc': {
'listRooms': function () {},
'join': function () {},
'leave': function () {}
},
'jid': 'dummy@localhost',
'addHandler': function (handler, ns, name, type, id, from, options) {
return function () {};
},
'send': function () {},
'roster': {
'add': function () {},
'authorize': function () {},
'unauthorize': function () {},
'get': function () {},
'subscribe': function () {},
'registerCallback': function () {}
},
'vcard': {
'get': function (callback, jid) {
var name = jid.split('@')[0].replace('.', ' ').split(' ');
var firstname = name[0].charAt(0).toUpperCase()+name[0].slice(1);
var lastname = name[1].charAt(0).toUpperCase()+name[1].slice(1);
var fullname = firstname+' '+lastname;
var vcard = $iq().c('vCard').c('FN').t(fullname);
callback(vcard.tree());
}
},
'disco': {
'info': function () {},
'items': function () {}
}
};
return mock_connection;
}));
(function (root, factory) {
define([
"converse",
"mock"
], function (converse, mock_connection) {
return factory(converse, mock_connection);
}
);
} (this, function (converse, mock_connection) {
return describe("ChatRooms", $.proxy(function() {
var chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
];
describe("A Chat Room", $.proxy(function () {
beforeEach($.proxy(function () {
if (!$("div#controlbox").is(':visible')) {
$('.toggle-online-users').click();
}
var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('lounge');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
$('.toggle-online-users').click();
}, converse));
it("shows users currently present in the room", $.proxy(function () {
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'];
var $participant_list = chatroomview.$el.find('.participant-list');
var roster = {}, room = {}, i;
for (i=0; i<chatroom_names.length; i++) {
roster[chatroom_names[i]] = {};
chatroomview.onChatRoomRoster(roster, room);
expect($participant_list.find('li').length).toBe(1+i);
expect($($participant_list.find('li')[i]).text()).toBe(chatroom_names[i]);
}
roster[converse.bare_jid] = {};
chatroomview.onChatRoomRoster(roster, room);
}, converse));
it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
// We instantiate a new ChatBoxes collection, which by default
// will be empty.
var newchatboxes = new this.ChatBoxes();
expect(newchatboxes.length).toEqual(0);
// The chatboxes will then be fetched from localStorage inside the
// onConnected method
newchatboxes.onConnected();
expect(newchatboxes.length).toEqual(1);
// Check that the chatrooms retrieved from localStorage
// have the same attributes values as the original ones.
attrs = ['id', 'box_id', 'visible'];
for (i=0; i<attrs.length; i++) {
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
}
this.rosterview.render();
}, converse));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
var view = this.chatboxesview.views['lounge@muc.localhost'], chatroom = view.model, $el;
spyOn(view, 'closeChat').andCallThrough();
spyOn(converse.connection.muc, 'leave');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.$el.find('.close-chatbox-button').click();
expect(view.closeChat).toHaveBeenCalled();
expect(converse.connection.muc.leave).toHaveBeenCalled();
}, converse));
}, converse));
describe("When attempting to enter a chatroom", $.proxy(function () {
beforeEach($.proxy(function () {
var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('problematic');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
}, converse));
afterEach($.proxy(function () {
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.closeChat();
}, converse));
it("will show an error message if the room requires a password", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('This chatroom requires a password');
}, converse));
it("will show an error message if the room is members-only and the user not included", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You are not on the member list of this room');
}, converse));
it("will show an error message if the user has been banned", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You have been banned from this room');
}, converse));
it("will show an error message if no nickname was specified for the user", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'modify'})
.c('jid-malformed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('No nickname was specified');
}, converse));
it("will show an error message if the user is not allowed to have created the room", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You are not allowed to create new rooms');
}, converse));
it("will show an error message if the user's nickname doesn't conform to room policy", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("Your nickname doesn't conform to the room's policies");
}, converse));
it("will show an error message if the user's nickname is already taken", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("Your nickname is already taken");
}, converse));
it("will show an error message if the room doesn't yet exist", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("This room does not (yet) exist");
}, converse));
it("will show an error message if the room has reached it's maximum number of occupants", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("This room has reached it's maximum number of occupants");
}, converse));
}, converse));
}, converse));
}));
(function (root, factory) { (function (root, factory) {
define([ define([
"converse" "converse",
], function (converse) { "mock"
return factory(converse); ], function (converse, mock_connection) {
return factory(converse, mock_connection);
} }
); );
} (this, function (converse) { } (this, function (converse, mock_connection) {
return describe("Converse.js", $.proxy(function() { return describe("Converse.js", $.proxy(function() {
// Names from http://www.fakenamegenerator.com/ // Names from http://www.fakenamegenerator.com/
var req_names = [ var req_names = [
...@@ -20,56 +20,7 @@ ...@@ -20,56 +20,7 @@
'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel', 'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers' 'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
]; ];
var chatroom_names = [
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
];
var num_contacts = req_names.length + pend_names.length + cur_names.length; var num_contacts = req_names.length + pend_names.length + cur_names.length;
mock_connection = {
'muc': {
'listRooms': function () {},
'join': function () {},
'leave': function () {}
},
'jid': 'dummy@localhost',
'addHandler': function (handler, ns, name, type, id, from, options) {
return function () {};
},
'send': function () {},
'roster': {
'add': function () {},
'authorize': function () {},
'unauthorize': function () {},
'get': function () {},
'subscribe': function () {},
'registerCallback': function () {}
},
'vcard': {
'get': function (callback, jid) {
var name = jid.split('@')[0].replace('.', ' ').split(' ');
var firstname = name[0].charAt(0).toUpperCase()+name[0].slice(1);
var lastname = name[1].charAt(0).toUpperCase()+name[1].slice(1);
var fullname = firstname+' '+lastname;
var vcard = $iq().c('vCard').c('FN').t(fullname);
callback(vcard.tree());
}
},
'disco': {
'info': function () {},
'items': function () {}
}
};
// Clear localStorage
window.localStorage.clear();
this.initialize({
prebind: false,
xhr_user_search: false,
auto_subscribe: false,
animate: false
});
this.onConnected(mock_connection);
// Variable declarations for specs
var open_controlbox; var open_controlbox;
describe("The Control Box", $.proxy(function () { describe("The Control Box", $.proxy(function () {
...@@ -82,8 +33,10 @@ ...@@ -82,8 +33,10 @@
// open yet. // open yet.
expect($("div#controlbox").is(':visible')).toBe(false); expect($("div#controlbox").is(':visible')).toBe(false);
spyOn(this, 'toggleControlBox').andCallThrough(); spyOn(this, 'toggleControlBox').andCallThrough();
spyOn(this, 'showControlBox').andCallThrough();
$('.toggle-online-users').click(); $('.toggle-online-users').click();
expect(this.toggleControlBox).toHaveBeenCalled(); expect(this.toggleControlBox).toHaveBeenCalled();
expect(this.showControlBox).toHaveBeenCalled();
expect($("div#controlbox").is(':visible')).toBe(true); expect($("div#controlbox").is(':visible')).toBe(true);
}, converse); }, converse);
it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox); it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
...@@ -577,8 +530,13 @@ ...@@ -577,8 +530,13 @@
it("is cleared when the window is focused", $.proxy(function () { it("is cleared when the window is focused", $.proxy(function () {
spyOn(converse, 'clearMsgCounter').andCallThrough(); spyOn(converse, 'clearMsgCounter').andCallThrough();
$(window).trigger('focus'); runs(function () {
expect(converse.clearMsgCounter).toHaveBeenCalled(); $(window).trigger('focus');
});
waits(50);
runs(function () {
expect(converse.clearMsgCounter).toHaveBeenCalled();
});
}, converse)); }, converse));
it("is not incremented when the message is received and the window is focused", $.proxy(function () { it("is not incremented when the message is received and the window is focused", $.proxy(function () {
...@@ -667,202 +625,5 @@ ...@@ -667,202 +625,5 @@
}, converse)); }, converse));
}, converse)); }, converse));
}, converse)); }, converse));
describe("A Chat Room", $.proxy(function () {
it("shows users currently present in the room", $.proxy(function () {
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'];
var $participant_list = chatroomview.$el.find('.participant-list');
var roster = {}, room = {}, i;
for (i=0; i<chatroom_names.length; i++) {
roster[chatroom_names[i]] = {};
chatroomview.onChatRoomRoster(roster, room);
expect($participant_list.find('li').length).toBe(1+i);
expect($($participant_list.find('li')[i]).text()).toBe(chatroom_names[i]);
}
roster[converse.bare_jid] = {};
chatroomview.onChatRoomRoster(roster, room);
}, converse));
it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
// We instantiate a new ChatBoxes collection, which by default
// will be empty.
var newchatboxes = new this.ChatBoxes();
expect(newchatboxes.length).toEqual(0);
// The chatboxes will then be fetched from localStorage inside the
// onConnected method
newchatboxes.onConnected();
expect(newchatboxes.length).toEqual(2); // controlbox is also included
// Check that the chatrooms retrieved from localStorage
// have the same attributes values as the original ones.
attrs = ['id', 'box_id', 'visible'];
for (i=0; i<attrs.length; i++) {
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
}
this.rosterview.render();
}, converse));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
var view = this.chatboxesview.views['lounge@muc.localhost'], chatroom = view.model, $el;
spyOn(view, 'closeChat').andCallThrough();
spyOn(converse.connection.muc, 'leave');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.$el.find('.close-chatbox-button').click();
expect(view.closeChat).toHaveBeenCalled();
expect(converse.connection.muc.leave).toHaveBeenCalled();
}, converse));
}, converse));
describe("When attempting to enter a chatroom", $.proxy(function () {
beforeEach($.proxy(function () {
var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('problematic');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
}, converse));
afterEach($.proxy(function () {
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.closeChat();
}, converse));
it("will show an error message if the room requires a password", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('This chatroom requires a password');
}, converse));
it("will show an error message if the room is members-only and the user not included", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You are not on the member list of this room');
}, converse));
it("will show an error message if the user has been banned", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'auth'})
.c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You have been banned from this room');
}, converse));
it("will show an error message if no nickname was specified for the user", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'modify'})
.c('jid-malformed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('No nickname was specified');
}, converse));
it("will show an error message if the user is not allowed to have created the room", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe('You are not allowed to create new rooms');
}, converse));
it("will show an error message if the user's nickname doesn't conform to room policy", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("Your nickname doesn't conform to the room's policies");
}, converse));
it("will show an error message if the user's nickname is already taken", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("Your nickname is already taken");
}, converse));
it("will show an error message if the room doesn't yet exist", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("This room does not (yet) exist");
}, converse));
it("will show an error message if the room has reached it's maximum number of occupants", $.proxy(function () {
var presence = $pres().attrs({
  from:'coven@chat.shakespeare.lit/thirdwitch',
    id:'n13mt3l',
    to:'hag66@shakespeare.lit/pda',
    type:'error'})
.c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
.c('error').attrs({by:'coven@chat.shakespeare.lit', type:'cancel'})
.c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
var view = this.chatboxesview.views['problematic@muc.localhost'];
view.onChatRoomPresence(presence, {'nick': 'dummy'});
var $chat_content = view.$el.find('.chat-content');
expect($chat_content.text()).toBe("This room has reached it's maximum number of occupants");
}, converse));
}, converse));
}, converse)); }, converse));
})); }));
require(["jquery", "spec/MainSpec"], function($) { require(["jquery", "converse", "mock", "spec/MainSpec", "spec/ChatRoomSpec"], function($, converse, mock_connection) {
// Set up converse.js
$(function($) { window.localStorage.clear();
var jasmineEnv = jasmine.getEnv(); converse.initialize({
jasmineEnv.updateInterval = 250; prebind: false,
xhr_user_search: false,
var htmlReporter = new jasmine.HtmlReporter(); auto_subscribe: false,
animate: false
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
jasmineEnv.execute();
}); });
converse.onConnected(mock_connection);
// Jasmine stuff
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 50;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
jasmineEnv.execute();
}); });
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