2
0

profiling.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. (function (root, factory) {
  2. define(["jasmine", "mock", "test-utils"], factory);
  3. } (this, function (jasmine, mock, test_utils) {
  4. var _ = converse.env._;
  5. var $iq = converse.env.$iq;
  6. var $pres = converse.env.$pres;
  7. var u = converse.env.utils;
  8. describe("Profiling", function() {
  9. it("shows users currently present in the groupchat",
  10. mock.initConverse(
  11. ['rosterGroupsFetched'], {'muc_show_join_leave': false},
  12. async function (done, _converse) {
  13. test_utils.openControlBox(_converse);
  14. await test_utils.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'romeo');
  15. _.rangeRight(3000, 0).forEach(i => {
  16. const name = `User ${i.toString().padStart(5, '0')}`;
  17. const presence = $pres({
  18. 'to': 'romeo@montague.lit/orchard',
  19. 'from': 'lounge@montague.lit/'+name
  20. }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
  21. .c('item').attrs({
  22. affiliation: 'none',
  23. jid: name.replace(/ /g,'.').toLowerCase() + '@montague.lit',
  24. });
  25. _converse.connection._dataRecv(test_utils.createRequest(presence));
  26. // expect(occupants.querySelectorAll('li').length).toBe(1+i);
  27. // const model = view.model.occupants.where({'nick': name})[0];
  28. // const index = view.model.occupants.indexOf(model);
  29. // expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(name);
  30. });
  31. done();
  32. }));
  33. xit("adds hundreds of contacts to the roster",
  34. mock.initConverse(
  35. ['rosterGroupsFetched'], {},
  36. function (done, _converse) {
  37. _converse.roster_groups = false;
  38. test_utils.openControlBox(_converse);
  39. expect(_converse.roster.pluck('jid').length).toBe(0);
  40. var stanza = $iq({
  41. to: _converse.connection.jid,
  42. type: 'result',
  43. id: 'roster_1'
  44. }).c('query', {
  45. xmlns: 'jabber:iq:roster'
  46. });
  47. _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
  48. var i;
  49. for (i=0; i<50; i++) {
  50. stanza = stanza.c('item', {
  51. jid: Math.random().toString().replace('0.', '')+'@example.net',
  52. subscription:'both'
  53. }).c('group').t(group).up().up();
  54. }
  55. });
  56. _converse.roster.onReceivedFromServer(stanza.tree());
  57. return u.waitUntil(function () {
  58. var $group = _converse.rosterview.$el.find('.roster-group')
  59. return $group.length && u.isVisible($group[0]);
  60. }).then(function () {
  61. var count = 0;
  62. _converse.roster.each(function (contact) {
  63. if (count < 10) {
  64. contact.set('chat_status', 'online');
  65. count += 1;
  66. }
  67. });
  68. return u.waitUntil(function () {
  69. return _converse.rosterview.$el.find('li.online').length
  70. })
  71. }).then(done);
  72. }));
  73. xit("adds hundreds of contacts to the roster, with roster groups",
  74. mock.initConverse(
  75. ['rosterGroupsFetched'], {},
  76. function (done, _converse) {
  77. // _converse.show_only_online_users = true;
  78. _converse.roster_groups = true;
  79. test_utils.openControlBox(_converse);
  80. expect(_converse.roster.pluck('jid').length).toBe(0);
  81. var stanza = $iq({
  82. to: _converse.connection.jid,
  83. type: 'result',
  84. id: 'roster_1'
  85. }).c('query', {
  86. xmlns: 'jabber:iq:roster'
  87. });
  88. _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
  89. var i;
  90. for (i=0; i<100; i++) {
  91. stanza = stanza.c('item', {
  92. jid: Math.random().toString().replace('0.', '')+'@example.net',
  93. subscription:'both'
  94. }).c('group').t(group).up().up();
  95. }
  96. });
  97. _converse.roster.onReceivedFromServer(stanza.tree());
  98. return u.waitUntil(function () {
  99. var $group = _converse.rosterview.$el.find('.roster-group')
  100. return $group.length && u.isVisible($group[0]);
  101. }).then(function () {
  102. _.each(['Friends', 'Colleagues', 'Family', 'Acquaintances'], function (group) {
  103. var count = 0;
  104. _converse.roster.each(function (contact) {
  105. if (_.includes(contact.get('groups'), group)) {
  106. if (count < 10) {
  107. contact.set('chat_status', 'online');
  108. count += 1;
  109. }
  110. }
  111. });
  112. });
  113. return u.waitUntil(function () {
  114. return _converse.rosterview.$el.find('li.online').length
  115. })
  116. }).then(done);
  117. }));
  118. });
  119. }));