diff --git a/mock.js b/mock.js new file mode 100644 index 000000000..38cd8fcf0 --- /dev/null +++ b/mock.js @@ -0,0 +1,43 @@ +(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; +})); diff --git a/spec/ChatRoomSpec.js b/spec/ChatRoomSpec.js new file mode 100644 index 000000000..b4f60b986 --- /dev/null +++ b/spec/ChatRoomSpec.js @@ -0,0 +1,224 @@ +(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