(function (root, factory) { define([ "jquery", "mock", "test_utils" ], function ($, mock, test_utils) { return factory($, mock, test_utils); } ); } (this, function ($, mock, test_utils) { return describe("ChatRooms", $.proxy(function (mock, test_utils) { describe("A Chat Room", $.proxy(function () { beforeEach(function () { runs(function () { test_utils.closeAllChatBoxes(); test_utils.clearBrowserStorage(); }); }); it("shows users currently present in the room", $.proxy(function () { test_utils.openChatRoom('lounge', 'localhost', 'dummy'); var chatroomview = this.chatboxviews.get('lounge@localhost'), $participant_list; var roster = {}, room = {}, i; for (i=0; i" + ""+ "" )[0]; expect(converse.chatboxes.models.length).toBe(1); expect(converse.chatboxes.models[0].id).toBe("controlbox"); converse.chatboxes.onInvite(message); expect(window.confirm).toHaveBeenCalledWith( name + ' has invited you to join a chat room: '+ room_jid + ', and left the following reason: "'+reason+'"'); expect(converse.chatboxes.models.length).toBe(2); expect(converse.chatboxes.models[0].id).toBe('controlbox'); expect(converse.chatboxes.models[1].id).toBe(room_jid); }, converse)); it("shows received groupchat messages", $.proxy(function () { test_utils.openChatRoom('lounge', 'localhost', 'dummy'); spyOn(converse, 'emit'); var view = this.chatboxviews.get('lounge@localhost'); if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } var nick = mock.chatroom_names[0]; var text = 'This is a received message'; var message = $msg({ from: 'lounge@localhost/'+nick, id: '1', to: 'dummy@localhost', type: 'groupchat' }).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-message-content').text()).toBe(text); expect(converse.emit).toHaveBeenCalledWith('message', message.nodeTree); }, converse)); it("shows sent groupchat messages", $.proxy(function () { test_utils.openChatRoom('lounge', 'localhost', 'dummy'); spyOn(converse, 'emit'); var view = this.chatboxviews.get('lounge@localhost'); if (!view.$el.find('.chat-area').length) { view.renderChatArea(); } var nick = mock.chatroom_names[0]; var text = 'This is a sent message'; 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 message = $msg({ from: 'lounge@localhost/dummy', to: 'dummy@localhost.com', type: 'groupchat', 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-message-content').last().text()).toBe(text); // We don't emit an event if it's our own message expect(converse.emit.callCount, 1); }, converse)); it("informs users if their nicknames has been changed.", $.proxy(function () { /* The service then sends two presence stanzas to the full JID * of each occupant (including the occupant who is changing his * or her room nickname), one of type "unavailable" for the old * nickname and one indicating availability for the new * nickname. * * See: http://xmpp.org/extensions/xep-0045.html#changenick * * * * * * * * * * * * * * * */ test_utils.openChatRoom('lounge', 'localhost', 'oldnick'); var presence = $pres().attrs({ from:'lounge@localhost/oldnick', id:'DC352437-C019-40EC-B590-AF29E879AF98', to:'dummy@localhost/pda', type:'unavailable' }) .c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'}) .c('item').attrs({ affiliation: 'member', jid: 'dummy@localhost/pda', nick: 'newnick', role: 'participant' }).up() .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: newnick'); // The second presence shouldn't do anything... presence = $pres().attrs({ from:'lounge@localhost/newnick', id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67', to:'dummy@localhost/pda' }) .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'}).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: newnick'); }, converse)); it("informs users if they have been kicked out of the chat room", $.proxy(function () { /* * * * * Avaunt, you cullion! * * * * */ test_utils.openChatRoom('lounge', 'localhost', 'dummy'); var presence = $pres().attrs({ from:'lounge@localhost/dummy', to:'dummy@localhost/pda', type:'unavailable' }) .c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'}) .c('item').attrs({ affiliation: 'none', jid: 'dummy@localhost/pda', role: 'none' }) .c('actor').attrs({nick: 'Fluellen'}).up() .c('reason').t('Avaunt, you cullion!').up() .up() .c('status').attrs({code:'307'}).nodeTree; var view = this.chatboxviews.get('lounge@localhost'); view.onChatRoomPresence(presence, {nick: 'dummy', name: 'lounge@localhost'}); expect(view.$('.chat-area').is(':visible')).toBeFalsy(); expect(view.$('.participants').is(':visible')).toBeFalsy(); var $chat_body = view.$('.chat-body'); expect($chat_body.html().trim().indexOf('

You have been kicked from this room

The reason given is: "Avaunt, you cullion!"

')).not.toBe(-1); }, converse)); it("can be saved to, and retrieved from, browserStorage", $.proxy(function () { test_utils.openChatRoom('lounge', 'localhost', 'dummy'); // We instantiate a new ChatBoxes collection, which by default // will be empty. test_utils.openControlBox(); var newchatboxes = new this.ChatBoxes(); expect(newchatboxes.length).toEqual(0); // The chatboxes will then be fetched from browserStorage inside the // onConnected method newchatboxes.onConnected(); expect(newchatboxes.length).toEqual(2); // XXX: Includes controlbox, is this a bug? // Check that the chatrooms retrieved from browserStorage // have the same attributes values as the original ones. attrs = ['id', 'box_id', 'visible']; for (i=0; i