Selaa lähdekoodia

Add another profiling method for adding users without groups

JC Brand 10 vuotta sitten
vanhempi
commit
015367af62
1 muutettua tiedostoa jossa 23 lisäystä ja 7 poistoa
  1. 23 7
      spec/profiling.js

+ 23 - 7
spec/profiling.js

@@ -9,22 +9,40 @@
     );
     );
 } (this, function ($, mock, test_utils) {
 } (this, function ($, mock, test_utils) {
     describe("Profiling", function() {
     describe("Profiling", function() {
-        var roster;
         beforeEach(function() {
         beforeEach(function() {
-            roster = converse.connection.roster;
+            converse.connection.roster.items = [];
             converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
             converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
         });
         });
 
 
         it("adds hundreds of contacts to the roster", $.proxy(function() {
         it("adds hundreds of contacts to the roster", $.proxy(function() {
+            converse.roster_groups = false;
+            spyOn(this.roster, 'clearCache').andCallThrough();
+            expect(this.roster.pluck('jid').length).toBe(0);
+            var stanza = $iq({
+                to: this.connection.jid,
+                type: 'result',
+                id: 'roster_1'
+            }).c('query', {
+                xmlns: 'jabber:iq:roster'
+            });
+            _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
+                var i;
+                for (i=0; i<100; i++) {
+                    stanza = stanza.c('item', {
+                        jid: Math.random().toString().replace('0.', '')+'@example.net',
+                        subscription:'both'
+                    }).c('group').t(group).up().up();
+                }
+            });
+            this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
+            expect(this.roster.clearCache).toHaveBeenCalled();
+            expect(this.roster.pluck('jid').length).toBe(400);
         }, converse));
         }, converse));
 
 
         it("adds hundreds of contacts to the roster, with roster groups", $.proxy(function() {
         it("adds hundreds of contacts to the roster, with roster groups", $.proxy(function() {
-            // XXX: Try with groups for now (might also add a test without groups)
             converse.roster_groups = true;
             converse.roster_groups = true;
-
             spyOn(this.roster, 'clearCache').andCallThrough();
             spyOn(this.roster, 'clearCache').andCallThrough();
             expect(this.roster.pluck('jid').length).toBe(0);
             expect(this.roster.pluck('jid').length).toBe(0);
-
             var stanza = $iq({
             var stanza = $iq({
                 to: this.connection.jid,
                 to: this.connection.jid,
                 type: 'result',
                 type: 'result',
@@ -32,7 +50,6 @@
             }).c('query', {
             }).c('query', {
                 xmlns: 'jabber:iq:roster'
                 xmlns: 'jabber:iq:roster'
             });
             });
-
             _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
             _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
                 var i;
                 var i;
                 for (i=0; i<100; i++) {
                 for (i=0; i<100; i++) {
@@ -44,7 +61,6 @@
             });
             });
             this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
             this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
             expect(this.roster.clearCache).toHaveBeenCalled();
             expect(this.roster.clearCache).toHaveBeenCalled();
-
             expect(this.roster.pluck('jid').length).toBe(400);
             expect(this.roster.pluck('jid').length).toBe(400);
         }, converse));
         }, converse));