tests: Unmock state_data.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-10-09 13:44:13 -07:00 committed by Tim Abbott
parent 95153b3f0c
commit e84bb9ff2c
63 changed files with 265 additions and 62 deletions

View File

@ -13,7 +13,7 @@ const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespac
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const $window_stub = $.create("window-stub");
set_global("to_$", () => $window_stub);
@ -52,8 +52,13 @@ const peer_data = zrequire("peer_data");
const message_lists = zrequire("message_lists");
const util = zrequire("util");
const {Filter} = zrequire("../src/filter");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -6,7 +6,7 @@ const _ = require("lodash");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => true,
@ -24,8 +24,13 @@ const user_status = zrequire("user_status");
const buddy_data = zrequire("buddy_data");
const {Filter} = zrequire("filter");
const message_lists = zrequire("message_lists");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -22,8 +22,10 @@ const message_viewport = mock_esm("../src/message_viewport");
const buddy_data = zrequire("buddy_data");
const {BuddyList} = zrequire("buddy_list");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
initialize_user_settings({user_settings: {}});
function init_simulated_scrolling() {

View File

@ -8,7 +8,7 @@ const {mock_banners} = require("./lib/compose_banner");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const user_groups = zrequire("user_groups");
@ -58,9 +58,14 @@ const compose_setup = zrequire("compose_setup");
const drafts = zrequire("drafts");
const echo = zrequire("echo");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -7,7 +7,6 @@ const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
const user_groups = zrequire("user_groups");
@ -88,6 +87,10 @@ const compose_reply = zrequire("compose_reply");
const message_lists = zrequire("message_lists");
const stream_data = zrequire("stream_data");
const compose_recipient = zrequire("compose_recipient");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
const start = compose_actions.start;
const cancel = compose_actions.cancel;

View File

@ -10,6 +10,9 @@ const input_pill = mock_esm("../src/input_pill");
const people = zrequire("people");
const compose_pm_pill = zrequire("compose_pm_pill");
const {set_realm} = zrequire("state_data");
set_realm({});
let pills = {
pill: {},

View File

@ -6,7 +6,6 @@ const {$t} = require("./lib/i18n");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
set_global("navigator", {});
@ -27,8 +26,11 @@ const channel = mock_esm("../src/channel");
const compose_reply = zrequire("compose_reply");
const message_lists = zrequire("message_lists");
const text_field_edit = mock_esm("text-field-edit");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
initialize_user_settings({user_settings: {}});
const alice = {

View File

@ -8,7 +8,6 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user, realm} = require("./lib/zpage_params");
const compose_banner = zrequire("compose_banner");
const compose_pm_pill = zrequire("compose_pm_pill");
@ -19,10 +18,16 @@ const people = zrequire("people");
const resolved_topic = zrequire("../shared/src/resolved_topic");
const settings_config = zrequire("settings_config");
const settings_data = mock_esm("../src/settings_data");
const {set_current_user, set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const compose_recipient = zrequire("/compose_recipient");
const user_groups = zrequire("user_groups");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
const me = {
email: "me@example.com",
user_id: 30,

View File

@ -6,7 +6,7 @@ const events = require("./lib/events");
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const channel = mock_esm("../src/channel");
const compose_closed_ui = mock_esm("../src/compose_closed_ui");
@ -27,6 +27,12 @@ set_global(
const server_events_dispatch = zrequire("server_events_dispatch");
const compose_setup = zrequire("compose_setup");
const {set_current_user, set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
function stub_out_video_calls() {
const $elem = $(".compose-control-buttons-container .video_link");

View File

@ -6,7 +6,6 @@ const {mock_banners} = require("./lib/compose_banner");
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user, realm} = require("./lib/zpage_params");
let autosize_called;
@ -57,8 +56,13 @@ const compose_pm_pill = zrequire("compose_pm_pill");
const compose_recipient = zrequire("compose_recipient");
const composebox_typeahead = zrequire("composebox_typeahead");
const settings_config = zrequire("settings_config");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -8,12 +8,7 @@ const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {
current_user,
page_params,
realm,
realm_user_settings_defaults,
} = require("./lib/zpage_params");
const {page_params, realm_user_settings_defaults} = require("./lib/zpage_params");
const event_fixtures = events.fixtures;
const test_message = events.test_message;
@ -102,8 +97,13 @@ const user_group_edit = mock_esm("../src/user_group_edit");
const overlays = mock_esm("../src/overlays");
mock_esm("../src/giphy");
const {Filter} = zrequire("filter");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -7,7 +7,6 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {realm} = require("./lib/zpage_params");
const event_fixtures = events.fixtures;
const test_user = events.test_user;
@ -27,9 +26,13 @@ const compose_state = zrequire("compose_state");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const server_events_dispatch = zrequire("server_events_dispatch");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const sub_store = zrequire("sub_store");
const realm = {};
set_realm(realm);
people.add_active_user(test_user);
const me = {

View File

@ -7,7 +7,6 @@ const MockDate = require("mockdate");
const {mock_esm, zrequire} = require("./lib/namespace");
const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test");
const {current_user} = require("./lib/zpage_params");
const compose_notifications = mock_esm("../src/compose_notifications");
const markdown = mock_esm("../src/markdown");
@ -70,9 +69,13 @@ message_lists.non_rendered_data = () => [];
const echo = zrequire("echo");
const echo_state = zrequire("echo_state");
const people = zrequire("people");
const {set_current_user} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const current_user = {};
set_current_user(current_user);
const general_sub = {
stream_id: 101,
name: "general",

View File

@ -12,8 +12,11 @@ const {run_test} = require("./lib/test");
// core piece of code that makes things work.
const {Filter} = zrequire("../src/filter");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
set_realm({});
const denmark_stream = make_stream({
color: "blue",
name: "Denmark",

View File

@ -65,6 +65,9 @@ const user_profile = mock_esm("../src/user_profile");
// Use real versions of these modules.
const people = zrequire("people");
const server_events_dispatch = zrequire("server_events_dispatch");
const {set_current_user} = zrequire("state_data");
set_current_user({});
const bob = make_bot({
email: "bob@example.com",

View File

@ -6,7 +6,6 @@ const {make_user} = require("./lib/example_user");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user} = require("./lib/zpage_params");
mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => true,
@ -30,9 +29,13 @@ mock_esm("../src/settings_data", {
const {Filter} = zrequire("filter");
const message_lists = zrequire("message_lists");
const people = zrequire("people");
const {set_current_user} = zrequire("state_data");
const typing_data = zrequire("typing_data");
const typing_events = zrequire("typing_events");
const current_user = {};
set_current_user(current_user);
// Let us add a few users to use as typists.
const anna = make_user({
email: "anna@example.com",

View File

@ -8,7 +8,7 @@ const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const message_store = mock_esm("../src/message_store");
const user_topics = mock_esm("../src/user_topics");
@ -17,8 +17,13 @@ const resolved_topic = zrequire("../shared/src/resolved_topic");
const stream_data = zrequire("stream_data");
const people = zrequire("people");
const {Filter} = zrequire("../src/filter");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
initialize_user_settings({user_settings: {}});
const stream_message = "stream";

View File

@ -4,9 +4,12 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {realm} = require("./lib/zpage_params");
const gear_menu_util = zrequire("gear_menu_util");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
run_test("version_display_string", ({override}) => {
let expected_version_display_string;

View File

@ -129,8 +129,6 @@ test.set_verbose(files.length === 1);
require("../../src/billing/page_params");
namespace.mock_esm("../../src/page_params", zpage_params);
require("../../src/page_params");
namespace.mock_esm("../../src/state_data", zpage_params);
require("../../src/state_data");
namespace.mock_esm("../../src/realm_user_settings_defaults", zpage_params);
require("../../src/realm_user_settings_defaults");

View File

@ -1,26 +1,14 @@
"use strict";
exports.current_user = {};
exports.page_params = {};
exports.realm = {};
exports.realm_user_settings_defaults = {};
exports.reset = () => {
for (const field in exports.current_user) {
if (Object.hasOwn(exports.current_user, field)) {
delete exports.current_user[field];
}
}
for (const field in exports.page_params) {
if (Object.hasOwn(exports.page_params, field)) {
delete exports.page_params[field];
}
}
for (const field in exports.realm) {
if (Object.hasOwn(exports.realm, field)) {
delete exports.realm[field];
}
}
for (const field in exports.realm_user_settings_defaults) {
if (Object.hasOwn(exports.realm_user_settings_defaults, field)) {
delete exports.realm_user_settings_defaults[field];

View File

@ -53,10 +53,12 @@ const markdown_config = zrequire("markdown_config");
const markdown = zrequire("markdown");
const people = zrequire("people");
const pygments_data = zrequire("pygments_data");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -4,15 +4,20 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, realm} = require("./lib/zpage_params");
const message_edit = zrequire("message_edit");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
const is_content_editable = message_edit.is_content_editable;
const settings_data = mock_esm("../src/settings_data");
const realm = {};
set_realm(realm);
const current_user = {};
set_current_user(current_user);
run_test("is_content_editable", ({override}) => {
// You can't edit a null message
assert.equal(is_content_editable(null), false);

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
const message_edit = mock_esm("../src/message_edit");
const message_lists = mock_esm("../src/message_lists");
@ -25,11 +24,15 @@ const people = zrequire("people");
const message_events = zrequire("message_events");
message_events.__Rewire__("update_views_filtered_on_message_property", () => {});
const message_helper = zrequire("message_helper");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const unread = zrequire("unread");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
initialize_user_settings({user_settings: {}});
const alice = {

View File

@ -7,7 +7,6 @@ const {make_stub} = require("./lib/stub");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user} = require("./lib/zpage_params");
// These unit tests for web/src/message_list.ts emphasize the model-ish
// aspects of the MessageList class. We have to stub out a few functions
@ -42,6 +41,10 @@ mock_esm("../src/message_list_view", {
MessageListView,
});
const {Filter} = zrequire("filter");
const {set_current_user} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
run_test("basics", ({override}) => {
override(activity_ui, "build_user_sidebar", noop);

View File

@ -27,8 +27,10 @@ const pm_conversations = zrequire("pm_conversations");
const message_helper = zrequire("message_helper");
const message_store = zrequire("message_store");
const message_user_ids = zrequire("message_user_ids");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
initialize_user_settings({user_settings: {}});
const denmark = {

View File

@ -6,7 +6,7 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const hash_util = zrequire("hash_util");
const compose_state = zrequire("compose_state");
@ -19,9 +19,13 @@ const narrow_title = zrequire("narrow_title");
const recent_view_util = zrequire("recent_view_util");
const inbox_util = zrequire("inbox_util");
const message_lists = zrequire("message_lists");
const {set_current_user, set_realm} = zrequire("state_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
set_current_user({});
const realm = {};
set_realm(realm);
initialize_user_settings({user_settings: {}});
mock_esm("../src/compose_banner", {

View File

@ -80,6 +80,9 @@ const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const message_view = zrequire("message_view");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
set_realm({});
const denmark = {
subscribed: false,

View File

@ -18,6 +18,10 @@ const unread = zrequire("unread");
// The main code we are testing lives here.
const narrow_state = zrequire("narrow_state");
const message_lists = zrequire("message_lists");
const {set_current_user, set_realm} = zrequire("state_data");
set_current_user({});
set_realm({});
const alice = {
email: "alice@example.com",

View File

@ -6,7 +6,7 @@ const {addDays} = require("date-fns");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
page_params.is_spectator = false;
@ -16,6 +16,12 @@ const timerender = mock_esm("../src/timerender");
const {localstorage} = zrequire("localstorage");
const navbar_alerts = zrequire("navbar_alerts");
const {set_current_user, set_realm} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
function test(label, f) {
run_test(label, (helpers) => {

View File

@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user, page_params} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
mock_esm("../src/electron_bridge");
mock_esm("../src/spoilers", {hide_spoilers_in_notification() {}});
@ -15,8 +15,11 @@ const stream_data = zrequire("stream_data");
const desktop_notifications = zrequire("desktop_notifications");
const message_notifications = zrequire("message_notifications");
const {set_current_user} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -15,8 +15,11 @@ const {page_params} = require("./lib/zpage_params");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const {set_current_user} = zrequire("state_data");
const stream_data = zrequire("stream_data");
set_current_user({});
page_params.realm_users = [];
const me = {

View File

@ -10,7 +10,7 @@ const {$t} = require("./lib/i18n");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const message_user_ids = mock_esm("../src/message_user_ids");
const settings_data = mock_esm("../src/settings_data", {
@ -19,9 +19,14 @@ const settings_data = mock_esm("../src/settings_data", {
const muted_users = zrequire("muted_users");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -6,7 +6,7 @@ const {zrequire, mock_esm} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const noop = function () {};
@ -17,10 +17,14 @@ const input_pill = zrequire("input_pill");
const pill_typeahead = zrequire("pill_typeahead");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const user_groups = zrequire("user_groups");
const typeahead_helper = zrequire("typeahead_helper");
const realm = {};
set_realm(realm);
// set global test variables.
let sort_recipients_called = false;
let sort_streams_called = false;

View File

@ -4,12 +4,15 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user} = require("./lib/zpage_params");
const user_topics = zrequire("user_topics");
const muted_users = zrequire("muted_users");
const people = zrequire("people");
const pmc = zrequire("pm_conversations");
const {set_current_user} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
const alice = {
user_id: 1,

View File

@ -23,8 +23,10 @@ const people = zrequire("people");
const pm_conversations = zrequire("pm_conversations");
const pm_list_data = zrequire("pm_list_data");
const message_lists = zrequire("message_lists");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
initialize_user_settings({user_settings: {}});
const alice = {

View File

@ -16,6 +16,9 @@ const {PollData} = zrequire("../shared/src/poll_data");
const poll_widget = zrequire("poll_widget");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
set_realm({});
const me = {
email: "me@zulip.com",

View File

@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {page_params, realm, current_user} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const {Filter} = zrequire("filter");
const {MessageList} = zrequire("message_list");
@ -16,6 +16,7 @@ const people = zrequire("people");
const compose_state = zrequire("compose_state");
const user_groups = zrequire("user_groups");
const {MessageListData} = zrequire("message_list_data");
const {set_current_user, set_realm} = zrequire("state_data");
const noop = function () {};
@ -54,6 +55,11 @@ mock_esm("../src/group_permission_settings", {
},
});
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
// Define test users
const mike = {
user_id: 1000,

View File

@ -4,7 +4,6 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {realm} = require("./lib/zpage_params");
mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => true,
@ -12,8 +11,11 @@ mock_esm("../src/settings_data", {
const people = zrequire("people");
const presence = zrequire("presence");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -7,7 +7,7 @@ const {make_stub} = require("./lib/stub");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user, page_params} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const alice_user_id = 5;
@ -59,8 +59,12 @@ const emoji = zrequire("emoji");
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
const people = zrequire("people");
const reactions = zrequire("reactions");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
set_realm({});
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -200,8 +200,11 @@ const rt = zrequire("recent_view_ui");
const recent_view_util = zrequire("recent_view_util");
const rt_data = zrequire("recent_view_data");
const muted_users = zrequire("muted_users");
const {set_realm} = zrequire("state_data");
const sub_store = zrequire("sub_store");
set_realm({});
for (const stream_id of [stream1, stream2, stream3, stream4, stream6]) {
sub_store.add_hydrated_sub(stream_id, {
color: "",

View File

@ -7,7 +7,6 @@ const {mock_cjs, mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
let clipboard_args;
class Clipboard {
@ -33,8 +32,11 @@ const message_store = mock_esm("../src/message_store");
mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => false,
});
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -4,7 +4,7 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const narrow_state = mock_esm("../src/narrow_state");
const stream_topic_history_util = mock_esm("../src/stream_topic_history_util");
@ -16,6 +16,12 @@ const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
const search = zrequire("search_suggestion");
const {set_current_user, set_realm} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const me = {
email: "myself@zulip.com",

View File

@ -4,7 +4,6 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, realm} = require("./lib/zpage_params");
const bot_data_params = {
realm_bots: [
@ -29,6 +28,12 @@ const bot_data_params = {
const bot_data = zrequire("bot_data");
const settings_bots = zrequire("settings_bots");
const {set_current_user, set_realm} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
bot_data.initialize(bot_data_params);

View File

@ -6,8 +6,10 @@ const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const settings_config = zrequire("settings_config");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -4,13 +4,18 @@ const assert = require("node:assert/strict");
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
const settings_data = zrequire("settings_data");
const settings_config = zrequire("settings_config");
const {set_current_user, set_realm} = zrequire("state_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -17,8 +17,10 @@ mock_esm("../src/settings_data", {
const settings_muted_users = zrequire("settings_muted_users");
const muted_users = zrequire("muted_users");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
initialize_user_settings({user_settings: {}});
run_test("settings", ({override}) => {

View File

@ -7,7 +7,6 @@ const {mock_esm, zrequire, set_global} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user, realm} = require("./lib/zpage_params");
const realm_icon = mock_esm("../src/realm_icon");
@ -26,8 +25,13 @@ const settings_bots = zrequire("settings_bots");
const settings_account = zrequire("settings_account");
const settings_components = zrequire("settings_components");
const settings_org = zrequire("settings_org");
const {set_current_user, set_realm} = zrequire("state_data");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
initialize_user_settings({user_settings: {}});
function test(label, f) {

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user, realm} = require("./lib/zpage_params");
const loading = mock_esm("../src/loading");
@ -50,6 +49,12 @@ const Sortable = {create: noop};
mock_esm("sortablejs", {default: Sortable});
const settings_profile_fields = zrequire("settings_profile_fields");
const {set_current_user, set_realm} = zrequire("state_data");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
function test_populate(opts, template_data) {
with_overrides(({override}) => {

View File

@ -4,11 +4,14 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user} = require("./lib/zpage_params");
const people = zrequire("people");
const {set_current_user} = zrequire("state_data");
const stream_create_subscribers_data = zrequire("stream_create_subscribers_data");
const current_user = {};
set_current_user(current_user);
const me = {
email: "me@zulip.com",
full_name: "Zed", // Zed will sort to the top by virtue of being the current user.

View File

@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {current_user, page_params, realm} = require("./lib/zpage_params");
const {page_params} = require("./lib/zpage_params");
// TODO: Remove after we enable support for
// web_public_streams in production.
@ -18,10 +18,15 @@ const settings_config = zrequire("settings_config");
const sub_store = zrequire("sub_store");
const stream_data = zrequire("stream_data");
const hash_util = zrequire("hash_util");
const {set_current_user, set_realm} = zrequire("state_data");
const stream_settings_data = zrequire("stream_settings_data");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -46,10 +46,14 @@ const narrow_state = zrequire("narrow_state");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const settings_config = zrequire("settings_config");
const {set_current_user, set_realm} = zrequire("state_data");
const stream_create = zrequire("stream_create");
const stream_data = zrequire("stream_data");
const stream_events = zrequire("stream_events");
set_current_user({});
set_realm({});
const george = {
email: "george@zulip.com",
full_name: "George",

View File

@ -4,13 +4,17 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user} = require("./lib/zpage_params");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_pill = zrequire("stream_pill");
const current_user = {};
set_current_user(current_user);
set_realm({});
const denmark = {
stream_id: 101,
name: "Denmark",

View File

@ -25,11 +25,14 @@ mock_esm("../src/hash_parser", {
});
set_global("page_params", {});
const {set_current_user, set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_settings_ui = zrequire("stream_settings_ui");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
set_realm({});
set_current_user({});
initialize_user_settings({user_settings: {}});
run_test("redraw_left_panel", ({mock_template}) => {

View File

@ -12,10 +12,13 @@ const all_messages_data = zrequire("all_messages_data");
const echo_state = zrequire("echo_state");
const unread = zrequire("unread");
const message_store = zrequire("message_store");
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const stream_topic_history_util = zrequire("stream_topic_history_util");
set_realm({});
stream_topic_history.set_update_topic_last_message_id(noop);
function test(label, f) {

View File

@ -31,11 +31,14 @@ const narrow_state = mock_esm("../src/narrow_state", {
stream_id() {},
});
const {set_realm} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const topic_list_data = zrequire("topic_list_data");
const unread = zrequire("unread");
set_realm({});
const general = {
stream_id: 556,
name: "general",

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {current_user} = require("./lib/zpage_params");
const channel = mock_esm("../src/channel");
const reload = mock_esm("../src/reload");
@ -25,8 +24,12 @@ const server_events = mock_esm("../src/server_events");
const people = zrequire("people");
const transmit = zrequire("transmit");
const {set_current_user} = zrequire("state_data");
const stream_data = zrequire("stream_data");
const current_user = {};
set_current_user(current_user);
run_test("transmit_message_ajax", () => {
let success_func_called;
const success = () => {

View File

@ -4,7 +4,6 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {current_user, realm} = require("./lib/zpage_params");
const stream_topic_history = mock_esm("../src/stream_topic_history");
@ -19,12 +18,17 @@ const stream_list_sort = zrequire("stream_list_sort");
const compose_state = zrequire("compose_state");
const emoji = zrequire("emoji");
const pygments_data = zrequire("pygments_data");
const {set_current_user, set_realm} = zrequire("state_data");
const util = zrequire("util");
const ct = zrequire("composebox_typeahead");
const th = zrequire("typeahead_helper");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
const current_user = {};
set_current_user(current_user);
const realm = {};
set_realm(realm);
const user_settings = {};
initialize_user_settings({user_settings});

View File

@ -5,16 +5,20 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
const {current_user} = require("./lib/zpage_params");
const settings_data = mock_esm("../src/settings_data");
const {Filter} = zrequire("filter");
const message_lists = zrequire("message_lists");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
const typing_data = zrequire("typing_data");
const typing_events = zrequire("typing_events");
const current_user = {};
set_current_user(current_user);
set_realm({});
const anna = {
email: "anna@example.com",
full_name: "Anna Karenina",

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
class ClipboardEvent {
constructor({clipboardData}) {
@ -34,6 +33,11 @@ const rows = mock_esm("../src/rows");
const compose_ui = zrequire("compose_ui");
const upload = zrequire("upload");
const message_lists = mock_esm("../src/message_lists");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
message_lists.current = {
id: "1",
};

View File

@ -6,7 +6,6 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const {current_user} = require("./lib/zpage_params");
const message_live_update = mock_esm("../src/message_live_update");
const navbar_alerts = mock_esm("../src/navbar_alerts");
@ -54,8 +53,13 @@ mock_esm("../src/settings_streams", {
const people = zrequire("people");
const settings_config = zrequire("settings_config");
const {set_current_user, set_realm} = zrequire("state_data");
const user_events = zrequire("user_events");
const current_user = {};
set_current_user(current_user);
set_realm({});
const me = {
email: "me@example.com",
user_id: 30,

View File

@ -5,9 +5,12 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {realm} = require("./lib/zpage_params");
const user_groups = zrequire("user_groups");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
run_test("user_groups", () => {
const students = {

View File

@ -5,13 +5,16 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const {realm} = require("./lib/zpage_params");
const people = zrequire("people");
const user_pill = zrequire("user_pill");
const {set_realm} = zrequire("state_data");
const settings_data = mock_esm("../src/settings_data");
const realm = {};
set_realm(realm);
const alice = {
email: "alice@example.com",
user_id: 99,

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {set_global, mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
const {realm} = require("./lib/zpage_params");
const fake_buddy_list = {
scroll_container_selector: "#whatever",
@ -46,6 +45,10 @@ const activity_ui = zrequire("activity_ui");
const buddy_data = zrequire("buddy_data");
const muted_users = zrequire("muted_users");
const people = zrequire("people");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
const me = {
email: "me@zulip.com",