Explorar o código

Reordered the tests

So that we have test suites for each type of contact
- Pending
- Existing
- Requesting
JC Brand %!s(int64=12) %!d(string=hai) anos
pai
achega
567cfd3501
Modificáronse 1 ficheiros con 148 adicións e 121 borrados
  1. 148 121
      spec/MainSpec.js

+ 148 - 121
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,133 +78,69 @@
                 expect(this.toggleControlBox).toHaveBeenCalled();
             }, 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));
+            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 () {
-                var i, t, is_last;
-                spyOn(this.rosterview, 'render').andCallThrough();
-                for (i=0; i<pend_names.length; i++) {
-                    is_last = i==(pend_names.length-1);
-                    this.roster.create({
-                        jid: pend_names[i].replace(' ','.').toLowerCase() + '@localhost',
-                        subscription: 'none',
-                        ask: 'subscribe',
-                        fullname: pend_names[i],
-                        is_last: is_last
-                    });
-                    // For performance reasons, the roster should only be shown once 
-                    // the last contact has been added.
-                    if (is_last) {
-                        expect(this.rosterview.$el.is(':visible')).toEqual(true);
-                    } else {
-                        expect(this.rosterview.$el.is(':visible')).toEqual(false);
+                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++) {
+                        is_last = i==(pend_names.length-1);
+                        this.roster.create({
+                            jid: pend_names[i].replace(' ','.').toLowerCase() + '@localhost',
+                            subscription: 'none',
+                            ask: 'subscribe',
+                            fullname: pend_names[i],
+                            is_last: is_last
+                        });
+                        // For performance reasons, the roster should only be shown once 
+                        // the last contact has been added.
+                        if (is_last) {
+                            expect(this.rosterview.$el.is(':visible')).toEqual(true);
+                        } else {
+                            expect(this.rosterview.$el.is(':visible')).toEqual(false);
+                        }
+                        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(pend_names.slice(0,i+1).sort().join(''));
                     }
-                    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(pend_names.slice(0,i+1).sort().join(''));
-                }
-                sleep(timeout);
-            }, xmppchat));
-
-            it("shows the pending contacts heading after they have been added", $.proxy(function () {
-                expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
-            }, xmppchat));
-
-            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("can add existing contacts, and they should be sorted alphabetically", $.proxy(function () {
-                var i, t;
-                spyOn(this.rosterview, 'render').andCallThrough();
-                for (i=0; i<cur_names.length; i++) {
-                    this.roster.create({
-                        jid: cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
-                        subscription: 'both',
-                        ask: null,
-                        fullname: cur_names[i],
-                        is_last: i==(cur_names.length-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(cur_names.slice(0,i+1).sort().join(''));
-                }
-                sleep(timeout);
-            }, xmppchat));
-
-            it("shows the current contacts heading if 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));
+                    sleep(timeout);
+                }, xmppchat));
 
-            it("allows the user to accept or decline requesting contacts", $.proxy(function () {
-                // TODO
+                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));
 
-            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);
+            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));
 
-                    // 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);
+                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++) {
+                        this.roster.create({
+                            jid: cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
+                            subscription: 'both',
+                            ask: null,
+                            fullname: cur_names[i],
+                            is_last: i==(cur_names.length-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(cur_names.slice(0,i+1).sort().join(''));
                     }
-                    this.rosterview.render();
+                    sleep(timeout);
+                }, xmppchat));
+
+                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));
 
                 it("can change their status to online and be sorted alphabetically", $.proxy(function () {
@@ -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));