controlbox.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. (function (root, factory) {
  2. define([
  3. "jquery",
  4. "mock",
  5. "test_utils"
  6. ], function ($, mock, test_utils) {
  7. return factory($, mock, test_utils);
  8. }
  9. );
  10. } (this, function ($, mock, test_utils) {
  11. var checkHeaderToggling = function ($header) {
  12. var $toggle = $header.find('a.group-toggle');
  13. expect($header.css('display')).toEqual('block');
  14. expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy();
  15. expect($toggle.hasClass('icon-closed')).toBeFalsy();
  16. expect($toggle.hasClass('icon-opened')).toBeTruthy();
  17. $toggle.click();
  18. expect($toggle.hasClass('icon-closed')).toBeTruthy();
  19. expect($toggle.hasClass('icon-opened')).toBeFalsy();
  20. expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:hidden').length).toBeTruthy();
  21. $toggle.click();
  22. expect($toggle.hasClass('icon-closed')).toBeFalsy();
  23. expect($toggle.hasClass('icon-opened')).toBeTruthy();
  24. expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy();
  25. };
  26. describe("The Control Box", $.proxy(function (mock, test_utils) {
  27. beforeEach(function () {
  28. runs(function () {
  29. test_utils.openControlBox();
  30. });
  31. });
  32. it("can be opened by clicking a DOM element with class 'toggle-controlbox'", $.proxy(function () {
  33. runs(function () {
  34. test_utils.closeControlBox();
  35. });
  36. waits(50);
  37. runs(function () {
  38. // This spec will only pass if the controlbox is not currently
  39. // open yet.
  40. expect($("div#controlbox").is(':visible')).toBe(false);
  41. spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
  42. spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
  43. spyOn(converse, 'emit');
  44. // Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
  45. this.controlboxtoggle.delegateEvents();
  46. $('.toggle-controlbox').click();
  47. }.bind(converse));
  48. waits(50);
  49. runs(function () {
  50. expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
  51. expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
  52. expect(this.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
  53. expect($("div#controlbox").is(':visible')).toBe(true);
  54. }.bind(converse));
  55. }, converse));
  56. describe("The Status Widget", $.proxy(function () {
  57. beforeEach(function () {
  58. test_utils.openControlBox();
  59. });
  60. it("shows the user's chat status, which is online by default", $.proxy(function () {
  61. var view = this.xmppstatusview;
  62. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  63. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am online');
  64. }, converse));
  65. it("can be used to set the current user's chat status", $.proxy(function () {
  66. var view = this.xmppstatusview;
  67. spyOn(view, 'toggleOptions').andCallThrough();
  68. spyOn(view, 'setStatus').andCallThrough();
  69. spyOn(converse, 'emit');
  70. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  71. runs(function () {
  72. view.$el.find('a.choose-xmpp-status').click();
  73. expect(view.toggleOptions).toHaveBeenCalled();
  74. });
  75. waits(250);
  76. runs(function () {
  77. spyOn(view, 'updateStatusUI').andCallThrough();
  78. view.initialize(); // Rebind events for spy
  79. $(view.$el.find('.dropdown dd ul li a')[1]).click(); // Change status to "dnd"
  80. expect(view.setStatus).toHaveBeenCalled();
  81. expect(converse.emit).toHaveBeenCalledWith('statusChanged', 'dnd');
  82. });
  83. waits(250);
  84. runs($.proxy(function () {
  85. expect(view.updateStatusUI).toHaveBeenCalled();
  86. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false);
  87. expect(view.$el.find('a.choose-xmpp-status').hasClass('dnd')).toBe(true);
  88. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am busy');
  89. }, converse));
  90. }, converse));
  91. it("can be used to set a custom status message", $.proxy(function () {
  92. var view = this.xmppstatusview;
  93. this.xmppstatus.save({'status': 'online'});
  94. spyOn(view, 'setStatusMessage').andCallThrough();
  95. spyOn(view, 'renderStatusChangeForm').andCallThrough();
  96. spyOn(converse, 'emit');
  97. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  98. view.$el.find('a.change-xmpp-status-message').click();
  99. expect(view.renderStatusChangeForm).toHaveBeenCalled();
  100. // The async testing here is used only to provide time for
  101. // visual feedback
  102. var msg = 'I am happy';
  103. runs (function () {
  104. view.$el.find('form input.custom-xmpp-status').val(msg);
  105. });
  106. waits(250);
  107. runs (function () {
  108. view.$el.find('form#set-custom-xmpp-status').submit();
  109. expect(view.setStatusMessage).toHaveBeenCalled();
  110. expect(converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg);
  111. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  112. expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe(msg);
  113. });
  114. }, converse));
  115. }, converse));
  116. }, converse, mock, test_utils));
  117. describe("The Contacts Roster", $.proxy(function (mock, utils) {
  118. function _clearContacts () {
  119. utils.clearBrowserStorage();
  120. converse.rosterview.model.reset();
  121. }
  122. describe("The live filter", $.proxy(function () {
  123. it("will only appear when roster contacts flow over the visible area", $.proxy(function () {
  124. _clearContacts();
  125. var $filter = converse.rosterview.$('.roster-filter');
  126. var names = mock.cur_names;
  127. expect($filter.length).toBe(1);
  128. expect($filter.is(':visible')).toBeFalsy();
  129. for (i=0; i<names.length; i++) {
  130. converse.roster.create({
  131. ask: null,
  132. fullname: names[i],
  133. jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  134. requesting: 'false',
  135. subscription: 'both'
  136. });
  137. converse.rosterview.update(); // XXX: Will normally called as event handler
  138. if (converse.rosterview.$roster.hasScrollBar()) {
  139. expect($filter.is(':visible')).toBeTruthy();
  140. } else {
  141. expect($filter.is(':visible')).toBeFalsy();
  142. }
  143. }
  144. }, converse));
  145. it("can be used to filter the contacts shown", function () {
  146. var $filter;
  147. var $roster;
  148. runs(function () {
  149. _clearContacts();
  150. converse.roster_groups = true;
  151. utils.createGroupedContacts();
  152. $filter = converse.rosterview.$('.roster-filter');
  153. $roster = converse.rosterview.$roster;
  154. });
  155. waits(350); // Needed, due to debounce
  156. runs(function () {
  157. expect($roster.find('dd:visible').length).toBe(15);
  158. expect($roster.find('dt:visible').length).toBe(5);
  159. $filter.val("candice");
  160. expect($roster.find('dd:visible').length).toBe(15); // because no keydown event
  161. expect($roster.find('dt:visible').length).toBe(5); // ditto
  162. $filter.trigger('keydown');
  163. });
  164. waits(350); // Needed, due to debounce
  165. runs (function () {
  166. expect($roster.find('dd:visible').length).toBe(1);
  167. expect($roster.find('dd:visible').eq(0).text().trim()).toBe('Candice van der Knijff');
  168. expect($roster.find('dt:visible').length).toBe(1);
  169. expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues');
  170. $filter.val("an");
  171. $filter.trigger('keydown');
  172. });
  173. waits(350); // Needed, due to debounce
  174. runs (function () {
  175. expect($roster.find('dd:visible').length).toBe(5);
  176. expect($roster.find('dt:visible').length).toBe(4);
  177. $filter.val("xxx");
  178. $filter.trigger('keydown');
  179. });
  180. waits(350); // Needed, due to debounce
  181. runs (function () {
  182. expect($roster.find('dd:visible').length).toBe(0);
  183. expect($roster.find('dt:visible').length).toBe(0);
  184. $filter.val(""); // Check that contacts are shown again, when the filter string is cleared.
  185. $filter.trigger('keydown');
  186. });
  187. waits(350); // Needed, due to debounce
  188. runs(function () {
  189. expect($roster.find('dd:visible').length).toBe(15);
  190. expect($roster.find('dt:visible').length).toBe(5);
  191. });
  192. converse.roster_groups = false;
  193. });
  194. it("can be used to filter the groups shown", function () {
  195. var $filter;
  196. var $roster;
  197. var $type;
  198. runs(function () {
  199. converse.roster_groups = true;
  200. _clearContacts();
  201. utils.createGroupedContacts();
  202. $filter = converse.rosterview.$('.roster-filter');
  203. $roster = converse.rosterview.$roster;
  204. $type = converse.rosterview.$('.filter-type');
  205. $type.val('groups');
  206. });
  207. waits(350); // Needed, due to debounce
  208. runs(function () {
  209. expect($roster.find('dd:visible').length).toBe(15);
  210. expect($roster.find('dt:visible').length).toBe(5);
  211. $filter.val("colleagues");
  212. expect($roster.find('dd:visible').length).toBe(15); // because no keydown event
  213. expect($roster.find('dt:visible').length).toBe(5); // ditto
  214. $filter.trigger('keydown');
  215. });
  216. waits(350); // Needed, due to debounce
  217. runs (function () {
  218. expect($roster.find('dt:visible').length).toBe(1);
  219. expect($roster.find('dt:visible').eq(0).text()).toBe('colleagues');
  220. // Check that all contacts under the group are shown
  221. expect($roster.find('dt:visible').nextUntil('dt', 'dd:hidden').length).toBe(0);
  222. $filter.val("xxx");
  223. $filter.trigger('keydown');
  224. });
  225. waits(350); // Needed, due to debounce
  226. runs (function () {
  227. expect($roster.find('dt:visible').length).toBe(0);
  228. $filter.val(""); // Check that groups are shown again, when the filter string is cleared.
  229. $filter.trigger('keydown');
  230. });
  231. waits(350); // Needed, due to debounce
  232. runs(function () {
  233. expect($roster.find('dd:visible').length).toBe(15);
  234. expect($roster.find('dt:visible').length).toBe(5);
  235. });
  236. converse.roster_groups = false;
  237. });
  238. it("has a button with which its contents can be cleared", function () {
  239. converse.roster_groups = true;
  240. _clearContacts();
  241. utils.createGroupedContacts();
  242. var $filter = converse.rosterview.$('.roster-filter');
  243. var $roster = converse.rosterview.$roster;
  244. runs (function () {
  245. $filter.val("xxx");
  246. $filter.trigger('keydown');
  247. expect($filter.hasClass("x")).toBeFalsy();
  248. });
  249. waits(350); // Needed, due to debounce
  250. runs (function () {
  251. expect($filter.hasClass("x")).toBeTruthy();
  252. $filter.addClass("onX").click();
  253. expect($filter.val()).toBe("");
  254. });
  255. converse.roster_groups = false;
  256. });
  257. }, converse));
  258. describe("A Roster Group", $.proxy(function () {
  259. beforeEach(function () {
  260. converse.roster_groups = true;
  261. });
  262. afterEach(function () {
  263. converse.roster_groups = false;
  264. });
  265. it("can be used to organize existing contacts", $.proxy(function () {
  266. runs($.proxy(function () {
  267. _clearContacts();
  268. spyOn(converse, 'emit');
  269. spyOn(this.rosterview, 'update').andCallThrough();
  270. converse.rosterview.render();
  271. utils.createContacts('pending');
  272. utils.createContacts('requesting');
  273. utils.createGroupedContacts();
  274. }, this));
  275. waits(50); // Needed, due to debounce
  276. runs($.proxy(function () {
  277. // Check that the groups appear alphabetically and that
  278. // requesting and pending contacts are last.
  279. var group_titles = $.map(this.rosterview.$el.find('dt'), function (o) { return $(o).text().trim(); });
  280. expect(group_titles).toEqual([
  281. "colleagues",
  282. "Family",
  283. "friends & acquaintences",
  284. "ænemies",
  285. "Ungrouped",
  286. "Contact requests",
  287. "Pending contacts"
  288. ]);
  289. // Check that usernames appear alphabetically per group
  290. _.each(_.keys(mock.groups), $.proxy(function (name) {
  291. var $contacts = this.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
  292. var names = $.map($contacts, function (o) { return $(o).text().trim(); });
  293. expect(names).toEqual(_.clone(names).sort());
  294. }, converse));
  295. }, this));
  296. }, converse));
  297. it("can share contacts with other roster groups", $.proxy(function () {
  298. var groups = ['colleagues', 'friends'];
  299. runs($.proxy(function () {
  300. _clearContacts();
  301. var i=0, j=0;
  302. spyOn(converse, 'emit');
  303. spyOn(this.rosterview, 'update').andCallThrough();
  304. converse.rosterview.render();
  305. for (i=0; i<mock.cur_names.length; i++) {
  306. this.roster.create({
  307. jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  308. subscription: 'both',
  309. ask: null,
  310. groups: groups,
  311. fullname: mock.cur_names[i]
  312. });
  313. }
  314. }, this));
  315. waits(50); // Needed, due to debounce
  316. runs($.proxy(function () {
  317. // Check that usernames appear alphabetically per group
  318. _.each(groups, $.proxy(function (name) {
  319. var $contacts = this.rosterview.$('dt.roster-group[data-group="'+name+'"]').nextUntil('dt', 'dd');
  320. var names = $.map($contacts, function (o) { return $(o).text().trim(); });
  321. expect(names).toEqual(_.clone(names).sort());
  322. expect(names.length).toEqual(mock.cur_names.length);
  323. }, this));
  324. }, this));
  325. }, converse));
  326. it("remembers whether it is closed or opened", $.proxy(function () {
  327. var i=0, j=0;
  328. var groups = {
  329. 'colleagues': 3,
  330. 'friends & acquaintences': 3,
  331. 'Ungrouped': 2
  332. };
  333. _.each(_.keys(groups), $.proxy(function (name) {
  334. j = i;
  335. for (i=j; i<j+groups[name]; i++) {
  336. this.roster.create({
  337. jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  338. subscription: 'both',
  339. ask: null,
  340. groups: name === 'ungrouped'? [] : [name],
  341. fullname: mock.cur_names[i]
  342. });
  343. }
  344. }, converse));
  345. var view = this.rosterview.get('colleagues');
  346. var $toggle = view.$el.find('a.group-toggle');
  347. expect(view.model.get('state')).toBe('opened');
  348. $toggle.click();
  349. expect(view.model.get('state')).toBe('closed');
  350. $toggle.click();
  351. expect(view.model.get('state')).toBe('opened');
  352. }, converse));
  353. }, converse));
  354. describe("Pending Contacts", $.proxy(function () {
  355. function _clearContacts () {
  356. utils.clearBrowserStorage();
  357. converse.rosterview.model.reset();
  358. }
  359. function _addContacts () {
  360. _clearContacts();
  361. // Must be initialized, so that render is called and documentFragment set up.
  362. utils.createContacts('pending').openControlBox().openContactsPanel();
  363. }
  364. it("can be collapsed under their own header", $.proxy(function () {
  365. runs(function () {
  366. _addContacts();
  367. });
  368. waits(50);
  369. runs($.proxy(function () {
  370. checkHeaderToggling.apply(this, [this.rosterview.get('Pending contacts').$el]);
  371. }, this));
  372. }, converse));
  373. it("can be added to the roster", $.proxy(function () {
  374. _clearContacts();
  375. spyOn(converse, 'emit');
  376. spyOn(this.rosterview, 'update').andCallThrough();
  377. runs($.proxy(function () {
  378. this.roster.create({
  379. jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
  380. subscription: 'none',
  381. ask: 'subscribe',
  382. fullname: mock.pend_names[0]
  383. });
  384. }, converse));
  385. waits(300);
  386. runs($.proxy(function () {
  387. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  388. expect(this.rosterview.update).toHaveBeenCalled();
  389. }, converse));
  390. }, converse));
  391. it("are shown in the roster when show_only_online_users", $.proxy(function () {
  392. converse.show_only_online_users = true;
  393. runs(function () {
  394. _addContacts();
  395. });
  396. waits(50);
  397. spyOn(this.rosterview, 'update').andCallThrough();
  398. runs($.proxy(function () {
  399. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  400. expect(this.rosterview.update).toHaveBeenCalled();
  401. }, converse));
  402. waits(300); // Needed, due to debounce
  403. runs ($.proxy(function () {
  404. expect(this.rosterview.$el.find('dd:visible').length).toBe(3);
  405. expect(this.rosterview.$el.find('dt:visible').length).toBe(1);
  406. }, converse));
  407. converse.show_only_online_users = false;
  408. }, converse));
  409. it("are shown in the roster when hide_offline_users", $.proxy(function () {
  410. converse.hide_offline_users = true;
  411. runs(function () {
  412. _addContacts();
  413. });
  414. waits(50);
  415. spyOn(this.rosterview, 'update').andCallThrough();
  416. waits(50);
  417. runs($.proxy(function () {
  418. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  419. expect(this.rosterview.update).toHaveBeenCalled();
  420. }, converse));
  421. waits(300); // Needed, due to debounce
  422. runs ($.proxy(function () {
  423. expect(this.rosterview.$el.find('dd:visible').length).toBe(3);
  424. expect(this.rosterview.$el.find('dt:visible').length).toBe(1);
  425. }, converse));
  426. converse.hide_offline_users = false;
  427. }, converse));
  428. it("can be removed by the user", $.proxy(function () {
  429. runs($.proxy(function () {
  430. _addContacts();
  431. }, this));
  432. waits(50);
  433. runs($.proxy(function () {
  434. /* FIXME: Monkepatch
  435. * After refactoring the mock connection to use a
  436. * Strophe.Connection object, these tests fail because "remove"
  437. * function in strophe.roster (line 292) gets called and it
  438. * then tries to actually remove the user which is not in the roster...
  439. */
  440. var old_remove = this.connection.roster.remove;
  441. this.connection.roster.remove = function (jid, callback) { callback(); };
  442. var name = mock.pend_names[0];
  443. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  444. spyOn(window, 'confirm').andReturn(true);
  445. spyOn(converse, 'emit');
  446. spyOn(this.connection.roster, 'remove').andCallThrough();
  447. spyOn(this.connection.roster, 'unauthorize');
  448. spyOn(this.rosterview.model, 'remove').andCallThrough();
  449. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  450. .siblings('.remove-xmpp-contact').click();
  451. expect(window.confirm).toHaveBeenCalled();
  452. expect(this.connection.roster.remove).toHaveBeenCalled();
  453. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  454. expect(this.rosterview.model.remove).toHaveBeenCalled();
  455. expect(converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length).toEqual(0);
  456. /* XXX Restore Monkeypatch */
  457. this.connection.roster.remove = old_remove;
  458. }, this));
  459. }, converse));
  460. it("do not have a header if there aren't any", $.proxy(function () {
  461. var name = mock.pend_names[0];
  462. runs($.proxy(function () {
  463. _clearContacts();
  464. }, this));
  465. waits(50);
  466. runs($.proxy(function () {
  467. spyOn(window, 'confirm').andReturn(true);
  468. this.roster.create({
  469. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  470. subscription: 'none',
  471. ask: 'subscribe',
  472. fullname: name
  473. });
  474. expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(true);
  475. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  476. .siblings('.remove-xmpp-contact').click();
  477. expect(window.confirm).toHaveBeenCalled();
  478. expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(false);
  479. }, this));
  480. }, converse));
  481. it("will lose their own header once the last one has been removed", $.proxy(function () {
  482. _addContacts();
  483. var name;
  484. spyOn(window, 'confirm').andReturn(true);
  485. for (i=0; i<mock.pend_names.length; i++) {
  486. name = mock.pend_names[i];
  487. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  488. .siblings('.remove-xmpp-contact').click();
  489. }
  490. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
  491. }, converse));
  492. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  493. _clearContacts();
  494. var i, t;
  495. spyOn(converse, 'emit');
  496. spyOn(this.rosterview, 'update').andCallThrough();
  497. for (i=0; i<mock.pend_names.length; i++) {
  498. this.roster.create({
  499. jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  500. subscription: 'none',
  501. ask: 'subscribe',
  502. fullname: mock.pend_names[i]
  503. });
  504. expect(this.rosterview.update).toHaveBeenCalled();
  505. }
  506. // Check that they are sorted alphabetically
  507. t = this.rosterview.get('Pending contacts').$el.siblings('dd.pending-xmpp-contact').find('span').text();
  508. expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
  509. }, converse));
  510. }, converse));
  511. describe("Existing Contacts", $.proxy(function () {
  512. function _clearContacts () {
  513. utils.clearBrowserStorage();
  514. converse.rosterview.model.reset();
  515. }
  516. var _addContacts = function () {
  517. _clearContacts();
  518. utils.createContacts('current').openControlBox().openContactsPanel();
  519. };
  520. it("can be collapsed under their own header", $.proxy(function () {
  521. runs(function () {
  522. _addContacts();
  523. });
  524. waits(50);
  525. runs($.proxy(function () {
  526. checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
  527. }, this));
  528. }, converse));
  529. it("will be hidden when appearing under a collapsed group", $.proxy(function () {
  530. _addContacts();
  531. this.rosterview.$el.find('dt.roster-group').find('a.group-toggle').click();
  532. var name = "Max Mustermann";
  533. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  534. converse.roster.create({
  535. ask: null,
  536. fullname: name,
  537. jid: jid,
  538. requesting: false,
  539. subscription: 'both'
  540. });
  541. var view = this.rosterview.get('My contacts').get(jid);
  542. expect(view.$el.is(':visible')).toBe(false);
  543. }, converse));
  544. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  545. runs(function () {
  546. _clearContacts();
  547. });
  548. waits(50);
  549. runs($.proxy(function () {
  550. var i, t;
  551. spyOn(converse, 'emit');
  552. spyOn(this.rosterview, 'update').andCallThrough();
  553. for (i=0; i<mock.cur_names.length; i++) {
  554. this.roster.create({
  555. jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  556. subscription: 'both',
  557. ask: null,
  558. fullname: mock.cur_names[i]
  559. });
  560. expect(this.rosterview.update).toHaveBeenCalled();
  561. }
  562. // Check that they are sorted alphabetically
  563. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
  564. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  565. }, this));
  566. }, converse));
  567. it("can be removed by the user", $.proxy(function () {
  568. runs(function () {
  569. _addContacts();
  570. });
  571. waits(50);
  572. runs($.proxy(function () {
  573. /* FIXME: Monkepatch
  574. * After refactoring the mock connection to use a
  575. * Strophe.Connection object, these tests fail because "remove"
  576. * function in strophe.roster (line 292) gets called and it
  577. * then tries to actually remove the user which is not in the roster...
  578. */
  579. var old_remove = this.connection.roster.remove;
  580. this.connection.roster.remove = function (jid, callback) { callback(); };
  581. var name = mock.cur_names[0];
  582. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  583. spyOn(window, 'confirm').andReturn(true);
  584. spyOn(converse, 'emit');
  585. spyOn(this.connection.roster, 'remove').andCallThrough();
  586. spyOn(this.connection.roster, 'unauthorize');
  587. spyOn(this.rosterview.model, 'remove').andCallThrough();
  588. converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
  589. .siblings('.remove-xmpp-contact').click();
  590. expect(window.confirm).toHaveBeenCalled();
  591. expect(this.connection.roster.remove).toHaveBeenCalled();
  592. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  593. expect(this.rosterview.model.remove).toHaveBeenCalled();
  594. expect(converse.rosterview.$el.find(".open-chat:contains('"+name+"')").length).toEqual(0);
  595. /* XXX Restore Monkeypatch */
  596. this.connection.roster.remove = old_remove;
  597. }, this));
  598. }, converse));
  599. it("do not have a header if there aren't any", $.proxy(function () {
  600. var name = mock.cur_names[0];
  601. runs(function () {
  602. _clearContacts();
  603. });
  604. waits(50);
  605. runs($.proxy(function () {
  606. spyOn(window, 'confirm').andReturn(true);
  607. this.roster.create({
  608. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  609. subscription: 'both',
  610. ask: null,
  611. fullname: name
  612. });
  613. expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('block');
  614. converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
  615. .siblings('.remove-xmpp-contact').click();
  616. expect(window.confirm).toHaveBeenCalled();
  617. expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
  618. }, this));
  619. }, converse));
  620. it("can change their status to online and be sorted alphabetically", $.proxy(function () {
  621. runs(function () {
  622. _addContacts();
  623. });
  624. waits(50);
  625. runs($.proxy(function () {
  626. var jid, t;
  627. spyOn(converse, 'emit');
  628. spyOn(this.rosterview, 'update').andCallThrough();
  629. for (i=0; i<mock.cur_names.length; i++) {
  630. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  631. this.roster.get(jid).set('chat_status', 'online');
  632. expect(this.rosterview.update).toHaveBeenCalled();
  633. // Check that they are sorted alphabetically
  634. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
  635. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  636. }
  637. }, this));
  638. }, converse));
  639. it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
  640. runs(function () {
  641. _addContacts();
  642. });
  643. waits(50);
  644. runs($.proxy(function () {
  645. var jid, t;
  646. spyOn(converse, 'emit');
  647. spyOn(this.rosterview, 'update').andCallThrough();
  648. for (i=0; i<mock.cur_names.length; i++) {
  649. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  650. this.roster.get(jid).set('chat_status', 'dnd');
  651. expect(this.rosterview.update).toHaveBeenCalled();
  652. // Check that they are sorted alphabetically
  653. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
  654. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  655. }
  656. }, this));
  657. }, converse));
  658. it("can change their status to away and be sorted alphabetically", $.proxy(function () {
  659. runs(function () {
  660. _addContacts();
  661. });
  662. waits(50);
  663. runs($.proxy(function () {
  664. var jid, t;
  665. spyOn(converse, 'emit');
  666. spyOn(this.rosterview, 'update').andCallThrough();
  667. for (i=0; i<mock.cur_names.length; i++) {
  668. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  669. this.roster.get(jid).set('chat_status', 'away');
  670. expect(this.rosterview.update).toHaveBeenCalled();
  671. // Check that they are sorted alphabetically
  672. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
  673. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  674. }
  675. }, this));
  676. }, converse));
  677. it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
  678. runs(function () {
  679. _addContacts();
  680. });
  681. waits(50);
  682. runs($.proxy(function () {
  683. var jid, t;
  684. spyOn(converse, 'emit');
  685. spyOn(this.rosterview, 'update').andCallThrough();
  686. for (i=0; i<mock.cur_names.length; i++) {
  687. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  688. this.roster.get(jid).set('chat_status', 'xa');
  689. expect(this.rosterview.update).toHaveBeenCalled();
  690. // Check that they are sorted alphabetically
  691. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
  692. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  693. }
  694. }, this));
  695. }, converse));
  696. it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
  697. runs(function () {
  698. _addContacts();
  699. });
  700. waits(50);
  701. runs($.proxy(function () {
  702. var jid, t;
  703. spyOn(converse, 'emit');
  704. spyOn(this.rosterview, 'update').andCallThrough();
  705. for (i=0; i<mock.cur_names.length; i++) {
  706. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  707. this.roster.get(jid).set('chat_status', 'unavailable');
  708. expect(this.rosterview.update).toHaveBeenCalled();
  709. // Check that they are sorted alphabetically
  710. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
  711. expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join(''));
  712. }
  713. }, this));
  714. }, converse));
  715. it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () {
  716. runs(function () {
  717. _addContacts();
  718. });
  719. waits(50);
  720. runs($.proxy(function () {
  721. var i;
  722. for (i=0; i<3; i++) {
  723. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  724. this.roster.get(jid).set('chat_status', 'online');
  725. }
  726. for (i=3; i<6; i++) {
  727. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  728. this.roster.get(jid).set('chat_status', 'dnd');
  729. }
  730. for (i=6; i<9; i++) {
  731. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  732. this.roster.get(jid).set('chat_status', 'away');
  733. }
  734. for (i=9; i<12; i++) {
  735. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  736. this.roster.get(jid).set('chat_status', 'xa');
  737. }
  738. for (i=12; i<15; i++) {
  739. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  740. this.roster.get(jid).set('chat_status', 'unavailable');
  741. }
  742. var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
  743. for (i=0; i<3; i++) {
  744. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
  745. }
  746. for (i=3; i<6; i++) {
  747. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
  748. }
  749. for (i=6; i<9; i++) {
  750. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
  751. }
  752. for (i=9; i<12; i++) {
  753. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('xa');
  754. }
  755. for (i=12; i<15; i++) {
  756. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
  757. }
  758. for (i=15; i<mock.cur_names.length; i++) {
  759. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
  760. }
  761. }, this));
  762. }, converse));
  763. }, converse));
  764. describe("Requesting Contacts", $.proxy(function () {
  765. beforeEach($.proxy(function () {
  766. runs(function () {
  767. utils.clearBrowserStorage();
  768. converse.rosterview.model.reset();
  769. utils.createContacts('requesting').openControlBox();
  770. });
  771. waits(50);
  772. runs(function () {
  773. utils.openContactsPanel();
  774. });
  775. }, converse));
  776. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  777. converse.rosterview.model.reset(); // We want to manually create users so that we can spy
  778. var i, children;
  779. var names = [];
  780. spyOn(converse, 'emit');
  781. spyOn(this.rosterview, 'update').andCallThrough();
  782. spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
  783. var addName = function (idx, item) {
  784. if (!$(item).hasClass('request-actions')) {
  785. names.push($(item).text().replace(/^\s+|\s+$/g, ''));
  786. }
  787. };
  788. for (i=0; i<mock.req_names.length; i++) {
  789. this.roster.create({
  790. jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  791. subscription: 'none',
  792. ask: null,
  793. requesting: true,
  794. fullname: mock.req_names[i]
  795. });
  796. expect(this.rosterview.update).toHaveBeenCalled();
  797. // When a requesting contact is added, the controlbox must
  798. // be opened.
  799. expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
  800. }
  801. // Check that they are sorted alphabetically
  802. children = this.rosterview.get('Contact requests').$el.siblings('dd.requesting-xmpp-contact').children('span');
  803. names = [];
  804. children.each(addName);
  805. expect(names.join('')).toEqual(mock.req_names.slice(0,i+1).sort().join(''));
  806. }, converse));
  807. it("do not have a header if there aren't any", $.proxy(function () {
  808. converse.rosterview.model.reset(); // We want to manually create users so that we can spy
  809. var name = mock.req_names[0];
  810. runs($.proxy(function () {
  811. spyOn(window, 'confirm').andReturn(true);
  812. this.roster.create({
  813. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  814. subscription: 'none',
  815. ask: null,
  816. requesting: true,
  817. fullname: name
  818. });
  819. }, this));
  820. waits(50);
  821. runs($.proxy(function () {
  822. expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(true);
  823. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  824. .siblings('.request-actions')
  825. .find('.decline-xmpp-request').click();
  826. expect(window.confirm).toHaveBeenCalled();
  827. expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(false);
  828. }, this));
  829. }, converse));
  830. it("can be collapsed under their own header", $.proxy(function () {
  831. checkHeaderToggling.apply(this, [this.rosterview.get('Contact requests').$el]);
  832. }, converse));
  833. it("can have their requests accepted by the user", $.proxy(function () {
  834. // TODO: Testing can be more thorough here, the user is
  835. // actually not accepted/authorized because of
  836. // mock_connection.
  837. var name = mock.req_names.sort()[0];
  838. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  839. spyOn(this.connection.roster, 'authorize');
  840. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  841. .siblings('.request-actions')
  842. .find('.accept-xmpp-request').click();
  843. expect(this.connection.roster.authorize).toHaveBeenCalled();
  844. }, converse));
  845. it("can have their requests denied by the user", $.proxy(function () {
  846. this.rosterview.model.reset();
  847. runs($.proxy(function () {
  848. spyOn(converse, 'emit');
  849. spyOn(this.connection.roster, 'unauthorize');
  850. spyOn(window, 'confirm').andReturn(true);
  851. utils.createContacts('requesting').openControlBox();
  852. converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
  853. }, this));
  854. waits(50);
  855. runs($.proxy(function () {
  856. var name = mock.req_names.sort()[1];
  857. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  858. .siblings('.request-actions')
  859. .find('.decline-xmpp-request').click();
  860. }, this));
  861. waits(50);
  862. runs($.proxy(function () {
  863. expect(window.confirm).toHaveBeenCalled();
  864. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  865. // There should now be one less contact
  866. expect(this.roster.length).toEqual(mock.req_names.length-1);
  867. }, this));
  868. }, converse));
  869. it("are persisted even if other contacts' change their presence ", $.proxy(function() {
  870. /* This is a regression test.
  871. * https://github.com/jcbrand/converse.js/issues/262
  872. */
  873. this.rosterview.model.reset();
  874. spyOn(this.roster, 'clearCache').andCallThrough();
  875. expect(this.roster.pluck('jid').length).toBe(0);
  876. var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
  877. this.connection._dataRecv(test_utils.createRequest(stanza));
  878. expect(this.roster.pluck('jid').length).toBe(1);
  879. expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
  880. // Taken from the spec
  881. // http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
  882. stanza = $iq({
  883. to: this.connection.jid,
  884. type: 'result',
  885. id: 'roster_1'
  886. }).c('query', {
  887. xmlns: 'jabber:iq:roster',
  888. }).c('item', {
  889. jid: 'romeo@example.net',
  890. name: 'Romeo',
  891. subscription:'both'
  892. }).c('group').t('Friends').up().up()
  893. .c('item', {
  894. jid: 'mercutio@example.org',
  895. name: 'Mercutio',
  896. subscription:'from'
  897. }).c('group').t('Friends').up().up()
  898. .c('item', {
  899. jid: 'benvolio@example.org',
  900. name: 'Benvolio',
  901. subscription:'both'
  902. }).c('group').t('Friends');
  903. this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
  904. expect(this.roster.clearCache).toHaveBeenCalled();
  905. expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
  906. }, converse));
  907. }, converse));
  908. describe("All Contacts", $.proxy(function () {
  909. beforeEach($.proxy(function () {
  910. utils.clearBrowserStorage();
  911. converse.rosterview.model.reset();
  912. utils.createContacts('all').openControlBox();
  913. utils.openContactsPanel();
  914. }, converse));
  915. it("are saved to, and can be retrieved from, browserStorage", $.proxy(function () {
  916. var new_attrs, old_attrs, attrs;
  917. var num_contacts = this.roster.length;
  918. new_roster = new this.RosterContacts();
  919. // Roster items are yet to be fetched from browserStorage
  920. expect(new_roster.length).toEqual(0);
  921. new_roster.browserStorage = this.roster.browserStorage;
  922. new_roster.fetch();
  923. expect(new_roster.length).toEqual(num_contacts);
  924. // Check that the roster items retrieved from browserStorage
  925. // have the same attributes values as the original ones.
  926. attrs = ['jid', 'fullname', 'subscription', 'ask'];
  927. for (i=0; i<attrs.length; i++) {
  928. new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
  929. old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
  930. // Roster items in storage are not necessarily sorted,
  931. // so we have to sort them here to do a proper
  932. // comparison
  933. expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
  934. }
  935. }, converse));
  936. }, converse));
  937. }, converse, mock, test_utils));
  938. describe("The 'Add Contact' widget", $.proxy(function (mock, test_utils) {
  939. it("opens up an add form when you click on it", $.proxy(function () {
  940. var panel = this.chatboxviews.get('controlbox').contactspanel;
  941. spyOn(panel, 'toggleContactForm').andCallThrough();
  942. panel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  943. panel.$el.find('a.toggle-xmpp-contact-form').click();
  944. expect(panel.toggleContactForm).toHaveBeenCalled();
  945. // XXX: Awaiting more tests, close it again for now...
  946. panel.$el.find('a.toggle-xmpp-contact-form').click();
  947. }, converse));
  948. }, converse, mock, test_utils));
  949. describe("The Controlbox Tabs", $.proxy(function () {
  950. beforeEach($.proxy(function () {
  951. runs(function () {
  952. test_utils.closeAllChatBoxes();
  953. });
  954. waits(50);
  955. runs(function () {
  956. test_utils.openControlBox();
  957. });
  958. }, converse));
  959. it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
  960. var cbview = this.chatboxviews.get('controlbox');
  961. var $panels = cbview.$el.find('.controlbox-panes');
  962. expect($panels.children().length).toBe(2);
  963. expect($panels.children().first().attr('id')).toBe('users');
  964. expect($panels.children().first().is(':visible')).toBe(true);
  965. expect($panels.children().last().attr('id')).toBe('chatrooms');
  966. expect($panels.children().last().is(':visible')).toBe(false);
  967. }, converse));
  968. describe("chatrooms panel", $.proxy(function () {
  969. beforeEach($.proxy(function () {
  970. runs(function () {
  971. test_utils.closeAllChatBoxes();
  972. });
  973. waits(50);
  974. runs(function () {
  975. test_utils.openControlBox();
  976. });
  977. }, converse));
  978. it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
  979. var cbview = this.chatboxviews.get('controlbox');
  980. var $tabs = cbview.$el.find('#controlbox-tabs');
  981. var $panels = cbview.$el.find('.controlbox-panes');
  982. var $contacts = $panels.children().first();
  983. var $chatrooms = $panels.children().last();
  984. spyOn(cbview, 'switchTab').andCallThrough();
  985. cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  986. runs(function () {
  987. $tabs.find('li').last().find('a').click(); // Clicks the chatrooms tab
  988. });
  989. waits(250);
  990. runs(function () {
  991. expect($contacts.is(':visible')).toBe(false);
  992. expect($chatrooms.is(':visible')).toBe(true);
  993. expect(cbview.switchTab).toHaveBeenCalled();
  994. });
  995. }, converse));
  996. it("contains a form through which a new chatroom can be created", $.proxy(function () {
  997. var roomspanel = this.chatboxviews.get('controlbox').roomspanel;
  998. var $input = roomspanel.$el.find('input.new-chatroom-name');
  999. var $nick = roomspanel.$el.find('input.new-chatroom-nick');
  1000. var $server = roomspanel.$el.find('input.new-chatroom-server');
  1001. expect($input.length).toBe(1);
  1002. expect($server.length).toBe(1);
  1003. expect($('.chatroom:visible').length).toBe(0); // There shouldn't be any chatrooms open currently
  1004. spyOn(roomspanel, 'createChatRoom').andCallThrough();
  1005. roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  1006. runs(function () {
  1007. $input.val('Lounge');
  1008. $nick.val('dummy');
  1009. $server.val('muc.localhost');
  1010. });
  1011. waits('250');
  1012. runs(function () {
  1013. roomspanel.$el.find('form').submit();
  1014. expect(roomspanel.createChatRoom).toHaveBeenCalled();
  1015. });
  1016. waits('250');
  1017. runs($.proxy(function () {
  1018. expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
  1019. }, converse));
  1020. }, converse));
  1021. }, converse));
  1022. }, converse, mock, test_utils));
  1023. }));