Files
zulip/frontend_tests/node_tests/buddy_data.js
Steve Howell 54389f7b41 buddy list: Shrink overly large lists.
If we would have more than 600 people in a buddy list, it's kind of
cumbersome to scroll through it, and it's also expensive to render
it (short of doing progressive rendering, which adds a lot of
complexity).

So, as a short term measure, we filter out offline users whenever the
list would exceed 600 users.  Note that if you are doing a search that
narrows to fewer 600 users, the offline users will appear again.
2018-04-22 20:08:08 -07:00

51 lines
1.2 KiB
JavaScript

zrequire('people');
zrequire('presence');
zrequire('util');
zrequire('buddy_data');
// The buddy_data module is mostly tested indirectly through
// activity.js, but we should feel free to add direct tests
// here.
set_global('page_params', {});
(function make_people() {
_.each(_.range(1000, 2000), (i) => {
const person = {
user_id: i,
full_name: `Person ${i}`,
email: `person${i}@example.com`,
};
people.add_in_realm(person);
});
}());
(function activate_people() {
const server_time = 9999;
const info = {
website: {
status: "active",
timestamp: server_time,
},
};
// Make 400 of the users active
_.each(_.range(1000, 1400), (user_id) => {
presence.set_user_status(user_id, info, server_time);
});
// And then 300 not active
_.each(_.range(1400, 1700), (user_id) => {
presence.set_user_status(user_id, {}, server_time);
});
}());
(function test_user_ids() {
const user_ids = buddy_data.get_filtered_and_sorted_user_ids();
// Even though we have 900 users, we only get the 400 active
// users. This is a consequence of buddy_data.maybe_shrink_list.
assert.equal(user_ids.length, 400);
}());