mirror of
https://github.com/zulip/zulip.git
synced 2026-06-03 21:01:43 +08:00
For `dm`, `dm-including` and `sender` operators, we use user ids as operands instead of emails.
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
|
|
const {make_realm} = require("./lib/example_realm.cjs");
|
|
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
|
|
const {noop, run_test} = require("./lib/test.cjs");
|
|
|
|
const activity = mock_esm("../src/activity");
|
|
const buddy_list_presence = mock_esm("../src/buddy_list_presence");
|
|
const scroll_util = mock_esm("../src/scroll_util");
|
|
const pm_list = mock_esm("../src/pm_list");
|
|
const util = mock_esm("../src/util");
|
|
|
|
const state_data = zrequire("state_data");
|
|
const activity_ui = zrequire("activity_ui");
|
|
|
|
run_test("redraw", ({override, override_rewire}) => {
|
|
override_rewire(activity_ui, "build_user_sidebar", noop);
|
|
activity_ui.set_cursor_and_filter();
|
|
override(pm_list, "update_private_messages", noop);
|
|
override(buddy_list_presence, "update_indicators", noop);
|
|
|
|
activity_ui.redraw();
|
|
});
|
|
|
|
run_test("initialize", ({override, override_rewire}) => {
|
|
const realm = make_realm();
|
|
state_data.set_realm(realm);
|
|
|
|
override(realm, "server_presence_ping_interval_seconds", 42);
|
|
|
|
override_rewire(activity_ui, "set_cursor_and_filter", noop);
|
|
override_rewire(activity_ui, "build_user_sidebar", noop);
|
|
|
|
override(scroll_util, "get_scroll_element", (selector) => {
|
|
assert.equal(selector.selector, "#buddy_list_wrapper");
|
|
return {
|
|
on(action, callback) {
|
|
assert.equal(action, "scroll");
|
|
// We don't test the actual logic of the scroll
|
|
// handler here. We did our job to set it up.
|
|
assert.ok(callback !== undefined);
|
|
},
|
|
};
|
|
});
|
|
|
|
let expected_redraw;
|
|
let num_presence_calls = 0;
|
|
|
|
override(activity, "send_presence_to_server", (redraw) => {
|
|
num_presence_calls += 1;
|
|
assert.equal(redraw, expected_redraw);
|
|
});
|
|
|
|
let f_to_call_periodically;
|
|
|
|
override(util, "call_function_periodically", (f, delay) => {
|
|
f_to_call_periodically = f;
|
|
assert.equal(delay, 42000);
|
|
});
|
|
|
|
let my_user_id;
|
|
|
|
function narrow_by_user_id(user_id) {
|
|
my_user_id = user_id;
|
|
}
|
|
|
|
activity_ui.initialize({narrow_by_user_id});
|
|
|
|
assert.equal(my_user_id, undefined);
|
|
activity_ui.get_narrow_by_user_id_function_for_test_code()(1);
|
|
assert.equal(my_user_id, 1);
|
|
|
|
// Simulate the subsequent calls to
|
|
// activity.send_presence_to_server.
|
|
expected_redraw = activity_ui.redraw;
|
|
|
|
assert.equal(num_presence_calls, 1);
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
assert.equal(num_presence_calls, 6);
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
f_to_call_periodically();
|
|
assert.equal(num_presence_calls, 11);
|
|
});
|