MainSpec.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. (function (root, factory) {
  2. define([
  3. "converse"
  4. ], function (xmppchat) {
  5. return factory(xmppchat);
  6. }
  7. );
  8. } (this, function (xmppchat) {
  9. return describe("Converse.js", $.proxy(function() {
  10. // Names from http://www.fakenamegenerator.com/
  11. var req_names = [
  12. 'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer'
  13. ];
  14. var pend_names = [
  15. 'Suleyman van Beusichem', 'Nicole Diederich', 'Nanja van Yperen'
  16. ];
  17. var cur_names = [
  18. 'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
  19. 'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
  20. 'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
  21. ];
  22. var num_contacts = req_names.length + pend_names.length + cur_names.length;
  23. this.bare_jid = 'dummy@localhost';
  24. mock_connection = {
  25. 'muc': {
  26. 'listRooms': function () {}
  27. },
  28. 'jid': this.bare_jid,
  29. 'addHandler': function (handler, ns, name, type, id, from, options) {
  30. return function () {};
  31. },
  32. 'send': function () {},
  33. 'roster': {
  34. 'add': function () {},
  35. 'authorize': function () {},
  36. 'unauthorize': function () {},
  37. 'get': function () {},
  38. 'subscribe': function () {},
  39. 'registerCallback': function () {}
  40. },
  41. 'vcard': {
  42. 'get': function (callback, jid) {
  43. var name = jid.split('@')[0].replace('.', ' ').split(' ');
  44. var firstname = name[0].charAt(0).toUpperCase()+name[0].slice(1);
  45. var lastname = name[1].charAt(0).toUpperCase()+name[1].slice(1);
  46. var fullname = firstname+' '+lastname;
  47. var vcard = $iq().c('vCard').c('FN').t(fullname);
  48. callback(vcard.tree());
  49. }
  50. }
  51. };
  52. // Clear localStorage
  53. window.localStorage.clear();
  54. this.prebind = true;
  55. this.onConnected(mock_connection);
  56. this.animate = false; // don't use animations
  57. describe("The Control Box", $.proxy(function () {
  58. it("is not shown by default", $.proxy(function () {
  59. expect(this.rosterview.$el.is(':visible')).toEqual(false);
  60. }, xmppchat));
  61. it("can be opened by clicking a DOM element with id 'toggle-online-users'", $.proxy(function () {
  62. spyOn(this, 'toggleControlBox').andCallThrough();
  63. $('#toggle-online-users').click();
  64. expect(this.toggleControlBox).toHaveBeenCalled();
  65. }, xmppchat));
  66. describe("The Status Widget", $.proxy(function () {
  67. it("can be used to set the current user's chat status", $.proxy(function () {
  68. var view = this.xmppstatusview;
  69. spyOn(view, 'toggleOptions').andCallThrough();
  70. spyOn(view, 'setStatus').andCallThrough();
  71. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  72. view.$el.find('a.choose-xmpp-status').click();
  73. expect(view.toggleOptions).toHaveBeenCalled();
  74. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false);
  75. runs(function () {
  76. spyOn(view, 'updateStatusUI').andCallThrough();
  77. view.initialize(); // Rebind events for spy
  78. view.$el.find('.dropdown dd ul li a').first().click();
  79. expect(view.setStatus).toHaveBeenCalled();
  80. });
  81. waits(100);
  82. runs($.proxy(function () {
  83. expect(view.updateStatusUI).toHaveBeenCalled();
  84. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  85. expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe('I am online');
  86. }, xmppchat));
  87. }, xmppchat));
  88. it("can be used to set a custom status message", $.proxy(function () {
  89. var view = this.xmppstatusview;
  90. spyOn(view, 'setStatusMessage').andCallThrough();
  91. spyOn(view, 'renderStatusChangeForm').andCallThrough();
  92. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  93. runs(function () {
  94. view.$el.find('a.change-xmpp-status-message').click();
  95. expect(view.renderStatusChangeForm).toHaveBeenCalled();
  96. });
  97. waits(250);
  98. runs(function () {
  99. var msg = 'I am happy';
  100. view.$el.find('form input.custom-xmpp-status').val(msg);
  101. view.$el.find('form#set-custom-xmpp-status').submit();
  102. expect(view.setStatusMessage).toHaveBeenCalled();
  103. expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
  104. expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe(msg);
  105. });
  106. }, xmppchat));
  107. }, xmppchat));
  108. }, xmppchat));
  109. describe("The Contacts Roster", $.proxy(function () {
  110. describe("Pending Contacts", $.proxy(function () {
  111. it("do not have a heading if there aren't any", $.proxy(function () {
  112. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
  113. }, xmppchat));
  114. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  115. var i, t, is_last;
  116. spyOn(this.rosterview, 'render').andCallThrough();
  117. for (i=0; i<pend_names.length; i++) {
  118. is_last = i==(pend_names.length-1);
  119. this.roster.create({
  120. jid: pend_names[i].replace(' ','.').toLowerCase() + '@localhost',
  121. subscription: 'none',
  122. ask: 'subscribe',
  123. fullname: pend_names[i],
  124. is_last: is_last
  125. });
  126. // For performance reasons, the roster should only be shown once
  127. // the last contact has been added.
  128. if (is_last) {
  129. expect(this.rosterview.$el.is(':visible')).toEqual(true);
  130. } else {
  131. expect(this.rosterview.$el.is(':visible')).toEqual(false);
  132. }
  133. expect(this.rosterview.render).toHaveBeenCalled();
  134. // Check that they are sorted alphabetically
  135. t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
  136. expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
  137. }
  138. }, xmppchat));
  139. it("will have their own heading once they have been added", $.proxy(function () {
  140. expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
  141. }, xmppchat));
  142. }, xmppchat));
  143. describe("Existing Contacts", $.proxy(function () {
  144. it("do not have a heading if there aren't any", $.proxy(function () {
  145. expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
  146. }, xmppchat));
  147. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  148. var i, t;
  149. spyOn(this.rosterview, 'render').andCallThrough();
  150. for (i=0; i<cur_names.length; i++) {
  151. this.roster.create({
  152. jid: cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
  153. subscription: 'both',
  154. ask: null,
  155. fullname: cur_names[i],
  156. is_last: i==(cur_names.length-1)
  157. });
  158. expect(this.rosterview.render).toHaveBeenCalled();
  159. // Check that they are sorted alphabetically
  160. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
  161. expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
  162. }
  163. }, xmppchat));
  164. it("will have their own heading once they have been added", $.proxy(function () {
  165. expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
  166. }, xmppchat));
  167. it("can change their status to online and be sorted alphabetically", $.proxy(function () {
  168. var item, view, jid, t;
  169. spyOn(this.rosterview, 'render').andCallThrough();
  170. for (i=0; i<3; i++) {
  171. jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  172. view = this.rosterview.rosteritemviews[jid];
  173. spyOn(view, 'render').andCallThrough();
  174. item = view.model;
  175. item.set('chat_status', 'online');
  176. expect(view.render).toHaveBeenCalled();
  177. expect(this.rosterview.render).toHaveBeenCalled();
  178. // Check that they are sorted alphabetically
  179. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
  180. expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
  181. }
  182. }, xmppchat));
  183. it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
  184. var item, view, jid, t;
  185. spyOn(this.rosterview, 'render').andCallThrough();
  186. for (i=3; i<6; i++) {
  187. jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  188. view = this.rosterview.rosteritemviews[jid];
  189. spyOn(view, 'render').andCallThrough();
  190. item = view.model;
  191. item.set('chat_status', 'dnd');
  192. expect(view.render).toHaveBeenCalled();
  193. expect(this.rosterview.render).toHaveBeenCalled();
  194. // Check that they are sorted alphabetically
  195. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
  196. expect(t).toEqual(cur_names.slice(3,i+1).sort().join(''));
  197. }
  198. }, xmppchat));
  199. it("can change their status to away and be sorted alphabetically", $.proxy(function () {
  200. var item, view, jid, t;
  201. spyOn(this.rosterview, 'render').andCallThrough();
  202. for (i=6; i<9; i++) {
  203. jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  204. view = this.rosterview.rosteritemviews[jid];
  205. spyOn(view, 'render').andCallThrough();
  206. item = view.model;
  207. item.set('chat_status', 'away');
  208. expect(view.render).toHaveBeenCalled();
  209. expect(this.rosterview.render).toHaveBeenCalled();
  210. // Check that they are sorted alphabetically
  211. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
  212. expect(t).toEqual(cur_names.slice(6,i+1).sort().join(''));
  213. }
  214. }, xmppchat));
  215. it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
  216. var item, view, jid, t;
  217. spyOn(this.rosterview, 'render').andCallThrough();
  218. for (i=9; i<12; i++) {
  219. jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  220. view = this.rosterview.rosteritemviews[jid];
  221. spyOn(view, 'render').andCallThrough();
  222. item = view.model;
  223. item.set('chat_status', 'unavailable');
  224. expect(view.render).toHaveBeenCalled();
  225. expect(this.rosterview.render).toHaveBeenCalled();
  226. // Check that they are sorted alphabetically
  227. t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
  228. expect(t).toEqual(cur_names.slice(9, i+1).sort().join(''));
  229. }
  230. }, xmppchat));
  231. it("are ordered according to status: online, busy, away, unavailable, offline", $.proxy(function () {
  232. var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
  233. var i;
  234. // The first five contacts are online.
  235. for (i=0; i<3; i++) {
  236. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
  237. }
  238. // The next five are busy
  239. for (i=3; i<6; i++) {
  240. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
  241. }
  242. // The next five are away
  243. for (i=6; i<9; i++) {
  244. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
  245. }
  246. // The next five are unavailable
  247. for (i=9; i<12; i++) {
  248. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
  249. }
  250. // The next 20 are offline
  251. for (i=12; i<cur_names.length; i++) {
  252. expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
  253. }
  254. }, xmppchat));
  255. }, xmppchat));
  256. describe("Requesting Contacts", $.proxy(function () {
  257. // by default the dts are hidden from css class and only later they will be hidden
  258. // by jQuery therefore for the first check we will see if visible instead of none
  259. it("do not have a heading if there aren't any", $.proxy(function () {
  260. expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
  261. }, xmppchat));
  262. it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
  263. var i, t;
  264. spyOn(this.rosterview, 'render').andCallThrough();
  265. spyOn(this, 'showControlBox').andCallThrough();
  266. for (i=0; i<req_names.length; i++) {
  267. this.roster.create({
  268. jid: req_names[i].replace(' ','.').toLowerCase() + '@localhost',
  269. subscription: 'none',
  270. ask: 'request',
  271. fullname: req_names[i],
  272. is_last: i==(req_names.length-1)
  273. });
  274. expect(this.rosterview.render).toHaveBeenCalled();
  275. // Check that they are sorted alphabetically
  276. t = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').text().replace(/AcceptDecline/g, '');
  277. expect(t).toEqual(req_names.slice(0,i+1).sort().join(''));
  278. // When a requesting contact is added, the controlbox must
  279. // be opened.
  280. expect(this.showControlBox).toHaveBeenCalled();
  281. }
  282. }, xmppchat));
  283. it("will have their own heading once they have been added", $.proxy(function () {
  284. expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
  285. }, xmppchat));
  286. it("can have their requests accepted by the user", $.proxy(function () {
  287. // TODO: Testing can be more thorough here, the user is
  288. // actually not accepted/authorized because of
  289. // mock_connection.
  290. var jid = req_names.sort()[0].replace(' ','.').toLowerCase() + '@localhost';
  291. var view = this.rosterview.rosteritemviews[jid];
  292. spyOn(this.connection.roster, 'authorize');
  293. spyOn(view, 'acceptRequest').andCallThrough();
  294. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  295. var accept_button = view.$el.find('.accept-xmpp-request');
  296. accept_button.click();
  297. expect(view.acceptRequest).toHaveBeenCalled();
  298. expect(this.connection.roster.authorize).toHaveBeenCalled();
  299. }, xmppchat));
  300. it("can have their requests denied by the user", $.proxy(function () {
  301. var jid = req_names.sort()[1].replace(' ','.').toLowerCase() + '@localhost';
  302. var view = this.rosterview.rosteritemviews[jid];
  303. spyOn(this.connection.roster, 'unauthorize');
  304. spyOn(this.rosterview, 'removeRosterItem').andCallThrough();
  305. spyOn(view, 'declineRequest').andCallThrough();
  306. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  307. var accept_button = view.$el.find('.decline-xmpp-request');
  308. accept_button.click();
  309. expect(view.declineRequest).toHaveBeenCalled();
  310. expect(this.rosterview.removeRosterItem).toHaveBeenCalled();
  311. expect(this.connection.roster.unauthorize).toHaveBeenCalled();
  312. // There should now be one less contact
  313. expect(this.roster.length).toEqual(num_contacts-1);
  314. }, xmppchat));
  315. }, xmppchat));
  316. describe("All Contacts", $.proxy(function () {
  317. it("are saved to, and can be retrieved from, localStorage", $.proxy(function () {
  318. var new_attrs, old_attrs, attrs, old_roster;
  319. // One contact was declined, so we have 1 less contact then originally
  320. expect(this.roster.length).toEqual(num_contacts-1);
  321. new_roster = new this.RosterItems();
  322. // Roster items are yet to be fetched from localStorage
  323. expect(new_roster.length).toEqual(0);
  324. new_roster.localStorage = new Backbone.LocalStorage(
  325. hex_sha1('converse.rosteritems-dummy@localhost'));
  326. new_roster.fetch();
  327. expect(this.roster.length).toEqual(num_contacts-1);
  328. // Check that the roster items retrieved from localStorage
  329. // have the same attributes values as the original ones.
  330. attrs = ['jid', 'fullname', 'subscription', 'ask'];
  331. for (i=0; i<attrs.length; i++) {
  332. new_attrs = _.pluck(_.pluck(new_roster.models, 'attributes'), attrs[i]);
  333. old_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
  334. // Roster items in storage are not necessarily sorted,
  335. // so we have to sort them here to do a proper
  336. // comparison
  337. expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
  338. }
  339. this.rosterview.render();
  340. }, xmppchat));
  341. afterEach($.proxy(function () {
  342. // Contacts retrieved from localStorage have chat_status of
  343. // "offline".
  344. // In the next test suite, we need some online contacts, so
  345. // we make some online now
  346. for (i=0; i<5; i++) {
  347. jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
  348. view = this.rosterview.rosteritemviews[jid];
  349. view.model.set('chat_status', 'online');
  350. }
  351. }, xmppchat));
  352. }, xmppchat));
  353. }, xmppchat));
  354. describe("A Chatbox", $.proxy(function () {
  355. it("is created when you click on a roster item", $.proxy(function () {
  356. var i, $el, click, jid, view;
  357. // showControlBox was called earlier, so the controlbox is
  358. // visible, but no other chat boxes have been created.
  359. expect(this.chatboxes.length).toEqual(1);
  360. var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat');
  361. for (i=0; i<online_contacts.length; i++) {
  362. $el = $(online_contacts[i]);
  363. jid = $el.text().replace(' ','.').toLowerCase() + '@localhost';
  364. view = this.rosterview.rosteritemviews[jid];
  365. spyOn(view, 'openChat').andCallThrough();
  366. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  367. $el.click();
  368. expect(view.openChat).toHaveBeenCalled();
  369. expect(this.chatboxes.length).toEqual(i+2);
  370. }
  371. }, xmppchat));
  372. it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
  373. // We instantiate a new ChatBoxes collection, which by default
  374. // will be empty.
  375. this.newchatboxes = new this.ChatBoxes();
  376. expect(this.newchatboxes.length).toEqual(0);
  377. // The chatboxes will then be fetched from localStorage inside the
  378. // onConnected method
  379. this.newchatboxes.onConnected();
  380. expect(this.newchatboxes.length).toEqual(6);
  381. // Check that the roster items retrieved from localStorage
  382. // have the same attributes values as the original ones.
  383. attrs = ['id', 'box_id', 'visible'];
  384. for (i=0; i<attrs.length; i++) {
  385. new_attrs = _.pluck(_.pluck(this.newchatboxes.models, 'attributes'), attrs[i]);
  386. old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
  387. expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
  388. }
  389. this.rosterview.render();
  390. }, xmppchat));
  391. it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
  392. var chatbox, view, $el,
  393. num_open_chats = this.chatboxes.length;
  394. for (i=0; i<num_open_chats; i++) {
  395. chatbox = this.chatboxes.models[0];
  396. view = this.chatboxesview.views[chatbox.get('id')];
  397. spyOn(view, 'closeChat').andCallThrough();
  398. view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  399. view.$el.find('.close-chatbox-button').click();
  400. expect(view.closeChat).toHaveBeenCalled();
  401. }
  402. }, xmppchat));
  403. it("will be removed from localStorage when closed", $.proxy(function () {
  404. this.newchatboxes = new this.ChatBoxes();
  405. expect(this.newchatboxes.length).toEqual(0);
  406. // onConnected will fetch chatboxes in localStorage, but
  407. // because there aren't any open chatboxes, there won't be any
  408. // in localStorage either.
  409. this.chatboxes.onConnected();
  410. expect(this.chatboxes.length).toEqual(0);
  411. }, xmppchat));
  412. describe("A Chat Message", $.proxy(function () {
  413. it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
  414. var message = 'This is a received message';
  415. var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
  416. msg = $msg({
  417. from: sender_jid,
  418. to: this.bare_jid,
  419. type: 'chat',
  420. id: (new Date()).getTime()
  421. }).c('body').t(message).up()
  422. .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
  423. spyOn(this, 'getVCard').andCallThrough();
  424. // We don't already have an open chatbox for this user
  425. expect(this.chatboxes.get(sender_jid)).not.toBeDefined();
  426. runs($.proxy(function () {
  427. // messageReceived is a handler for received XMPP
  428. // messages
  429. this.chatboxes.messageReceived(msg);
  430. }, xmppchat));
  431. waits(500);
  432. runs($.proxy(function () {
  433. // Since we didn't already have an open chatbox, one
  434. // will asynchronously created inside a callback to
  435. // getVCard
  436. expect(this.getVCard).toHaveBeenCalled();
  437. // Check that the chatbox and its view now exist
  438. var chatbox = this.chatboxes.get(sender_jid);
  439. var chatboxview = this.chatboxesview.views[sender_jid];
  440. expect(chatbox).toBeDefined();
  441. expect(chatboxview).toBeDefined();
  442. // Check that the message was received and check the
  443. // message parameters
  444. expect(chatbox.messages.length).toEqual(1);
  445. var msg_obj = chatbox.messages.models[0];
  446. expect(msg_obj.get('message')).toEqual(message);
  447. // XXX: This is stupid, fullname is actually only the
  448. // users first name
  449. expect(msg_obj.get('fullname')).toEqual(cur_names[0].split(' ')[0]);
  450. expect(msg_obj.get('sender')).toEqual('them');
  451. expect(msg_obj.get('delayed')).toEqual(false);
  452. // Now check that the message appears inside the
  453. // chatbox in the DOM
  454. var txt = chatboxview.$el.find('.chat-content').find('.chat-message').find('.chat-message-content').text();
  455. expect(txt).toEqual(message);
  456. }, xmppchat));
  457. }, xmppchat));
  458. it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
  459. var contact_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
  460. var view = this.chatboxesview.views[contact_jid];
  461. var message = 'This message is sent from this chatbox';
  462. spyOn(view, 'sendMessage').andCallThrough();
  463. view.$el.find('.chat-textarea').text(message);
  464. view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
  465. expect(view.sendMessage).toHaveBeenCalled();
  466. expect(view.model.messages.length, 2);
  467. var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text();
  468. expect(txt).toEqual(message);
  469. }, xmppchat));
  470. }, xmppchat));
  471. }, xmppchat));
  472. }, xmppchat));
  473. }));