Reordered the tests
So that we have test suites for each type of contact - Pending - Existing - Requesting
This commit is contained in:
parent
29a6e1d9f1
commit
567cfd3501
175
spec/MainSpec.js
175
spec/MainSpec.js
@ -67,7 +67,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
describe("The contacts roster", $.proxy(function () {
|
||||
describe("The Contacts Roster", $.proxy(function () {
|
||||
it("is not shown by default", $.proxy(function () {
|
||||
expect(this.rosterview.$el.is(':visible')).toEqual(false);
|
||||
}, xmppchat));
|
||||
@ -78,11 +78,12 @@
|
||||
expect(this.toggleControlBox).toHaveBeenCalled();
|
||||
}, xmppchat));
|
||||
|
||||
it("hides the pending contacts heading if there aren't any", $.proxy(function () {
|
||||
describe("Pending Contacts", $.proxy(function () {
|
||||
it("do not have a 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 pending contacts, and they should be sorted alphabetically", $.proxy(function () {
|
||||
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
||||
var i, t, is_last;
|
||||
spyOn(this.rosterview, 'render').andCallThrough();
|
||||
for (i=0; i<pend_names.length; i++) {
|
||||
@ -109,15 +110,17 @@
|
||||
sleep(timeout);
|
||||
}, xmppchat));
|
||||
|
||||
it("shows the pending contacts heading after they have been added", $.proxy(function () {
|
||||
it("will have their own heading once they have been added", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
|
||||
}, xmppchat));
|
||||
}, xmppchat));
|
||||
|
||||
it("hides the current contacts heading if there aren't any", $.proxy(function () {
|
||||
describe("Existing Contacts", $.proxy(function () {
|
||||
it("do not have a heading if there aren't any", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
|
||||
}, xmppchat));
|
||||
|
||||
it("can add existing contacts, and they should be sorted alphabetically", $.proxy(function () {
|
||||
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
||||
var i, t;
|
||||
spyOn(this.rosterview, 'render').andCallThrough();
|
||||
for (i=0; i<cur_names.length; i++) {
|
||||
@ -136,77 +139,10 @@
|
||||
sleep(timeout);
|
||||
}, xmppchat));
|
||||
|
||||
it("shows the current contacts heading if they have been added", $.proxy(function () {
|
||||
it("will have their own heading once they have been added", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
|
||||
}, 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 () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
|
||||
}, xmppchat));
|
||||
|
||||
it("can add requesting contacts, and they should be sorted alphabetically", $.proxy(function () {
|
||||
var i, t;
|
||||
spyOn(this.rosterview, 'render').andCallThrough();
|
||||
spyOn(this, 'showControlBox').andCallThrough();
|
||||
for (i=0; i<req_names.length; i++) {
|
||||
this.roster.create({
|
||||
jid: req_names[i].replace(' ','.').toLowerCase() + '@localhost',
|
||||
subscription: 'none',
|
||||
ask: 'request',
|
||||
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(req_names.slice(0,i+1).sort().join(''));
|
||||
// When a requesting contact is added, the controlbox must
|
||||
// be opened.
|
||||
expect(this.showControlBox).toHaveBeenCalled();
|
||||
}
|
||||
sleep(timeout);
|
||||
}, xmppchat));
|
||||
|
||||
it("shows the requesting contacts heading after they have been added", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
|
||||
}, xmppchat));
|
||||
|
||||
it("allows the user to accept or decline requesting contacts", $.proxy(function () {
|
||||
// TODO
|
||||
}, xmppchat));
|
||||
|
||||
describe("Roster items", $.proxy(function () {
|
||||
|
||||
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));
|
||||
|
||||
it("can change their status to online and be sorted alphabetically", $.proxy(function () {
|
||||
var item, view, jid, t;
|
||||
spyOn(this.rosterview, 'render').andCallThrough();
|
||||
@ -306,6 +242,97 @@
|
||||
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
|
||||
}
|
||||
}, xmppchat));
|
||||
|
||||
|
||||
}, xmppchat));
|
||||
|
||||
describe("Requesting Contacts", $.proxy(function () {
|
||||
// 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("do not have a heading if there aren't any", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
|
||||
}, xmppchat));
|
||||
|
||||
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
|
||||
var i, t;
|
||||
spyOn(this.rosterview, 'render').andCallThrough();
|
||||
spyOn(this, 'showControlBox').andCallThrough();
|
||||
for (i=0; i<req_names.length; i++) {
|
||||
this.roster.create({
|
||||
jid: req_names[i].replace(' ','.').toLowerCase() + '@localhost',
|
||||
subscription: 'none',
|
||||
ask: 'request',
|
||||
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(req_names.slice(0,i+1).sort().join(''));
|
||||
// When a requesting contact is added, the controlbox must
|
||||
// be opened.
|
||||
expect(this.showControlBox).toHaveBeenCalled();
|
||||
}
|
||||
sleep(timeout);
|
||||
}, xmppchat));
|
||||
|
||||
it("will have their own heading once they have been added", $.proxy(function () {
|
||||
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
|
||||
}, xmppchat));
|
||||
|
||||
it("can have their requests accepted by the user", $.proxy(function () {
|
||||
// TODO Simulate and test clicking of accept/deny
|
||||
}, xmppchat));
|
||||
|
||||
it("can have their requests denied by the user", $.proxy(function () {
|
||||
// TODO Simulate and test clicking of accept/deny
|
||||
}, xmppchat));
|
||||
}, xmppchat));
|
||||
|
||||
describe("All Contacts", $.proxy(function () {
|
||||
|
||||
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]);
|
||||
// Roster items in storage are not necessarily sorted,
|
||||
// so we have to sort them here to do a proper
|
||||
// comparison
|
||||
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
|
||||
}
|
||||
this.rosterview.render();
|
||||
}, xmppchat));
|
||||
|
||||
afterEach($.proxy(function () {
|
||||
// Contacts retrieved from localStorage have chat_status of
|
||||
// "offline".
|
||||
// In the next test suite, we need some online contacts, so
|
||||
// we make some online now
|
||||
for (i=0; i<5; i++) {
|
||||
jid = cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
||||
view = this.rosterview.rosteritemviews[jid];
|
||||
view.model.set('chat_status', 'online');
|
||||
}
|
||||
}, xmppchat));
|
||||
}, xmppchat));
|
||||
}, xmppchat));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user