|
@@ -10,22 +10,15 @@
|
|
return describe("Converse.js", $.proxy(function() {
|
|
return describe("Converse.js", $.proxy(function() {
|
|
// Names from http://www.fakenamegenerator.com/
|
|
// Names from http://www.fakenamegenerator.com/
|
|
var req_names = [
|
|
var req_names = [
|
|
- 'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer', 'Dirk Eichel', 'Marco Duerr', 'Ute Schiffer',
|
|
|
|
- 'Billie Westerhuis', 'Sarah Kuester', 'Sabrina Loewe', 'Laura Duerr', 'Mathias Meyer',
|
|
|
|
- 'Tijm Keller', 'Lea Gerste', 'Martin Pfeffer', 'Ulrike Abt', 'Zoubida van Rooij',
|
|
|
|
- 'Maylin Hettema', 'Ruwan Bechan', 'Marco Beich', 'Karin Busch', 'Mathias Müller'
|
|
|
|
|
|
+ 'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer'
|
|
];
|
|
];
|
|
var pend_names = [
|
|
var pend_names = [
|
|
- 'Suleyman van Beusichem', 'Nicole Diederich', 'Nanja van Yperen', 'Delany Bloemendaal',
|
|
|
|
- 'Jannah Hofmeester', 'Christine Trommler', 'Martin Bumgarner', 'Emil Baeten', 'Farshad Brasser',
|
|
|
|
- 'Gabriele Fisher', 'Sofiane Schopman', 'Sky Wismans', 'Jeffery Stoelwinder', 'Ganesh Waaijenberg',
|
|
|
|
- 'Dani Boldewijn', 'Katrin Propst', 'Martina Kaiser', 'Philipp Kappel', 'Meeke Grootendorst'
|
|
|
|
|
|
+ 'Suleyman van Beusichem', 'Nicole Diederich', 'Nanja van Yperen'
|
|
];
|
|
];
|
|
var cur_names = [
|
|
var cur_names = [
|
|
'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
|
|
'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
|
|
'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
|
|
'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
|
|
- 'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers', 'Ben Zomer',
|
|
|
|
- 'Leah Weiss', 'Francesca Disseldorp', 'Sven Bumgarner', 'Benjamin Zweig'
|
|
|
|
|
|
+ 'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
|
|
];
|
|
];
|
|
var num_contacts = req_names.length + pend_names.length + cur_names.length;
|
|
var num_contacts = req_names.length + pend_names.length + cur_names.length;
|
|
this.bare_jid = 'dummy@localhost';
|
|
this.bare_jid = 'dummy@localhost';
|
|
@@ -44,6 +37,16 @@
|
|
'get': function () {},
|
|
'get': function () {},
|
|
'subscribe': function () {},
|
|
'subscribe': function () {},
|
|
'registerCallback': function () {}
|
|
'registerCallback': 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());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -54,24 +57,13 @@
|
|
hex_sha1('converse.chatboxes-'+this.bare_jid));
|
|
hex_sha1('converse.chatboxes-'+this.bare_jid));
|
|
window.localStorage.removeItem(
|
|
window.localStorage.removeItem(
|
|
hex_sha1('converse.xmppstatus-'+this.bare_jid));
|
|
hex_sha1('converse.xmppstatus-'+this.bare_jid));
|
|
|
|
+ window.localStorage.removeItem(
|
|
|
|
+ hex_sha1('converse.messages'+cur_names[0].replace(' ','.').toLowerCase() + '@localhost'));
|
|
|
|
|
|
this.prebind = true;
|
|
this.prebind = true;
|
|
this.onConnected(mock_connection);
|
|
this.onConnected(mock_connection);
|
|
this.animate = false; // don't use animations
|
|
this.animate = false; // don't use animations
|
|
|
|
|
|
- // The timeout is used to slow down the tests so that one can see
|
|
|
|
- // visually what is happening in the page.
|
|
|
|
- var timeout = 0;
|
|
|
|
- var sleep = function (delay) {
|
|
|
|
- // Yes this is blocking and stupid, but these are tests and this is
|
|
|
|
- // the easiest way to delay execution without having to use
|
|
|
|
- // callbacks.
|
|
|
|
- var start = new Date().getTime();
|
|
|
|
- while (new Date().getTime() < start + delay) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
describe("The Contacts Roster", $.proxy(function () {
|
|
describe("The Contacts Roster", $.proxy(function () {
|
|
it("is not shown by default", $.proxy(function () {
|
|
it("is not shown by default", $.proxy(function () {
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(false);
|
|
expect(this.rosterview.$el.is(':visible')).toEqual(false);
|
|
@@ -112,7 +104,6 @@
|
|
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
|
|
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
|
|
expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
|
|
expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
|
|
}
|
|
}
|
|
- sleep(timeout);
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
@@ -141,7 +132,6 @@
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
}
|
|
}
|
|
- sleep(timeout);
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
@@ -151,7 +141,7 @@
|
|
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
|
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
|
var item, view, jid, t;
|
|
var item, view, jid, t;
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
- for (i=0; i<5; i++) {
|
|
|
|
|
|
+ for (i=0; i<3; i++) {
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
spyOn(view, 'render').andCallThrough();
|
|
spyOn(view, 'render').andCallThrough();
|
|
@@ -163,14 +153,13 @@
|
|
// Check that they are sorted alphabetically
|
|
// Check that they are sorted alphabetically
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
|
|
- sleep(timeout);
|
|
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
|
|
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
|
|
var item, view, jid, t;
|
|
var item, view, jid, t;
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
- for (i=5; i<10; i++) {
|
|
|
|
|
|
+ for (i=3; i<6; i++) {
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
spyOn(view, 'render').andCallThrough();
|
|
spyOn(view, 'render').andCallThrough();
|
|
@@ -180,15 +169,14 @@
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
|
// Check that they are sorted alphabetically
|
|
// Check that they are sorted alphabetically
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
|
|
- expect(t).toEqual(cur_names.slice(5,i+1).sort().join(''));
|
|
|
|
- sleep(timeout);
|
|
|
|
|
|
+ expect(t).toEqual(cur_names.slice(3,i+1).sort().join(''));
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
|
|
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
|
|
var item, view, jid, t;
|
|
var item, view, jid, t;
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
- for (i=10; i<15; i++) {
|
|
|
|
|
|
+ for (i=6; i<9; i++) {
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
spyOn(view, 'render').andCallThrough();
|
|
spyOn(view, 'render').andCallThrough();
|
|
@@ -199,15 +187,14 @@
|
|
|
|
|
|
// Check that they are sorted alphabetically
|
|
// Check that they are sorted alphabetically
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
|
|
- expect(t).toEqual(cur_names.slice(10,i+1).sort().join(''));
|
|
|
|
- sleep(timeout);
|
|
|
|
|
|
+ expect(t).toEqual(cur_names.slice(6,i+1).sort().join(''));
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
|
|
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
|
|
var item, view, jid, t;
|
|
var item, view, jid, t;
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
|
- for (i=15; i<20; i++) {
|
|
|
|
|
|
+ for (i=9; i<12; i++) {
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
view = this.rosterview.rosteritemviews[jid];
|
|
spyOn(view, 'render').andCallThrough();
|
|
spyOn(view, 'render').andCallThrough();
|
|
@@ -218,8 +205,7 @@
|
|
|
|
|
|
// Check that they are sorted alphabetically
|
|
// Check that they are sorted alphabetically
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
|
|
- expect(t).toEqual(cur_names.slice(15, i+1).sort().join(''));
|
|
|
|
- sleep(timeout);
|
|
|
|
|
|
+ expect(t).toEqual(cur_names.slice(9, i+1).sort().join(''));
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
@@ -227,23 +213,23 @@
|
|
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
|
|
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
|
|
var i;
|
|
var i;
|
|
// The first five contacts are online.
|
|
// The first five contacts are online.
|
|
- for (i=0; i<5; i++) {
|
|
|
|
|
|
+ for (i=0; i<3; i++) {
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
|
|
}
|
|
}
|
|
// The next five are busy
|
|
// The next five are busy
|
|
- for (i=5; i<10; i++) {
|
|
|
|
|
|
+ for (i=3; i<6; i++) {
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
|
|
}
|
|
}
|
|
// The next five are away
|
|
// The next five are away
|
|
- for (i=10; i<15; i++) {
|
|
|
|
|
|
+ for (i=6; i<9; i++) {
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
|
|
}
|
|
}
|
|
// The next five are unavailable
|
|
// The next five are unavailable
|
|
- for (i=15; i<20; i++) {
|
|
|
|
|
|
+ for (i=9; i<12; i++) {
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
|
|
}
|
|
}
|
|
// The next 20 are offline
|
|
// The next 20 are offline
|
|
- for (i=20; i<cur_names.length; i++) {
|
|
|
|
|
|
+ for (i=12; i<cur_names.length; i++) {
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
@@ -278,7 +264,6 @@
|
|
// be opened.
|
|
// be opened.
|
|
expect(this.showControlBox).toHaveBeenCalled();
|
|
expect(this.showControlBox).toHaveBeenCalled();
|
|
}
|
|
}
|
|
- sleep(timeout);
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
it("will have their own heading once they have been added", $.proxy(function () {
|
|
@@ -298,7 +283,6 @@
|
|
accept_button.click();
|
|
accept_button.click();
|
|
expect(view.acceptRequest).toHaveBeenCalled();
|
|
expect(view.acceptRequest).toHaveBeenCalled();
|
|
expect(this.connection.roster.authorize).toHaveBeenCalled();
|
|
expect(this.connection.roster.authorize).toHaveBeenCalled();
|
|
- sleep(timeout);
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can have their requests denied by the user", $.proxy(function () {
|
|
it("can have their requests denied by the user", $.proxy(function () {
|
|
@@ -315,7 +299,6 @@
|
|
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
|
|
expect(this.connection.roster.unauthorize).toHaveBeenCalled();
|
|
// There should now be one less contact
|
|
// There should now be one less contact
|
|
expect(this.roster.length).toEqual(num_contacts-1);
|
|
expect(this.roster.length).toEqual(num_contacts-1);
|
|
- sleep(timeout);
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
@@ -366,9 +349,9 @@
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
- describe("Chatboxes", $.proxy(function () {
|
|
|
|
|
|
+ describe("A Chatbox", $.proxy(function () {
|
|
|
|
|
|
- it("are created when you click on a roster item", $.proxy(function () {
|
|
|
|
|
|
+ it("is created when you click on a roster item", $.proxy(function () {
|
|
var i, $el, click, jid, view;
|
|
var i, $el, click, jid, view;
|
|
// showControlBox was called earlier, so the controlbox is
|
|
// showControlBox was called earlier, so the controlbox is
|
|
// visible, but no other chat boxes have been created.
|
|
// visible, but no other chat boxes have been created.
|
|
@@ -384,52 +367,106 @@
|
|
$el.click();
|
|
$el.click();
|
|
expect(view.openChat).toHaveBeenCalled();
|
|
expect(view.openChat).toHaveBeenCalled();
|
|
expect(this.chatboxes.length).toEqual(i+2);
|
|
expect(this.chatboxes.length).toEqual(i+2);
|
|
- sleep(timeout);
|
|
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
|
|
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
|
|
// Check that the roster items retrieved from localStorage
|
|
// have the same attributes values as the original ones.
|
|
// have the same attributes values as the original ones.
|
|
attrs = ['id', 'box_id', 'visible'];
|
|
attrs = ['id', 'box_id', 'visible'];
|
|
for (i=0; i<attrs.length; i++) {
|
|
for (i=0; i<attrs.length; i++) {
|
|
- new_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
- old_attrs = _.pluck(_.pluck(old_chatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
|
|
+ new_attrs = _.pluck(_.pluck(this.newchatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
+ old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
}
|
|
}
|
|
this.rosterview.render();
|
|
this.rosterview.render();
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
|
|
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
|
|
- var chatbox, view, $el;
|
|
|
|
- for (i=0; i<this.chatboxes.length; i++) {
|
|
|
|
- chatbox = this.chatboxes.models[i];
|
|
|
|
|
|
+ var chatbox, view, $el,
|
|
|
|
+ num_open_chats = this.chatboxes.length;
|
|
|
|
+ for (i=0; i<num_open_chats; i++) {
|
|
|
|
+ chatbox = this.chatboxes.models[0];
|
|
view = this.chatboxesview.views[chatbox.get('id')];
|
|
view = this.chatboxesview.views[chatbox.get('id')];
|
|
spyOn(view, 'closeChat').andCallThrough();
|
|
spyOn(view, 'closeChat').andCallThrough();
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
view.$el.find('.close-chatbox-button').click();
|
|
view.$el.find('.close-chatbox-button').click();
|
|
expect(view.closeChat).toHaveBeenCalled();
|
|
expect(view.closeChat).toHaveBeenCalled();
|
|
- sleep(timeout);
|
|
|
|
}
|
|
}
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
it("will be removed from localStorage when closed", $.proxy(function () {
|
|
it("will be removed from localStorage when closed", $.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.newchatboxes = new this.ChatBoxes();
|
|
|
|
+ expect(this.newchatboxes.length).toEqual(0);
|
|
|
|
+ // onConnected will fetch chatboxes in localStorage, but
|
|
|
|
+ // because there aren't any open chatboxes, there won't be any
|
|
|
|
+ // in localStorage either.
|
|
this.chatboxes.onConnected();
|
|
this.chatboxes.onConnected();
|
|
expect(this.chatboxes.length).toEqual(0);
|
|
expect(this.chatboxes.length).toEqual(0);
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
+
|
|
|
|
+ describe("A Chat Message", $.proxy(function () {
|
|
|
|
+ it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
|
|
|
|
+ var message = 'This is a received message';
|
|
|
|
+ var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
|
|
|
|
+ msg = $msg({
|
|
|
|
+ from: sender_jid,
|
|
|
|
+ to: this.bare_jid,
|
|
|
|
+ type: 'chat',
|
|
|
|
+ id: (new Date()).getTime()
|
|
|
|
+ }).c('body').t(message).up()
|
|
|
|
+ .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
+
|
|
|
|
+ spyOn(this, 'getVCard').andCallThrough();
|
|
|
|
+
|
|
|
|
+ // We don't already have an open chatbox for this user
|
|
|
|
+ expect(this.chatboxes.get(sender_jid)).not.toBeDefined();
|
|
|
|
+
|
|
|
|
+ runs($.proxy(function () {
|
|
|
|
+ // messageReceived is a handler for received XMPP
|
|
|
|
+ // messages
|
|
|
|
+ this.chatboxes.messageReceived(msg);
|
|
|
|
+ }, xmppchat));
|
|
|
|
+ waits(500);
|
|
|
|
+ runs($.proxy(function () {
|
|
|
|
+ // Since we didn't already have an open chatbox, one
|
|
|
|
+ // will asynchronously created inside a callback to
|
|
|
|
+ // getVCard
|
|
|
|
+ expect(this.getVCard).toHaveBeenCalled();
|
|
|
|
+ // Check that the chatbox and its view now exist
|
|
|
|
+ var chatbox = this.chatboxes.get(sender_jid);
|
|
|
|
+ var chatboxview = this.chatboxesview.views[sender_jid];
|
|
|
|
+ expect(chatbox).toBeDefined();
|
|
|
|
+ expect(chatboxview).toBeDefined();
|
|
|
|
+ // Check that the message was received and check the
|
|
|
|
+ // message parameters
|
|
|
|
+ expect(chatbox.messages.length).toEqual(1);
|
|
|
|
+ var msg_obj = chatbox.messages.models[0];
|
|
|
|
+ expect(msg_obj.get('message')).toEqual(message);
|
|
|
|
+ // XXX: This is stupid, fullname is actually only the
|
|
|
|
+ // users first name
|
|
|
|
+ expect(msg_obj.get('fullname')).toEqual(cur_names[0].split(' ')[0]);
|
|
|
|
+ expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
+ expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
+ // Now check that the message appears inside the
|
|
|
|
+ // chatbox in the DOM
|
|
|
|
+ var txt = chatboxview.$el.find('.chat-content').find('.chat-message').find('.chat-message-content').text();
|
|
|
|
+ expect(txt).toEqual(message);
|
|
|
|
+ }, xmppchat));
|
|
|
|
+ }, xmppchat));
|
|
|
|
+
|
|
|
|
+ it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
|
|
|
|
+ // TODO
|
|
|
|
+ }, xmppchat));
|
|
|
|
+ }, xmppchat));
|
|
}, xmppchat));
|
|
}, xmppchat));
|
|
|
|
|
|
}, xmppchat));
|
|
}, xmppchat));
|