xmpp.chapril.org-conversejs/spec/profiling.js
JC Brand 1fa203c990 Support for IndexedDB. updates #1105
Depend on latest backbone.browserStorage which has support for IndexedDB
via localforage.

Storage operations are now asynchronous and transactional.

Bugs fixed (mostly by waiting for operations to complete):

* Rooms are now fetched asynchronously, so wait before triggering `show`
  or when closing.
* Make sure chat create/update transactions complete before firing events
* Make sure chats and messages have been fetched before creating new ones.
* When doing a `fetch` with `wait: false` on a collection and then
  creating a model in that collection, then once the read
  operation finishes (after creating the model), the collection is emptied again.
* Patch and wait when saving.
  Otherwise we have previously set attributes overriding later ones.
* Make sure api.roomviews.close returns a promise

Test fixes:

* Chats are now asynchronously returned, so we need to use `await`
* Wait for the storage transaction to complete when creating and updating messages
* Wait for all chatboxes to close
    Otherwise we get sessionStorage inconsistencies due to the async nature of localforage.
* Wait for room views to close in spec/chatroom.js

In the process, remove the `closeAllChatBoxes` override in
converse-controlbox by letting the `close` method decide whether it
should be closed or not.
2019-10-30 13:02:23 +01:00

132 lines
5.4 KiB
JavaScript

(function (root, factory) {
define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) {
var _ = converse.env._;
var $iq = converse.env.$iq;
var $pres = converse.env.$pres;
var u = converse.env.utils;
describe("Profiling", function() {
it("shows users currently present in the groupchat",
mock.initConverse(
['rosterGroupsFetched'], {'muc_show_join_leave': false},
async function (done, _converse) {
test_utils.openControlBox(_converse);
await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
_.rangeRight(3000, 0).forEach(i => {
const name = `User ${i.toString().padStart(5, '0')}`;
const presence = $pres({
'to': 'romeo@montague.lit/orchard',
'from': 'lounge@montague.lit/'+name
}).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
.c('item').attrs({
affiliation: 'none',
jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
// expect(occupants.querySelectorAll('li').length).toBe(1+i);
// const model = view.model.occupants.where({'nick': name})[0];
// const index = view.model.occupants.indexOf(model);
// expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(name);
});
done();
}));
xit("adds hundreds of contacts to the roster",
mock.initConverse(
['rosterGroupsFetched'], {},
function (done, _converse) {
_converse.roster_groups = false;
test_utils.openControlBox(_converse);
expect(_converse.roster.pluck('jid').length).toBe(0);
var stanza = $iq({
to: _converse.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<50; i++) {
stanza = stanza.c('item', {
jid: Math.random().toString().replace('0.', '')+'@example.net',
subscription:'both'
}).c('group').t(group).up().up();
}
});
_converse.roster.onReceivedFromServer(stanza.tree());
return u.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 u.waitUntil(function () {
return _converse.rosterview.$el.find('li.online').length
})
}).then(done);
}));
xit("adds hundreds of contacts to the roster, with roster groups",
mock.initConverse(
['rosterGroupsFetched'], {},
function (done, _converse) {
// _converse.show_only_online_users = true;
_converse.roster_groups = true;
test_utils.openControlBox(_converse);
expect(_converse.roster.pluck('jid').length).toBe(0);
var stanza = $iq({
to: _converse.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();
}
});
_converse.roster.onReceivedFromServer(stanza.tree());
return u.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 u.waitUntil(function () {
return _converse.rosterview.$el.find('li.online').length
})
}).then(done);
}));
});
}));