(function (root, factory) { define([ "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.openControlBox(); }); waits(150); runs(function () { test_utils.openRoomsPanel(); }); waits(200); runs(function () { // Open a new chatroom var roomspanel = converse.chatboxviews.get('controlbox').roomspanel; var $input = roomspanel.$el.find('input.new-chatroom-name'); var $nick = roomspanel.$el.find('input.new-chatroom-nick'); var $server = roomspanel.$el.find('input.new-chatroom-server'); $input.val('lounge'); $nick.val('dummy'); $server.val('muc.localhost'); roomspanel.$el.find('form').submit(); }); waits(250); runs(function () { test_utils.closeControlBox(); }); runs(function () {}); }); it("shows users currently present in the room", $.proxy(function () { var chatroomview = this.chatboxviews.get('lounge@muc.localhost'), $participant_list; var roster = {}, room = {}, i; for (i=0; i" + ""+ "" )[0]; expect(converse.chatboxes.models.length).toBe(0); 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(1); expect(converse.chatboxes.models[0].id).toBe(room_jid); }, converse)); it("shows received groupchat messages", $.proxy(function () { spyOn(converse, 'emit'); var view = this.chatboxviews.get('lounge@muc.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@muc.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 () { spyOn(converse, 'emit'); var view = this.chatboxviews.get('lounge@muc.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@muc.localhost/dummy', id: '2', to: 'dummy@localhost.com', 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').last().text()).toBe(text); // We don't emit an event if it's our own message expect(converse.emit.callCount, 1); }, converse)); it("can be saved to, and retrieved from, browserStorage", $.proxy(function () { // We instantiate a new ChatBoxes collection, which by default // will be empty. spyOn(this.chatboxviews, 'trimChats'); 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(this.chatboxviews.trimChats).toHaveBeenCalled(); 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