diff --git a/spec/chatroom.js b/spec/chatroom.js index 42022a0a7..890b194d6 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -95,7 +95,7 @@ }); })); - it("has a method 'open' which opens and returns a wrapped chat box", mock.initConverse(function (converse) { + it("has a method 'open' which opens (optionally configures) and returns a wrapped chat box", mock.initConverse(function (converse) { test_utils.createContacts(converse, 'current'); var chatroomview; var jid = 'lounge@localhost'; @@ -138,6 +138,94 @@ expect(chatroomview.$el.is(':visible')).toBeTruthy(); chatroomview.close(); }); + waits('300'); // ChatBox.show() is debounced for 250ms + runs(function () { + converse.muc_instant_rooms = false; + var sent_IQ, IQ_id; + var sendIQ = converse.connection.sendIQ; + spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) { + sent_IQ = iq; + IQ_id = sendIQ.bind(this)(iq, callback, errback); + }); + // Test with configuration + converse_api.rooms.open('room@conference.example.org', { + 'nick': 'some1', + 'auto_configure': true, + 'roomconfig': { + 'changesubject': false, + 'membersonly': true, + 'persistentroom': true, + 'publicroom': true, + 'roomdesc': 'Welcome to this room', + 'whois': 'anyone' + } + }); + /* + * + * + * + * + * + * + */ + var presence = $pres({ + from:'room@conference.example.org/some1', + to:'dummy@localhost/pda' + }) + .c('x', {xmlns:'http://jabber.org/protocol/muc#user'}) + .c('item', { + affiliation: 'owner', + jid: 'dummy@localhost/pda', + role: 'moderator' + }).up() + .c('status', {code:'110'}).up() + .c('status', {code:'201'}); + converse.connection._dataRecv(test_utils.createRequest(presence)); + expect(converse.connection.sendIQ).toHaveBeenCalled(); + expect(sent_IQ.toLocaleString()).toBe( + "" + ); + converse.connection._dataRecv(test_utils.createRequest($( + ''+ + ' '+ + ' '+ + ' Configuration for room@conference.example.org'+ + ' Complete and submit this form to configure the room.'+ + ' '+ + ' http://jabber.org/protocol/muc#roomconfig'+ + ' '+ + ' '+ + ' Room'+ + ' '+ + ' '+ + ' '+ + ' 1'+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' '+ + ' 20'+ + ' '+ + ' '+ + ' ')[0])); + var $sent_stanza = $(sent_IQ.toLocaleString()); + expect($sent_stanza.find('field[var="muc#roomconfig_roomname"] value').text()).toBe('Room'); + expect($sent_stanza.find('field[var="muc#roomconfig_roomdesc"] value').text()).toBe('Welcome to this room'); + expect($sent_stanza.find('field[var="muc#roomconfig_persistentroom"] value').text()).toBe('1'); + expect($sent_stanza.find('field[var="muc#roomconfig_publicroom"] value ').text()).toBe('1'); + expect($sent_stanza.find('field[var="muc#roomconfig_changesubject"] value').text()).toBe('0'); + expect($sent_stanza.find('field[var="muc#roomconfig_whois"] value ').text()).toBe('anyone'); + expect($sent_stanza.find('field[var="muc#roomconfig_membersonly"] value').text()).toBe('1'); + expect($sent_stanza.find('field[var="muc#roomconfig_historylength"] value').text()).toBe('20'); + }); })); }); @@ -608,6 +696,7 @@ it("indicates when a room is no longer anonymous", mock.initConverse(function (converse) { converse_api.rooms.open('room@conference.example.org', { 'nick': 'some1', + 'auto_configure': true, 'roomconfig': { 'changesubject': false, 'membersonly': true, diff --git a/src/converse-muc.js b/src/converse-muc.js index 2fd81be74..4702a7fd9 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -816,7 +816,7 @@ .c("query", {xmlns: Strophe.NS.MUC_OWNER}) .c("x", {xmlns: Strophe.NS.XFORM, type: "submit"}); _.each(config, function (node) { iq.cnode(node).up(); }); - return converse.connection.sendIQ(iq.tree(), onSuccess, onError); + return converse.connection.sendIQ(iq, onSuccess, onError); }, saveConfiguration: function (ev) { @@ -920,7 +920,7 @@ $iq({ 'to': this.model.get('jid'), 'type': "get" - }).c("query", {xmlns: Strophe.NS.MUC_OWNER}).tree(), + }).c("query", {xmlns: Strophe.NS.MUC_OWNER}), handleIQ ); },