2
0

controlbox.js 29 KB

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