controlbox.js 29 KB

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