From da095caa38a09d729f407d7693b4b801d4007f6b Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 17 Apr 2013 00:09:16 +0200 Subject: [PATCH] Finish the test for receiving messages. --- spec/MainSpec.js | 100 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 29 deletions(-) diff --git a/spec/MainSpec.js b/spec/MainSpec.js index 639294eb3..168b17c13 100644 --- a/spec/MainSpec.js +++ b/spec/MainSpec.js @@ -45,8 +45,15 @@ 'subscribe': function () {}, 'registerCallback': function () {} }, - 'vcard': { - 'get': function () {} + 'vcard': { + 'get': function (callback, jid) { + var name = jid.split('@')[0].replace('.', ' ').split(' '); + var firstname = name[0].charAt(0).toUpperCase()+name[0].slice(1); + var lastname = name[1].charAt(0).toUpperCase()+name[1].slice(1); + var fullname = firstname+' '+lastname; + var vcard = $iq().c('vCard').c('FN').t(fullname); + callback(vcard.tree()); + } } }; @@ -57,6 +64,8 @@ hex_sha1('converse.chatboxes-'+this.bare_jid)); window.localStorage.removeItem( hex_sha1('converse.xmppstatus-'+this.bare_jid)); + window.localStorage.removeItem( + hex_sha1('converse.messages'+cur_names[0].replace(' ','.').toLowerCase() + '@localhost')); this.prebind = true; this.onConnected(mock_connection); @@ -392,29 +401,30 @@ }, xmppchat)); it("can be saved to, and retrieved from, localStorage", $.proxy(function () { - var old_chatboxes = this.chatboxes; - expect(this.chatboxes.length).toEqual(6); - this.chatboxes = new this.ChatBoxes(); - expect(this.chatboxes.length).toEqual(0); - - this.chatboxes.onConnected(); - expect(this.chatboxes.length).toEqual(6); - + // We instantiate a new ChatBoxes collection, which by default + // will be empty. + this.newchatboxes = new this.ChatBoxes(); + expect(this.newchatboxes.length).toEqual(0); + // The chatboxes will then be fetched from localStorage inside the + // onConnected method + this.newchatboxes.onConnected(); + expect(this.newchatboxes.length).toEqual(6); // Check that the roster items retrieved from localStorage // have the same attributes values as the original ones. attrs = ['id', 'box_id', 'visible']; for (i=0; i