controlbox.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. runs($.proxy(function () {
  417. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  418. expect(this.rosterview.update).toHaveBeenCalled();
  419. }, converse));
  420. waits(300); // Needed, due to debounce
  421. runs ($.proxy(function () {
  422. expect(this.rosterview.$el.find('dd:visible').length).toBe(3);
  423. expect(this.rosterview.$el.find('dt:visible').length).toBe(1);
  424. }, converse));
  425. converse.hide_offline_users = false;
  426. }, converse));
  427. it("can be removed by the user", $.proxy(function () {
  428. runs($.proxy(function () {
  429. _addContacts();
  430. }, this));
  431. waits(50);
  432. runs($.proxy(function () {
  433. /* FIXME: Monkepatch
  434. * After refactoring the mock connection to use a
  435. * Strophe.Connection object, these tests fail because "remove"
  436. * function in strophe.roster (line 292) gets called and it
  437. * then tries to actually remove the user which is not in the roster...
  438. */
  439. var old_remove = this.connection.roster.remove;
  440. this.connection.roster.remove = function (jid, callback) { callback(); };
  441. var name = mock.pend_names[0];
  442. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  443. spyOn(window, 'confirm').andReturn(true);
  444. spyOn(converse, 'emit');
  445. spyOn(this.connection.roster, 'remove').andCallThrough();
  446. spyOn(this.connection.roster, 'unauthorize');
  447. spyOn(this.rosterview.model, 'remove').andCallThrough();
  448. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  449. .siblings('.remove-xmpp-contact').click();
  450. expect(window.confirm).toHaveBeenCalled();
  451. expect(this.connection.roster.remove).toHaveBeenCalled();
  452. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  453. expect(this.rosterview.model.remove).toHaveBeenCalled();
  454. expect(converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')").length).toEqual(0);
  455. /* XXX Restore Monkeypatch */
  456. this.connection.roster.remove = old_remove;
  457. }, this));
  458. }, converse));
  459. it("do not have a header if there aren't any", $.proxy(function () {
  460. var name = mock.pend_names[0];
  461. runs($.proxy(function () {
  462. _clearContacts();
  463. }, this));
  464. waits(50);
  465. runs($.proxy(function () {
  466. spyOn(window, 'confirm').andReturn(true);
  467. this.roster.create({
  468. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  469. subscription: 'none',
  470. ask: 'subscribe',
  471. fullname: name
  472. });
  473. expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(true);
  474. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  475. .siblings('.remove-xmpp-contact').click();
  476. expect(window.confirm).toHaveBeenCalled();
  477. expect(this.rosterview.get('Pending contacts').$el.is(':visible')).toEqual(false);
  478. }, this));
  479. }, converse));
  480. it("will lose their own header once the last one has been removed", $.proxy(function () {
  481. _addContacts();
  482. var name;
  483. spyOn(window, 'confirm').andReturn(true);
  484. for (i=0; i<mock.pend_names.length; i++) {
  485. name = mock.pend_names[i];
  486. converse.rosterview.$el.find(".pending-contact-name:contains('"+name+"')")
  487. .siblings('.remove-xmpp-contact').click();
  488. }
  489. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy();
  490. }, converse));
  491. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  492. _clearContacts();
  493. var i, t;
  494. spyOn(converse, 'emit');
  495. spyOn(this.rosterview, 'update').andCallThrough();
  496. for (i=0; i<mock.pend_names.length; i++) {
  497. this.roster.create({
  498. jid: mock.pend_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  499. subscription: 'none',
  500. ask: 'subscribe',
  501. fullname: mock.pend_names[i]
  502. });
  503. expect(this.rosterview.update).toHaveBeenCalled();
  504. }
  505. // Check that they are sorted alphabetically
  506. t = this.rosterview.get('Pending contacts').$el.siblings('dd.pending-xmpp-contact').find('span').text();
  507. expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join(''));
  508. }, converse));
  509. }, converse));
  510. describe("Existing Contacts", $.proxy(function () {
  511. function _clearContacts () {
  512. utils.clearBrowserStorage();
  513. converse.rosterview.model.reset();
  514. }
  515. var _addContacts = function () {
  516. _clearContacts();
  517. utils.createContacts('current').openControlBox().openContactsPanel();
  518. };
  519. it("can be collapsed under their own header", $.proxy(function () {
  520. runs(function () {
  521. _addContacts();
  522. });
  523. waits(50);
  524. runs($.proxy(function () {
  525. checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt.roster-group')]);
  526. }, this));
  527. }, converse));
  528. it("will be hidden when appearing under a collapsed group", $.proxy(function () {
  529. _addContacts();
  530. this.rosterview.$el.find('dt.roster-group').find('a.group-toggle').click();
  531. var name = "Max Mustermann";
  532. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  533. converse.roster.create({
  534. ask: null,
  535. fullname: name,
  536. jid: jid,
  537. requesting: false,
  538. subscription: 'both'
  539. });
  540. var view = this.rosterview.get('My contacts').get(jid);
  541. expect(view.$el.is(':visible')).toBe(false);
  542. }, converse));
  543. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  544. runs(function () {
  545. _clearContacts();
  546. });
  547. waits(50);
  548. runs($.proxy(function () {
  549. var i, t;
  550. spyOn(converse, 'emit');
  551. spyOn(this.rosterview, 'update').andCallThrough();
  552. for (i=0; i<mock.cur_names.length; i++) {
  553. this.roster.create({
  554. jid: mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  555. subscription: 'both',
  556. ask: null,
  557. fullname: mock.cur_names[i]
  558. });
  559. expect(this.rosterview.update).toHaveBeenCalled();
  560. }
  561. // Check that they are sorted alphabetically
  562. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
  563. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  564. }, this));
  565. }, converse));
  566. it("can be removed by the user", $.proxy(function () {
  567. runs(function () {
  568. _addContacts();
  569. });
  570. waits(50);
  571. runs($.proxy(function () {
  572. /* FIXME: Monkepatch
  573. * After refactoring the mock connection to use a
  574. * Strophe.Connection object, these tests fail because "remove"
  575. * function in strophe.roster (line 292) gets called and it
  576. * then tries to actually remove the user which is not in the roster...
  577. */
  578. var old_remove = this.connection.roster.remove;
  579. this.connection.roster.remove = function (jid, callback) { callback(); };
  580. var name = mock.cur_names[0];
  581. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  582. spyOn(window, 'confirm').andReturn(true);
  583. spyOn(converse, 'emit');
  584. spyOn(this.connection.roster, 'remove').andCallThrough();
  585. spyOn(this.connection.roster, 'unauthorize');
  586. spyOn(this.rosterview.model, 'remove').andCallThrough();
  587. converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
  588. .siblings('.remove-xmpp-contact').click();
  589. expect(window.confirm).toHaveBeenCalled();
  590. expect(this.connection.roster.remove).toHaveBeenCalled();
  591. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  592. expect(this.rosterview.model.remove).toHaveBeenCalled();
  593. expect(converse.rosterview.$el.find(".open-chat:contains('"+name+"')").length).toEqual(0);
  594. /* XXX Restore Monkeypatch */
  595. this.connection.roster.remove = old_remove;
  596. }, this));
  597. }, converse));
  598. it("do not have a header if there aren't any", $.proxy(function () {
  599. var name = mock.cur_names[0];
  600. runs(function () {
  601. _clearContacts();
  602. });
  603. waits(50);
  604. runs($.proxy(function () {
  605. spyOn(window, 'confirm').andReturn(true);
  606. this.roster.create({
  607. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  608. subscription: 'both',
  609. ask: null,
  610. fullname: name
  611. });
  612. expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('block');
  613. converse.rosterview.$el.find(".open-chat:contains('"+name+"')")
  614. .siblings('.remove-xmpp-contact').click();
  615. expect(window.confirm).toHaveBeenCalled();
  616. expect(this.rosterview.$el.find('dt.roster-group').css('display')).toEqual('none');
  617. }, this));
  618. }, converse));
  619. it("can change their status to online and be sorted alphabetically", $.proxy(function () {
  620. runs(function () {
  621. _addContacts();
  622. });
  623. waits(50);
  624. runs($.proxy(function () {
  625. var jid, t;
  626. spyOn(converse, 'emit');
  627. spyOn(this.rosterview, 'update').andCallThrough();
  628. for (i=0; i<mock.cur_names.length; i++) {
  629. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  630. this.roster.get(jid).set('chat_status', 'online');
  631. expect(this.rosterview.update).toHaveBeenCalled();
  632. // Check that they are sorted alphabetically
  633. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
  634. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  635. }
  636. }, this));
  637. }, converse));
  638. it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
  639. runs(function () {
  640. _addContacts();
  641. });
  642. waits(50);
  643. runs($.proxy(function () {
  644. var jid, t;
  645. spyOn(converse, 'emit');
  646. spyOn(this.rosterview, 'update').andCallThrough();
  647. for (i=0; i<mock.cur_names.length; i++) {
  648. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  649. this.roster.get(jid).set('chat_status', 'dnd');
  650. expect(this.rosterview.update).toHaveBeenCalled();
  651. // Check that they are sorted alphabetically
  652. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
  653. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  654. }
  655. }, this));
  656. }, converse));
  657. it("can change their status to away and be sorted alphabetically", $.proxy(function () {
  658. runs(function () {
  659. _addContacts();
  660. });
  661. waits(50);
  662. runs($.proxy(function () {
  663. var jid, t;
  664. spyOn(converse, 'emit');
  665. spyOn(this.rosterview, 'update').andCallThrough();
  666. for (i=0; i<mock.cur_names.length; i++) {
  667. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  668. this.roster.get(jid).set('chat_status', 'away');
  669. expect(this.rosterview.update).toHaveBeenCalled();
  670. // Check that they are sorted alphabetically
  671. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
  672. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  673. }
  674. }, this));
  675. }, converse));
  676. it("can change their status to xa and be sorted alphabetically", $.proxy(function () {
  677. runs(function () {
  678. _addContacts();
  679. });
  680. waits(50);
  681. runs($.proxy(function () {
  682. var jid, t;
  683. spyOn(converse, 'emit');
  684. spyOn(this.rosterview, 'update').andCallThrough();
  685. for (i=0; i<mock.cur_names.length; i++) {
  686. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  687. this.roster.get(jid).set('chat_status', 'xa');
  688. expect(this.rosterview.update).toHaveBeenCalled();
  689. // Check that they are sorted alphabetically
  690. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.xa').find('a.open-chat').text();
  691. expect(t).toEqual(mock.cur_names.slice(0,i+1).sort().join(''));
  692. }
  693. }, this));
  694. }, converse));
  695. it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
  696. runs(function () {
  697. _addContacts();
  698. });
  699. waits(50);
  700. runs($.proxy(function () {
  701. var jid, t;
  702. spyOn(converse, 'emit');
  703. spyOn(this.rosterview, 'update').andCallThrough();
  704. for (i=0; i<mock.cur_names.length; i++) {
  705. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  706. this.roster.get(jid).set('chat_status', 'unavailable');
  707. expect(this.rosterview.update).toHaveBeenCalled();
  708. // Check that they are sorted alphabetically
  709. t = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
  710. expect(t).toEqual(mock.cur_names.slice(0, i+1).sort().join(''));
  711. }
  712. }, this));
  713. }, converse));
  714. it("are ordered according to status: online, busy, away, xa, unavailable, offline", $.proxy(function () {
  715. runs(function () {
  716. _addContacts();
  717. });
  718. waits(50);
  719. runs($.proxy(function () {
  720. var i;
  721. for (i=0; i<3; i++) {
  722. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  723. this.roster.get(jid).set('chat_status', 'online');
  724. }
  725. for (i=3; i<6; i++) {
  726. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  727. this.roster.get(jid).set('chat_status', 'dnd');
  728. }
  729. for (i=6; i<9; i++) {
  730. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  731. this.roster.get(jid).set('chat_status', 'away');
  732. }
  733. for (i=9; i<12; i++) {
  734. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  735. this.roster.get(jid).set('chat_status', 'xa');
  736. }
  737. for (i=12; i<15; i++) {
  738. jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
  739. this.roster.get(jid).set('chat_status', 'unavailable');
  740. }
  741. var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
  742. for (i=0; i<3; i++) {
  743. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
  744. }
  745. for (i=3; i<6; i++) {
  746. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
  747. }
  748. for (i=6; i<9; i++) {
  749. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
  750. }
  751. for (i=9; i<12; i++) {
  752. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('xa');
  753. }
  754. for (i=12; i<15; i++) {
  755. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
  756. }
  757. for (i=15; i<mock.cur_names.length; i++) {
  758. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
  759. }
  760. }, this));
  761. }, converse));
  762. }, converse));
  763. describe("Requesting Contacts", $.proxy(function () {
  764. beforeEach($.proxy(function () {
  765. runs(function () {
  766. utils.clearBrowserStorage();
  767. converse.rosterview.model.reset();
  768. utils.createContacts('requesting').openControlBox();
  769. });
  770. waits(50);
  771. runs(function () {
  772. utils.openContactsPanel();
  773. });
  774. }, converse));
  775. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  776. converse.rosterview.model.reset(); // We want to manually create users so that we can spy
  777. var i, children;
  778. var names = [];
  779. spyOn(converse, 'emit');
  780. spyOn(this.rosterview, 'update').andCallThrough();
  781. spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
  782. var addName = function (idx, item) {
  783. if (!$(item).hasClass('request-actions')) {
  784. names.push($(item).text().replace(/^\s+|\s+$/g, ''));
  785. }
  786. };
  787. for (i=0; i<mock.req_names.length; i++) {
  788. this.roster.create({
  789. jid: mock.req_names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
  790. subscription: 'none',
  791. ask: null,
  792. requesting: true,
  793. fullname: mock.req_names[i]
  794. });
  795. expect(this.rosterview.update).toHaveBeenCalled();
  796. // When a requesting contact is added, the controlbox must
  797. // be opened.
  798. expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
  799. }
  800. // Check that they are sorted alphabetically
  801. children = this.rosterview.get('Contact requests').$el.siblings('dd.requesting-xmpp-contact').children('span');
  802. names = [];
  803. children.each(addName);
  804. expect(names.join('')).toEqual(mock.req_names.slice(0,i+1).sort().join(''));
  805. }, converse));
  806. it("do not have a header if there aren't any", $.proxy(function () {
  807. converse.rosterview.model.reset(); // We want to manually create users so that we can spy
  808. var name = mock.req_names[0];
  809. runs($.proxy(function () {
  810. spyOn(window, 'confirm').andReturn(true);
  811. this.roster.create({
  812. jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
  813. subscription: 'none',
  814. ask: null,
  815. requesting: true,
  816. fullname: name
  817. });
  818. }, this));
  819. waits(50);
  820. runs($.proxy(function () {
  821. expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(true);
  822. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  823. .siblings('.request-actions')
  824. .find('.decline-xmpp-request').click();
  825. expect(window.confirm).toHaveBeenCalled();
  826. expect(this.rosterview.get('Contact requests').$el.is(':visible')).toEqual(false);
  827. }, this));
  828. }, converse));
  829. it("can be collapsed under their own header", $.proxy(function () {
  830. checkHeaderToggling.apply(this, [this.rosterview.get('Contact requests').$el]);
  831. }, converse));
  832. it("can have their requests accepted by the user", $.proxy(function () {
  833. // TODO: Testing can be more thorough here, the user is
  834. // actually not accepted/authorized because of
  835. // mock_connection.
  836. var name = mock.req_names.sort()[0];
  837. var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  838. spyOn(this.connection.roster, 'authorize');
  839. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  840. .siblings('.request-actions')
  841. .find('.accept-xmpp-request').click();
  842. expect(this.connection.roster.authorize).toHaveBeenCalled();
  843. }, converse));
  844. it("can have their requests denied by the user", $.proxy(function () {
  845. this.rosterview.model.reset();
  846. runs($.proxy(function () {
  847. spyOn(converse, 'emit');
  848. spyOn(this.connection.roster, 'unauthorize');
  849. spyOn(window, 'confirm').andReturn(true);
  850. utils.createContacts('requesting').openControlBox();
  851. converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
  852. }, this));
  853. waits(50);
  854. runs($.proxy(function () {
  855. var name = mock.req_names.sort()[1];
  856. converse.rosterview.$el.find(".req-contact-name:contains('"+name+"')")
  857. .siblings('.request-actions')
  858. .find('.decline-xmpp-request').click();
  859. }, this));
  860. waits(50);
  861. runs($.proxy(function () {
  862. expect(window.confirm).toHaveBeenCalled();
  863. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  864. // There should now be one less contact
  865. expect(this.roster.length).toEqual(mock.req_names.length-1);
  866. }, this));
  867. }, converse));
  868. it("are persisted even if other contacts' change their presence ", $.proxy(function() {
  869. /* This is a regression test.
  870. * https://github.com/jcbrand/converse.js/issues/262
  871. */
  872. this.rosterview.model.reset();
  873. spyOn(this.roster, 'clearCache').andCallThrough();
  874. expect(this.roster.pluck('jid').length).toBe(0);
  875. var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
  876. this.connection._dataRecv(test_utils.createRequest(stanza));
  877. expect(this.roster.pluck('jid').length).toBe(1);
  878. expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
  879. // Taken from the spec
  880. // http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
  881. stanza = $iq({
  882. to: this.connection.jid,
  883. type: 'result',
  884. id: 'roster_1'
  885. }).c('query', {
  886. xmlns: 'jabber:iq:roster',
  887. }).c('item', {
  888. jid: 'romeo@example.net',
  889. name: 'Romeo',
  890. subscription:'both'
  891. }).c('group').t('Friends').up().up()
  892. .c('item', {
  893. jid: 'mercutio@example.org',
  894. name: 'Mercutio',
  895. subscription:'from'
  896. }).c('group').t('Friends').up().up()
  897. .c('item', {
  898. jid: 'benvolio@example.org',
  899. name: 'Benvolio',
  900. subscription:'both'
  901. }).c('group').t('Friends');
  902. this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
  903. expect(this.roster.clearCache).toHaveBeenCalled();
  904. expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
  905. }, converse));
  906. }, converse));
  907. describe("All Contacts", $.proxy(function () {
  908. beforeEach($.proxy(function () {
  909. runs(function () {
  910. utils.clearBrowserStorage();
  911. converse.rosterview.model.reset();
  912. utils.createContacts('all').openControlBox();
  913. });
  914. waits(50);
  915. runs(function () {
  916. utils.openContactsPanel();
  917. });
  918. }, converse));
  919. it("are saved to, and can be retrieved from, browserStorage", $.proxy(function () {
  920. var new_attrs, old_attrs, attrs;
  921. var num_contacts = this.roster.length;
  922. new_roster = new this.RosterContacts();
  923. // Roster items are yet to be fetched from browserStorage
  924. expect(new_roster.length).toEqual(0);
  925. new_roster.browserStorage = this.roster.browserStorage;
  926. new_roster.fetch();
  927. expect(new_roster.length).toEqual(num_contacts);
  928. // Check that the roster items retrieved from browserStorage
  929. // have the same attributes values as the original ones.
  930. attrs = ['jid', 'fullname', 'subscription', 'ask'];
  931. for (i=0; i<attrs.length; i++) {
  932. new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
  933. old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
  934. // Roster items in storage are not necessarily sorted,
  935. // so we have to sort them here to do a proper
  936. // comparison
  937. expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
  938. }
  939. }, converse));
  940. it("will show fullname and jid properties on tooltip", $.proxy(function () {
  941. var jid, name, i, t;
  942. for (i=0; i<mock.cur_names.length; i++) {
  943. name = mock.cur_names[i];
  944. jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
  945. var $dd = this.rosterview.$el.find("dd:contains('"+name+"')").children().first();
  946. var dd_text = $dd.text();
  947. var dd_title = $dd.attr('title');
  948. expect(dd_text).toBe(name);
  949. expect(dd_title).toContain(name);
  950. expect(dd_title).toContain(jid);
  951. }
  952. }, converse));
  953. }, converse));
  954. }, converse, mock, test_utils));
  955. describe("The 'Add Contact' widget", $.proxy(function (mock, test_utils) {
  956. it("opens up an add form when you click on it", $.proxy(function () {
  957. var panel = this.chatboxviews.get('controlbox').contactspanel;
  958. spyOn(panel, 'toggleContactForm').andCallThrough();
  959. panel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  960. panel.$el.find('a.toggle-xmpp-contact-form').click();
  961. expect(panel.toggleContactForm).toHaveBeenCalled();
  962. // XXX: Awaiting more tests, close it again for now...
  963. panel.$el.find('a.toggle-xmpp-contact-form').click();
  964. }, converse));
  965. }, converse, mock, test_utils));
  966. describe("The Controlbox Tabs", $.proxy(function () {
  967. beforeEach($.proxy(function () {
  968. runs(function () {
  969. test_utils.closeAllChatBoxes();
  970. });
  971. waits(50);
  972. runs(function () {
  973. test_utils.openControlBox();
  974. });
  975. }, converse));
  976. it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
  977. var cbview = this.chatboxviews.get('controlbox');
  978. var $panels = cbview.$el.find('.controlbox-panes');
  979. expect($panels.children().length).toBe(2);
  980. expect($panels.children().first().attr('id')).toBe('users');
  981. expect($panels.children().first().is(':visible')).toBe(true);
  982. expect($panels.children().last().attr('id')).toBe('chatrooms');
  983. expect($panels.children().last().is(':visible')).toBe(false);
  984. }, converse));
  985. describe("chatrooms panel", $.proxy(function () {
  986. beforeEach($.proxy(function () {
  987. runs(function () {
  988. test_utils.closeAllChatBoxes();
  989. });
  990. waits(50);
  991. runs(function () {
  992. test_utils.openControlBox();
  993. });
  994. }, converse));
  995. it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
  996. var cbview = this.chatboxviews.get('controlbox');
  997. var $tabs = cbview.$el.find('#controlbox-tabs');
  998. var $panels = cbview.$el.find('.controlbox-panes');
  999. var $contacts = $panels.children().first();
  1000. var $chatrooms = $panels.children().last();
  1001. spyOn(cbview, 'switchTab').andCallThrough();
  1002. cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  1003. runs(function () {
  1004. $tabs.find('li').last().find('a').click(); // Clicks the chatrooms tab
  1005. });
  1006. waits(250);
  1007. runs(function () {
  1008. expect($contacts.is(':visible')).toBe(false);
  1009. expect($chatrooms.is(':visible')).toBe(true);
  1010. expect(cbview.switchTab).toHaveBeenCalled();
  1011. });
  1012. }, converse));
  1013. it("contains a form through which a new chatroom can be created", $.proxy(function () {
  1014. var roomspanel = this.chatboxviews.get('controlbox').roomspanel;
  1015. var $input = roomspanel.$el.find('input.new-chatroom-name');
  1016. var $nick = roomspanel.$el.find('input.new-chatroom-nick');
  1017. var $server = roomspanel.$el.find('input.new-chatroom-server');
  1018. expect($input.length).toBe(1);
  1019. expect($server.length).toBe(1);
  1020. expect($('.chatroom:visible').length).toBe(0); // There shouldn't be any chatrooms open currently
  1021. spyOn(roomspanel, 'createChatRoom').andCallThrough();
  1022. roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  1023. runs(function () {
  1024. $input.val('Lounge');
  1025. $nick.val('dummy');
  1026. $server.val('muc.localhost');
  1027. });
  1028. waits('250');
  1029. runs(function () {
  1030. roomspanel.$el.find('form').submit();
  1031. expect(roomspanel.createChatRoom).toHaveBeenCalled();
  1032. });
  1033. waits('250');
  1034. runs($.proxy(function () {
  1035. expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
  1036. }, converse));
  1037. }, converse));
  1038. }, converse));
  1039. }, converse, mock, test_utils));
  1040. }));