controlbox.js 29 KB

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