profiling.js 4.06 KB
Newer Older
1
(function (root, factory) {
JC Brand's avatar
JC Brand committed
2 3
    define(["jasmine", "mock", "converse-core", "test-utils", "utils"], factory);
} (this, function (jasmine, mock, converse, test_utils, u) {
4 5
    var _ = converse.env._;
    var $iq = converse.env.$iq;
6

7
    describe("Profiling", function() {
JC Brand's avatar
JC Brand committed
8 9 10 11
        xit("adds hundreds of contacts to the roster",
                mock.initConverseWithPromises(
                    null, ['rosterGroupsFetched'], {},
                    function (done, _converse) {
12

13
            _converse.roster_groups = false;
JC Brand's avatar
JC Brand committed
14 15 16
            test_utils.openControlBox();

            expect(_converse.roster.pluck('jid').length).toBe(0);
17
            var stanza = $iq({
JC Brand's avatar
JC Brand committed
18
                to: _converse.connection.jid,
19 20 21 22 23 24 25
                type: 'result',
                id: 'roster_1'
            }).c('query', {
                xmlns: 'jabber:iq:roster'
            });
            _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
                var i;
26
                for (i=0; i<50; i++) {
27 28 29 30 31 32
                    stanza = stanza.c('item', {
                        jid: Math.random().toString().replace('0.', '')+'@example.net',
                        subscription:'both'
                    }).c('group').t(group).up().up();
                }
            });
JC Brand's avatar
JC Brand committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
            _converse.roster.onReceivedFromServer(stanza.tree());

            return test_utils.waitUntil(function () {
                var $group = _converse.rosterview.$el.find('.roster-group')
                return $group.length && u.isVisible($group[0]);
            }).then(function () {
                var count = 0;
                _converse.roster.each(function (contact) {
                    if (count < 10) {
                        contact.set('chat_status', 'online');
                        count += 1;
                    }
                });
                return test_utils.waitUntil(function () {
                    return _converse.rosterview.$el.find('li.online').length
                })
            }).then(done);
50
        }));
51

JC Brand's avatar
JC Brand committed
52 53 54 55 56
        xit("adds hundreds of contacts to the roster, with roster groups",
                mock.initConverseWithPromises(
                    null, ['rosterGroupsFetched'], {},
                    function (done, _converse) {
            
57 58
            // _converse.show_only_online_users = true;
            _converse.roster_groups = true;
JC Brand's avatar
JC Brand committed
59 60 61
            test_utils.openControlBox();

            expect(_converse.roster.pluck('jid').length).toBe(0);
62
            var stanza = $iq({
JC Brand's avatar
JC Brand committed
63
                to: _converse.connection.jid,
64 65 66
                type: 'result',
                id: 'roster_1'
            }).c('query', {
67 68 69
                xmlns: 'jabber:iq:roster'
            });
            _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
70
                var i;
JC Brand's avatar
JC Brand committed
71
                for (i=0; i<100; i++) {
72
                    stanza = stanza.c('item', {
73
                        jid: Math.random().toString().replace('0.', '')+'@example.net',
74
                        subscription:'both'
75
                    }).c('group').t(group).up().up();
76 77
                }
            });
JC Brand's avatar
JC Brand committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            _converse.roster.onReceivedFromServer(stanza.tree());

            return test_utils.waitUntil(function () {
                var $group = _converse.rosterview.$el.find('.roster-group')
                return $group.length && u.isVisible($group[0]);
            }).then(function () {
                _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
                    var count = 0;
                    _converse.roster.each(function (contact) {
                        if (_.includes(contact.get('groups'), group)) {
                            if (count < 10) {
                                contact.set('chat_status', 'online');
                                count += 1;
                            }
                        }
                    });
                });
                return test_utils.waitUntil(function () {
                    return _converse.rosterview.$el.find('li.online').length
                })
            }).then(done);
99
        }));
100 101
    });
}));