controlbox.js 28 KB

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