2012-12-09 18:55:23 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
|
|
|
"converse"
|
|
|
|
], function (xmppchat) {
|
|
|
|
return factory(xmppchat);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} (this, function (xmppchat) {
|
|
|
|
|
2013-04-13 00:56:53 +02:00
|
|
|
return describe("Converse.js", $.proxy(function() {
|
2012-12-09 18:55:23 +01:00
|
|
|
// Names from http://www.fakenamegenerator.com/
|
|
|
|
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',
|
|
|
|
'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',
|
|
|
|
'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
|
|
|
|
'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'
|
|
|
|
];
|
2013-04-12 20:30:41 +02:00
|
|
|
mock_connection = {
|
|
|
|
'muc': {
|
|
|
|
'listRooms': function () {}
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
};
|
2013-04-13 00:16:50 +02:00
|
|
|
this.prebind = true;
|
|
|
|
this.connection = mock_connection;
|
|
|
|
this.chatboxes = new this.ChatBoxes();
|
|
|
|
this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes});
|
|
|
|
this.roster = new this.RosterItems();
|
|
|
|
// Clear localStorage
|
|
|
|
var key = hex_sha1('converse.rosteritems-dummy@localhost');
|
|
|
|
window.localStorage.removeItem(key);
|
|
|
|
this.roster.localStorage = new Backbone.LocalStorage(key);
|
|
|
|
|
|
|
|
this.chatboxes.onConnected();
|
|
|
|
this.rosterview = new this.RosterView({'model':this.roster});
|
|
|
|
this.rosterview.render();
|
2013-04-12 20:30:41 +02:00
|
|
|
|
2013-04-13 00:56:53 +02:00
|
|
|
describe("The contacts roster", $.proxy(function () {
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-02-28 06:48:06 +01:00
|
|
|
// by default the dts are hidden from css class and only later they will be hidden
|
|
|
|
// by jQuery therefore for the first check we will see if visible instead of none
|
2013-04-13 00:16:50 +02:00
|
|
|
it("hides the requesting contacts heading if there aren't any", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
|
|
|
|
}, xmppchat));
|
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("hides the current contacts heading if there aren't any", $.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
|
|
|
|
}, xmppchat));
|
|
|
|
|
|
|
|
it("hides the pending contacts heading if there aren't any", $.proxy(function () {
|
|
|
|
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
|
|
|
|
}, xmppchat));
|
|
|
|
|
|
|
|
it("can add requesting contacts, and they should be sorted alphabetically", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
var i, t;
|
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2013-04-12 23:08:30 +02:00
|
|
|
spyOn(this, 'showControlBox');
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=0; i<10; i++) {
|
2013-04-12 20:30:41 +02:00
|
|
|
this.roster.create({
|
|
|
|
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'request',
|
|
|
|
fullname: names[i],
|
|
|
|
is_last: i<9
|
|
|
|
});
|
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').text().replace(/AcceptDecline/g, '');
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(0,i+1).sort().join(''));
|
|
|
|
// When a requesting contact is added, the controlbox must
|
|
|
|
// be opened.
|
2013-04-12 23:08:30 +02:00
|
|
|
expect(this.showControlBox).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
}
|
2013-04-12 20:30:41 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("shows the requesting contacts heading after they have been added", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
|
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("can add pending contacts, and they should be sorted alphabetically", $.proxy(function () {
|
2013-04-12 23:08:30 +02:00
|
|
|
var i, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=10; i<20; i++) {
|
2013-04-12 23:08:30 +02:00
|
|
|
this.roster.create({
|
|
|
|
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: names[i],
|
|
|
|
is_last: i<20
|
|
|
|
});
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(10,i+1).sort().join(''));
|
|
|
|
}
|
2013-04-12 20:30:41 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("shows the pending contacts heading after they have been added", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
|
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("can add existing contacts, and they should be sorted alphabetically", $.proxy(function () {
|
2013-04-12 23:08:30 +02:00
|
|
|
var i, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
// Add 40 properly regisertered contacts (initially all offline) and check that they are sorted alphabetically
|
|
|
|
for (i=20; i<60; i++) {
|
2013-04-12 23:08:30 +02:00
|
|
|
this.roster.create({
|
|
|
|
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
|
|
|
fullname: names[i],
|
|
|
|
is_last: i<60
|
|
|
|
});
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(20,i+1).sort().join(''));
|
|
|
|
}
|
2013-04-12 20:30:41 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("shows the current contacts heading if they have been added", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
|
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-12 20:30:41 +02:00
|
|
|
describe("roster items", $.proxy(function () {
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
it("are saved to, and can be retrieved from, localStorage", $.proxy(function () {
|
|
|
|
var new_attrs, old_attrs, attrs, old_roster;
|
|
|
|
|
|
|
|
expect(this.roster.length).toEqual(60);
|
|
|
|
old_roster = this.roster;
|
|
|
|
this.roster = new this.RosterItems();
|
|
|
|
expect(this.roster.length).toEqual(0);
|
|
|
|
|
|
|
|
this.roster.localStorage = new Backbone.LocalStorage(
|
|
|
|
hex_sha1('converse.rosteritems-dummy@localhost'));
|
|
|
|
this.chatboxes.onConnected();
|
|
|
|
|
|
|
|
spyOn(this.roster, 'fetch').andCallThrough();
|
|
|
|
this.rosterview = new this.RosterView({'model':this.roster});
|
|
|
|
expect(this.roster.fetch).toHaveBeenCalled();
|
|
|
|
expect(this.roster.length).toEqual(60);
|
|
|
|
|
|
|
|
// Check that the roster items retrieved from localStorage
|
|
|
|
// have the same attributes values as the original ones.
|
|
|
|
attrs = ['jid', 'fullname', 'subscription', 'ask'];
|
|
|
|
for (i=0; i<attrs.length; i++) {
|
|
|
|
new_attrs = _.pluck(_.pluck(this.roster.models, 'attributes'), attrs[i]);
|
|
|
|
old_attrs = _.pluck(_.pluck(old_roster.models, 'attributes'), attrs[i]);
|
|
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
|
|
}
|
|
|
|
this.rosterview.render();
|
|
|
|
}, xmppchat));
|
|
|
|
|
2013-04-12 23:20:31 +02:00
|
|
|
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
2013-04-13 00:56:53 +02:00
|
|
|
var item, view, jid, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=59; i>54; i--) {
|
|
|
|
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
|
2013-04-12 20:30:41 +02:00
|
|
|
view = this.rosterview.rosteritemviews[jid];
|
2012-12-09 18:55:23 +01:00
|
|
|
spyOn(view, 'render').andCallThrough();
|
|
|
|
item = view.model;
|
2013-04-12 23:08:30 +02:00
|
|
|
item.set('chat_status', 'online');
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(view.render).toHaveBeenCalled();
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
|
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(-(60-i)).sort().join(''));
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-12 23:20:31 +02:00
|
|
|
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
|
2013-04-13 00:56:53 +02:00
|
|
|
var item, view, jid, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=54; i>49; i--) {
|
|
|
|
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
|
2013-04-12 20:30:41 +02:00
|
|
|
view = this.rosterview.rosteritemviews[jid];
|
2012-12-09 18:55:23 +01:00
|
|
|
spyOn(view, 'render').andCallThrough();
|
|
|
|
item = view.model;
|
2013-04-12 23:08:30 +02:00
|
|
|
item.set('chat_status', 'dnd');
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(view.render).toHaveBeenCalled();
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 23:08:30 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(-(60-i), -5).sort().join(''));
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-12 23:20:31 +02:00
|
|
|
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
|
2013-04-13 00:56:53 +02:00
|
|
|
var item, view, jid, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=49; i>44; i--) {
|
|
|
|
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
|
2013-04-12 20:30:41 +02:00
|
|
|
view = this.rosterview.rosteritemviews[jid];
|
2012-12-09 18:55:23 +01:00
|
|
|
spyOn(view, 'render').andCallThrough();
|
|
|
|
item = view.model;
|
2013-04-12 23:08:30 +02:00
|
|
|
item.set('chat_status', 'away');
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(view.render).toHaveBeenCalled();
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
|
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(-(60-i),-10).sort().join(''));
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-12 23:20:31 +02:00
|
|
|
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
|
2013-04-13 00:56:53 +02:00
|
|
|
var item, view, jid, t;
|
2013-04-12 20:30:41 +02:00
|
|
|
spyOn(this.rosterview, 'render').andCallThrough();
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=44; i>39; i--) {
|
|
|
|
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
|
2013-04-12 20:30:41 +02:00
|
|
|
view = this.rosterview.rosteritemviews[jid];
|
2012-12-09 18:55:23 +01:00
|
|
|
spyOn(view, 'render').andCallThrough();
|
|
|
|
item = view.model;
|
2013-04-12 23:08:30 +02:00
|
|
|
item.set('chat_status', 'unavailable');
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(view.render).toHaveBeenCalled();
|
2013-04-12 20:30:41 +02:00
|
|
|
expect(this.rosterview.render).toHaveBeenCalled();
|
2012-12-09 18:55:23 +01:00
|
|
|
|
|
|
|
// Check that they are sorted alphabetically
|
2013-04-12 20:30:41 +02:00
|
|
|
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
|
2012-12-09 18:55:23 +01:00
|
|
|
expect(t).toEqual(names.slice(-(60-i), -15).sort().join(''));
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-12 23:20:31 +02:00
|
|
|
it("are ordered according to status: online, busy, away, unavailable, offline", $.proxy(function () {
|
2013-04-12 20:30:41 +02:00
|
|
|
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
|
2012-12-09 18:55:23 +01:00
|
|
|
var i;
|
|
|
|
// The first five contacts are online.
|
|
|
|
for (i=0; i<5; i++) {
|
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('online');
|
|
|
|
}
|
|
|
|
// The next five are busy
|
|
|
|
for (i=5; i<10; i++) {
|
2013-04-12 23:08:30 +02:00
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('dnd');
|
2012-12-09 18:55:23 +01:00
|
|
|
}
|
|
|
|
// The next five are away
|
|
|
|
for (i=10; i<15; i++) {
|
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('away');
|
|
|
|
}
|
2013-02-22 14:42:35 +01:00
|
|
|
// The next five are unavailable
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=15; i<20; i++) {
|
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
|
|
|
|
}
|
2013-02-22 14:42:35 +01:00
|
|
|
// The next 20 are offline
|
2012-12-09 18:55:23 +01:00
|
|
|
for (i=20; i<40; i++) {
|
|
|
|
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
|
|
|
|
}
|
2013-04-12 23:08:30 +02:00
|
|
|
}, xmppchat));
|
2013-04-12 20:30:41 +02:00
|
|
|
}, xmppchat));
|
2013-04-13 00:56:53 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
|
2013-04-13 00:56:53 +02:00
|
|
|
describe("Chatboxes", $.proxy(function () {
|
|
|
|
it("are created when you click on a roster item", $.proxy(function () {
|
|
|
|
var $el = $(this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat')[0]);
|
|
|
|
var click = jQuery.Event("click", { target: $el });
|
|
|
|
var jid = $el.text().replace(' ','.').toLowerCase() + '@localhost';
|
|
|
|
var view = this.rosterview.rosteritemviews[jid];
|
|
|
|
spyOn(view, 'openChat');
|
|
|
|
// We need to rebind all events otherwise our spy won't work.
|
|
|
|
view.delegateEvents();
|
|
|
|
var ev = $el.click();
|
|
|
|
expect(view.openChat).toHaveBeenCalled();
|
|
|
|
}, xmppchat));
|
2013-04-12 20:30:41 +02:00
|
|
|
}, xmppchat));
|
2013-04-13 00:56:53 +02:00
|
|
|
|
2013-04-13 00:16:50 +02:00
|
|
|
}, xmppchat));
|
2012-12-09 18:55:23 +01:00
|
|
|
}));
|