2
0

controlbox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. (function (root, factory) {
  2. define([
  3. "mock",
  4. "utils"
  5. ], function (mock, utils) {
  6. return factory(mock, utils);
  7. }
  8. );
  9. } (this, function (mock, utils) {
  10. describe("The Control Box", $.proxy(function (mock, utils) {
  11. window.localStorage.clear();
  12. it("is not shown by default", $.proxy(function () {
  13. expect(this.rosterview.$el.is(':visible')).toEqual(false);
  14. }, converse));
  15. var open_controlbox = $.proxy(function () {
  16. // This spec will only pass if the controlbox is not currently
  17. // open yet.
  18. expect($("div#controlbox").is(':visible')).toBe(false);
  19. spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
  20. spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
  21. // Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
  22. this.controlboxtoggle.delegateEvents();
  23. $('.toggle-online-users').click();
  24. expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
  25. expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
  26. expect($("div#controlbox").is(':visible')).toBe(true);
  27. }, converse);
  28. it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
  29. describe("The Status Widget", $.proxy(function () {
  30. it("shows the user's chat status, which is online by default", $.proxy(function () {
  31. var view = this.xmppstatusview;
  32. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  33. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am online');
  34. }, converse));
  35. it("can be used to set the current user's chat status", $.proxy(function () {
  36. var view = this.xmppstatusview;
  37. spyOn(view, 'toggleOptions').andCallThrough();
  38. spyOn(view, 'setStatus').andCallThrough();
  39. spyOn(converse, 'emit');
  40. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  41. runs(function () {
  42. view.$el.find('a.choose-xmpp-status').click();
  43. expect(view.toggleOptions).toHaveBeenCalled();
  44. });
  45. waits(250);
  46. runs(function () {
  47. spyOn(view, 'updateStatusUI').andCallThrough();
  48. view.initialize(); // Rebind events for spy
  49. $(view.$el.find('.dropdown dd ul li a')[1]).click(); // Change status to "dnd"
  50. expect(view.setStatus).toHaveBeenCalled();
  51. expect(converse.emit).toHaveBeenCalledWith('onStatusChanged', 'dnd');
  52. });
  53. waits(250);
  54. runs($.proxy(function () {
  55. expect(view.updateStatusUI).toHaveBeenCalled();
  56. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false);
  57. expect(view.$el.find('a.choose-xmpp-status').hasClass('dnd')).toBe(true);
  58. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am busy');
  59. }, converse));
  60. }, converse));
  61. it("can be used to set a custom status message", $.proxy(function () {
  62. var view = this.xmppstatusview;
  63. this.xmppstatus.save({'status': 'online'});
  64. spyOn(view, 'setStatusMessage').andCallThrough();
  65. spyOn(view, 'renderStatusChangeForm').andCallThrough();
  66. spyOn(converse, 'emit');
  67. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  68. view.$el.find('a.change-xmpp-status-message').click();
  69. expect(view.renderStatusChangeForm).toHaveBeenCalled();
  70. // The async testing here is used only to provide time for
  71. // visual feedback
  72. var msg = 'I am happy';
  73. runs (function () {
  74. view.$el.find('form input.custom-xmpp-status').val(msg);
  75. });
  76. waits(250);
  77. runs (function () {
  78. view.$el.find('form#set-custom-xmpp-status').submit();
  79. expect(view.setStatusMessage).toHaveBeenCalled();
  80. expect(converse.emit).toHaveBeenCalledWith('onStatusMessageChanged', msg);
  81. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  82. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe(msg);
  83. });
  84. }, converse));
  85. }, converse));
  86. }, converse, utils, mock));
  87. describe("The Contacts Roster", $.proxy(function (utils, mock) {
  88. describe("Pending Contacts", $.proxy(function () {
  89. beforeEach(function () {
  90. if (!$("div#controlbox").is(':visible')) {
  91. $('.toggle-online-users').click();
  92. }
  93. });
  94. it("do not have a heading if there aren't any", $.proxy(function () {
  95. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
  96. }, converse));
  97. it("can be added to the roster", $.proxy(function () {
  98. spyOn(this.rosterview, 'render').andCallThrough();
  99. this.roster.create({
  100. jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
  101. subscription: 'none',
  102. ask: 'subscribe',
  103. fullname: mock.pend_names[0],
  104. is_last: true
  105. });
  106. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  107. expect(this.rosterview.render).toHaveBeenCalled();
  108. }, converse));
  109. it("can be removed by the user", $.proxy(function () {
  110. var view = _.toArray(this.rosterview.rosteritemviews).pop();
  111. spyOn(window, 'confirm').andReturn(true);
  112. spyOn(this.connection.roster, 'remove').andCallThrough();
  113. spyOn(this.connection.roster, 'unauthorize');
  114. spyOn(this.rosterview.model, 'remove').andCallThrough();
  115. //spyOn(view, 'removeContact').andCallThrough();
  116. runs($.proxy(function () {
  117. view.$el.find('.remove-xmpp-contact').click();
  118. }, converse));
  119. waits(500);
  120. runs($.proxy(function () {
  121. expect(window.confirm).toHaveBeenCalled();
  122. //expect(view.removeContact).toHaveBeenCalled();
  123. expect(this.connection.roster.remove).toHaveBeenCalled();
  124. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  125. expect(this.rosterview.model.remove).toHaveBeenCalled();
  126. // The element must now be detached from the DOM.
  127. expect(view.$el.closest('html').length).toBeFalsy();
  128. }, converse));
  129. }, converse));
  130. it("will lose their own heading once the last one has been removed", $.proxy(function () {
  131. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
  132. }, converse));
  133. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  134. var i, t, is_last;
  135. spyOn(this.rosterview, 'render').andCallThrough();
  136. for (i=0; i<mock.pend_names.length; i++) {
  137. is_last = i===(mock.pend_names.length-1);
  138. this.roster.create({
  139. jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  140. subscription: 'none',
  141. ask: 'subscribe',
  142. fullname: mock.pend_names[i],
  143. is_last: is_last
  144. });
  145. expect(this.rosterview.render).toHaveBeenCalled();
  146. // Check that they are sorted alphabetically
  147. t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
  148. expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
  149. }
  150. }, converse));
  151. it("will have their own heading once they have been added", $.proxy(function () {
  152. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
  153. }, converse));
  154. }, converse));
  155. describe("Existing Contacts", $.proxy(function () {
  156. beforeEach($.proxy(function () {
  157. utils.openControlBox();
  158. }, converse));
  159. it("do not have a heading if there aren't any", $.proxy(function () {
  160. expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
  161. }, converse));
  162. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  163. var i, t;
  164. spyOn(this.rosterview, 'render').andCallThrough();
  165. for (i=0; i<mock.cur_names.length; i++) {
  166. this.roster.create({
  167. jid: mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
  168. subscription: 'both',
  169. ask: null,
  170. fullname: mock.cur_names[i],
  171. is_last: i===(mock.cur_names.length-1)
  172. });
  173. expect(this.rosterview.render).toHaveBeenCalled();
  174. // Check that they are sorted alphabetically
  175. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
  176. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  177. }
  178. }, converse));
  179. it("will have their own heading once they have been added", $.proxy(function () {
  180. expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
  181. }, converse));
  182. it("can change their status to online and be sorted alphabetically", $.proxy(function () {
  183. var item, view, jid, t;
  184. spyOn(this.rosterview, 'render').andCallThrough();
  185. for (i=0; i<3; i++) {
  186. jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  187. view = this.rosterview.rosteritemviews[jid];
  188. spyOn(view, 'render').andCallThrough();
  189. item = view.model;
  190. item.set('chat_status', 'online');
  191. expect(view.render).toHaveBeenCalled();
  192. expect(this.rosterview.render).toHaveBeenCalled();
  193. // Check that they are sorted alphabetically
  194. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
  195. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  196. }
  197. }, converse));
  198. it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
  199. var item, view, jid, t;
  200. spyOn(this.rosterview, 'render').andCallThrough();
  201. for (i=3; i<6; i++) {
  202. jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  203. view = this.rosterview.rosteritemviews[jid];
  204. spyOn(view, 'render').andCallThrough();
  205. item = view.model;
  206. item.set('chat_status', 'dnd');
  207. expect(view.render).toHaveBeenCalled();
  208. expect(this.rosterview.render).toHaveBeenCalled();
  209. // Check that they are sorted alphabetically
  210. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
  211. expect(t).toEqual(mock.cur_names.slice(3,i+1).sort().join(''));
  212. }
  213. }, converse));
  214. it("can change their status to away and be sorted alphabetically", $.proxy(function () {
  215. var item, view, jid, t;
  216. spyOn(this.rosterview, 'render').andCallThrough();
  217. for (i=6; i<9; i++) {
  218. jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  219. view = this.rosterview.rosteritemviews[jid];
  220. spyOn(view, 'render').andCallThrough();
  221. item = view.model;
  222. item.set('chat_status', 'away');
  223. expect(view.render).toHaveBeenCalled();
  224. expect(this.rosterview.render).toHaveBeenCalled();
  225. // Check that they are sorted alphabetically
  226. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
  227. expect(t).toEqual(mock.cur_names.slice(6,i+1).sort().join(''));
  228. }
  229. }, converse));
  230. it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
  231. var item, view, jid, t;
  232. spyOn(this.rosterview, 'render').andCallThrough();
  233. for (i=9; i<12; i++) {
  234. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  235. view = this.rosterview.rosteritemviews[jid];
  236. spyOn(view, 'render').andCallThrough();
  237. item = view.model;
  238. item.set('chat_status', 'xa');
  239. expect(view.render).toHaveBeenCalled();
  240. expect(this.rosterview.render).toHaveBeenCalled();
  241. // Check that they are sorted alphabetically
  242. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
  243. expect(t).toEqual(mock.cur_names.slice(9,i+1).sort().join(''));
  244. }
  245. }, converse));
  246. it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
  247. var item, view, jid, t;
  248. spyOn(this.rosterview, 'render').andCallThrough();
  249. for (i=12; i<15; i++) {
  250. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  251. view = this.rosterview.rosteritemviews[jid];
  252. spyOn(view, 'render').andCallThrough();
  253. item = view.model;
  254. item.set('chat_status', 'unavailable');
  255. expect(view.render).toHaveBeenCalled();
  256. expect(this.rosterview.render).toHaveBeenCalled();
  257. // Check that they are sorted alphabetically
  258. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
  259. expect(t).toEqual(mock.cur_names.slice(12, i+1).sort().join(''));
  260. }
  261. }, converse));
  262. it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () {
  263. var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
  264. var i;
  265. for (i=0; i<3; i++) {
  266. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
  267. }
  268. for (i=3; i<6; i++) {
  269. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
  270. }
  271. for (i=6; i<9; i++) {
  272. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
  273. }
  274. for (i=9; i<12; i++) {
  275. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('xa');
  276. }
  277. for (i=12; i<15; i++) {
  278. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
  279. }
  280. for (i=15; i<mock.cur_names.length; i++) {
  281. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
  282. }
  283. }, converse));
  284. }, converse));
  285. describe("Requesting Contacts", $.proxy(function () {
  286. // by default the dts are hidden from css class and only later they will be hidden
  287. // by jQuery therefore for the first check we will see if visible instead of none
  288. it("do not have a heading if there aren't any", $.proxy(function () {
  289. expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
  290. }, converse));
  291. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  292. var i, t;
  293. spyOn(this.rosterview, 'render').andCallThrough();
  294. spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
  295. for (i=0; i<mock.req_names.length; i++) {
  296. this.roster.create({
  297. jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  298. subscription: 'none',
  299. ask: null,
  300. requesting: true,
  301. fullname: mock.req_names[i],
  302. is_last: i===(mock.req_names.length-1)
  303. });
  304. expect(this.rosterview.render).toHaveBeenCalled();
  305. // Check that they are sorted alphabetically
  306. t = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').text().replace(/AcceptDecline/g, '');
  307. expect(t).toEqual(mock.req_names.slice(0,i+1).sort().join(''));
  308. // When a requesting contact is added, the controlbox must
  309. // be opened.
  310. expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
  311. }
  312. }, converse));
  313. it("will have their own heading once they have been added", $.proxy(function () {
  314. expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
  315. }, converse));
  316. it("can have their requests accepted by the user", $.proxy(function () {
  317. // TODO: Testing can be more thorough here, the user is
  318. // actually not accepted/authorized because of
  319. // mock_connection.
  320. var jid = mock.req_names.sort()[0].replace(' ','.').toLowerCase() + '@localhost';
  321. var view = this.rosterview.rosteritemviews[jid];
  322. spyOn(this.connection.roster, 'authorize');
  323. spyOn(view, 'acceptRequest').andCallThrough();
  324. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  325. var accept_button = view.$el.find('.accept-xmpp-request');
  326. accept_button.click();
  327. expect(view.acceptRequest).toHaveBeenCalled();
  328. expect(this.connection.roster.authorize).toHaveBeenCalled();
  329. }, converse));
  330. it("can have their requests denied by the user", $.proxy(function () {
  331. var jid = mock.req_names.sort()[1].replace(/ /g,'.').toLowerCase() + '@localhost';
  332. var view = this.rosterview.rosteritemviews[jid];
  333. spyOn(this.connection.roster, 'unauthorize');
  334. spyOn(this.rosterview, 'removeRosterItemView').andCallThrough();
  335. spyOn(view, 'declineRequest').andCallThrough();
  336. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  337. var accept_button = view.$el.find('.decline-xmpp-request');
  338. accept_button.click();
  339. expect(view.declineRequest).toHaveBeenCalled();
  340. expect(this.rosterview.removeRosterItemView).toHaveBeenCalled();
  341. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  342. // There should now be one less contact
  343. expect(this.roster.length).toEqual(mock.num_contacts-1);
  344. }, converse));
  345. }, converse));
  346. describe("All Contacts", $.proxy(function () {
  347. it("are saved to, and can be retrieved from, localStorage", $.proxy(function () {
  348. var new_attrs, old_attrs, attrs, old_roster;
  349. var num_contacts = this.roster.length;
  350. new_roster = new this.RosterItems();
  351. // Roster items are yet to be fetched from localStorage
  352. expect(new_roster.length).toEqual(0);
  353. new_roster.localStorage = new Backbone.LocalStorage(
  354. hex_sha1('converse.rosteritems-dummy@localhost'));
  355. new_roster.fetch();
  356. expect(this.roster.length).toEqual(num_contacts);
  357. // Check that the roster items retrieved from localStorage
  358. // have the same attributes values as the original ones.
  359. attrs = ['jid', 'fullname', 'subscription', 'ask'];
  360. for (i=0; i<attrs.length; i++) {
  361. new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
  362. old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
  363. // Roster items in storage are not necessarily sorted,
  364. // so we have to sort them here to do a proper
  365. // comparison
  366. expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
  367. }
  368. this.rosterview.render();
  369. }, converse));
  370. afterEach($.proxy(function () {
  371. // Contacts retrieved from localStorage have chat_status of
  372. // "offline".
  373. // In the next test suite, we need some online contacts, so
  374. // we make some online now
  375. for (i=0; i<5; i++) {
  376. jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  377. view = this.rosterview.rosteritemviews[jid];
  378. view.model.set('chat_status', 'online');
  379. }
  380. }, converse));
  381. }, converse));
  382. }, converse, utils, mock));
  383. describe("The 'Add Contact' widget", $.proxy(function (utils, mock) {
  384. it("opens up an add form when you click on it", $.proxy(function () {
  385. var panel = this.chatboxesview.views.controlbox.contactspanel;
  386. spyOn(panel, 'toggleContactForm').andCallThrough();
  387. panel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  388. panel.$el.find('a.toggle-xmpp-contact-form').click();
  389. expect(panel.toggleContactForm).toHaveBeenCalled();
  390. // XXX: Awaiting more tests, close it again for now...
  391. panel.$el.find('a.toggle-xmpp-contact-form').click();
  392. }, converse));
  393. }, converse, utils, mock));
  394. describe("The Controlbox Tabs", $.proxy(function () {
  395. beforeEach($.proxy(function () {
  396. utils.closeAllChatBoxes();
  397. utils.openControlBox();
  398. }, converse));
  399. it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
  400. var cbview = this.chatboxesview.views.controlbox;
  401. var $panels = cbview.$el.find('.controlbox-panes');
  402. expect($panels.children().length).toBe(2);
  403. expect($panels.children().first().attr('id')).toBe('users');
  404. expect($panels.children().first().is(':visible')).toBe(true);
  405. expect($panels.children().last().attr('id')).toBe('chatrooms');
  406. expect($panels.children().last().is(':visible')).toBe(false);
  407. }, converse));
  408. describe("The Chatrooms Panel", $.proxy(function () {
  409. beforeEach($.proxy(function () {
  410. utils.closeAllChatBoxes();
  411. utils.openControlBox();
  412. }, converse));
  413. it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
  414. var cbview = this.chatboxesview.views.controlbox;
  415. var $tabs = cbview.$el.find('#controlbox-tabs');
  416. var $panels = cbview.$el.find('.controlbox-panes');
  417. var $contacts = $panels.children().first();
  418. var $chatrooms = $panels.children().last();
  419. spyOn(cbview, 'switchTab').andCallThrough();
  420. cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  421. runs(function () {
  422. $tabs.find('li').last().find('a').click(); // Clicks the chatrooms tab
  423. });
  424. waits(250);
  425. runs(function () {
  426. expect($contacts.is(':visible')).toBe(false);
  427. expect($chatrooms.is(':visible')).toBe(true);
  428. expect(cbview.switchTab).toHaveBeenCalled();
  429. });
  430. }, converse));
  431. it("contains a form through which a new chatroom can be created", $.proxy(function () {
  432. var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
  433. var $input = roomspanel.$el.find('input.new-chatroom-name');
  434. var $nick = roomspanel.$el.find('input.new-chatroom-nick');
  435. var $server = roomspanel.$el.find('input.new-chatroom-server');
  436. expect($input.length).toBe(1);
  437. expect($server.length).toBe(1);
  438. expect($('.chatroom:visible').length).toBe(0); // There shouldn't be any chatrooms open currently
  439. spyOn(roomspanel, 'createChatRoom').andCallThrough();
  440. roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  441. runs(function () {
  442. $input.val('Lounge');
  443. $nick.val('dummy');
  444. $server.val('muc.localhost');
  445. });
  446. waits('250');
  447. runs(function () {
  448. roomspanel.$el.find('form').submit();
  449. expect(roomspanel.createChatRoom).toHaveBeenCalled();
  450. });
  451. waits('250');
  452. runs($.proxy(function () {
  453. expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
  454. }, converse));
  455. }, converse));
  456. }, converse));
  457. }, converse, mock, utils));
  458. }));