Commit 7852f67a authored by JC Brand's avatar JC Brand

Split the contacts up into distinct groups.

This reduces some hoops that had to be jumped through to get the proper indexes
to retrieve contacts
parent d66cf7c2
......@@ -9,15 +9,19 @@
return describe("Converse.js", $.proxy(function() {
// Names from http://www.fakenamegenerator.com/
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',
'Maylin Hettema', 'Ruwan Bechan', 'Marco Beich', 'Karin Busch', 'Mathias Müller'
];
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',
'Dani Boldewijn', 'Katrin Propst', 'Martina Kaiser', 'Philipp Kappel', 'Meeke Grootendorst'
];
var cur_names = [
'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',
......@@ -47,7 +51,7 @@
hex_sha1('converse.xmppstatus-'+this.bare_jid));
this.prebind = true;
this.initialize(mock_connection);
this.onConnected(mock_connection);
// The timeout is used to slow down the tests so that one can see
// visually what is happening in the page.
......@@ -59,6 +63,12 @@
expect(this.rosterview.$el.is(':visible')).toEqual(false);
}, xmppchat));
it("can be opened by clicking a DOM element with id 'toggle-online-users'", $.proxy(function () {
spyOn(this, 'toggleControlBox').andCallThrough();
$('#toggle-online-users').click();
expect(this.toggleControlBox).toHaveBeenCalled();
}, xmppchat));
// 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
it("hides the requesting contacts heading if there aren't any", $.proxy(function () {
......@@ -69,18 +79,18 @@
var i, t;
spyOn(this.rosterview, 'render').andCallThrough();
spyOn(this, 'showControlBox').andCallThrough();
for (i=0; i<10; i++) {
for (i=0; i<req_names.length; i++) {
this.roster.create({
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
jid: req_names[i].replace(' ','.').toLowerCase() + '@localhost',
subscription: 'none',
ask: 'request',
fullname: names[i],
is_last: i<9
fullname: req_names[i],
is_last: i==(req_names.length-1)
});
expect(this.rosterview.render).toHaveBeenCalled();
// Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contact-requests').siblings('dd.requesting-xmpp-contact').text().replace(/AcceptDecline/g, '');
expect(t).toEqual(names.slice(0,i+1).sort().join(''));
expect(t).toEqual(req_names.slice(0,i+1).sort().join(''));
// When a requesting contact is added, the controlbox must
// be opened.
expect(this.showControlBox).toHaveBeenCalled();
......@@ -98,18 +108,18 @@
it("can add pending contacts, and they should be sorted alphabetically", $.proxy(function () {
var i, t;
spyOn(this.rosterview, 'render').andCallThrough();
for (i=10; i<20; i++) {
for (i=0; i<pend_names.length; i++) {
this.roster.create({
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
jid: pend_names[i].replace(' ','.').toLowerCase() + '@localhost',
subscription: 'none',
ask: 'subscribe',
fullname: names[i],
is_last: i<20
fullname: pend_names[i],
is_last: i==(pend_names-1)
});
expect(this.rosterview.render).toHaveBeenCalled();
// Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
expect(t).toEqual(names.slice(10,i+1).sort().join(''));
expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
}
}, xmppchat));
......@@ -124,19 +134,18 @@
it("can add existing contacts, and they should be sorted alphabetically", $.proxy(function () {
var i, t;
spyOn(this.rosterview, 'render').andCallThrough();
// Add 40 properly regisertered contacts (initially all offline) and check that they are sorted alphabetically
for (i=20; i<60; i++) {
for (i=0; i<cur_names.length; i++) {
this.roster.create({
jid: names[i].replace(' ','.').toLowerCase() + '@localhost',
jid: cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
subscription: 'both',
ask: null,
fullname: names[i],
is_last: i<60
fullname: cur_names[i],
is_last: i==(cur_names-1)
});
expect(this.rosterview.render).toHaveBeenCalled();
// Check that they are sorted alphabetically
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
expect(t).toEqual(names.slice(20,i+1).sort().join(''));
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
}
}, xmppchat));
......@@ -177,8 +186,8 @@
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t;
spyOn(this.rosterview, 'render').andCallThrough();
for (i=59; i>54; i--) {
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
for (i=0; i<5; i++) {
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
view = this.rosterview.rosteritemviews[jid];
spyOn(view, 'render').andCallThrough();
item = view.model;
......@@ -188,15 +197,15 @@
// 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();
expect(t).toEqual(names.slice(-(60-i)).sort().join(''));
expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
}
}, xmppchat));
it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t;
spyOn(this.rosterview, 'render').andCallThrough();
for (i=54; i>49; i--) {
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
for (i=5; i<10; i++) {
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
view = this.rosterview.rosteritemviews[jid];
spyOn(view, 'render').andCallThrough();
item = view.model;
......@@ -205,15 +214,15 @@
expect(this.rosterview.render).toHaveBeenCalled();
// 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();
expect(t).toEqual(names.slice(-(60-i), -5).sort().join(''));
expect(t).toEqual(cur_names.slice(5,i+1).sort().join(''));
}
}, xmppchat));
it("can change their status to away and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t;
spyOn(this.rosterview, 'render').andCallThrough();
for (i=49; i>44; i--) {
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
for (i=10; i<15; i++) {
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
view = this.rosterview.rosteritemviews[jid];
spyOn(view, 'render').andCallThrough();
item = view.model;
......@@ -223,15 +232,15 @@
// 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();
expect(t).toEqual(names.slice(-(60-i),-10).sort().join(''));
expect(t).toEqual(cur_names.slice(10,i+1).sort().join(''));
}
}, xmppchat));
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t;
spyOn(this.rosterview, 'render').andCallThrough();
for (i=44; i>39; i--) {
jid = names[i].replace(' ','.').toLowerCase() + '@localhost';
for (i=15; i<20; i++) {
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
view = this.rosterview.rosteritemviews[jid];
spyOn(view, 'render').andCallThrough();
item = view.model;
......@@ -241,7 +250,7 @@
// 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();
expect(t).toEqual(names.slice(-(60-i), -15).sort().join(''));
expect(t).toEqual(cur_names.slice(15, i+1).sort().join(''));
}
}, xmppchat));
......@@ -265,7 +274,7 @@
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('unavailable');
}
// The next 20 are offline
for (i=20; i<40; i++) {
for (i=20; i<cur_names.length; i++) {
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
}
}, xmppchat));
......
......@@ -3,16 +3,31 @@
<html>
<head>
<title>Converse.js Tests</title>
<meta name="description" content="Converse.js: Open Source Browser-Based Instant Messaging" />
<link rel="shortcut icon" type="image/png" href="Libraries/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="Libraries/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="Libraries/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="Libraries/jasmine-1.3.1/jasmine-html.js"></script>
<!-- include source files here... -->
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<link rel="stylesheet" type="text/css" media="screen" href="converse.css">
<script data-main="tests_main" src="Libraries/require-jquery.js"></script>
</head>
<body>
<div id="header_wrap" class="outer">
<header class="inner">
<h1 id="project_title">Converse.js</h1>
<h2 id="project_tagline">Tests</h2>
</header>
</div>
<div id="chatpanel">
<div id="collective-xmpp-chat-data"></div>
<div id="toggle-controlbox">
<a href="#" class="chat" id="toggle-online-users">
<span class="conn-feedback">Click here to chat</span> <strong style="display: none" id="online-count">(0)</strong>
</a>
</div>
</div>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment