";
});
- override_rewire(drafts, "open_overlay", noop);
override_rewire(drafts, "set_initial_element", noop);
$.create("#drafts_table .draft-row", {children: []});
@@ -440,5 +442,4 @@ test("format_drafts", ({override_rewire, mock_template}) => {
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
drafts.launch();
- timerender.__Rewire__("render_now", stub_render_now);
});
diff --git a/frontend_tests/node_tests/example7.js b/frontend_tests/node_tests/example7.js
index fd3a00325e..0dc5c72a03 100644
--- a/frontend_tests/node_tests/example7.js
+++ b/frontend_tests/node_tests/example7.js
@@ -72,7 +72,7 @@ const denmark_stream = {
subscribed: false,
};
-run_test("unread_ops", ({override, override_rewire}) => {
+run_test("unread_ops", ({override}) => {
stream_data.clear_subscriptions();
stream_data.add_sub(denmark_stream);
message_store.clear_for_testing();
@@ -90,7 +90,7 @@ run_test("unread_ops", ({override, override_rewire}) => {
];
// We don't want recent topics to process message for this test.
- override_rewire(recent_topics_util, "is_visible", () => false);
+ recent_topics_util.set_visible(false);
// Make our test message appear to be unread, so that
// we then need to subsequently process them as read.
diff --git a/frontend_tests/node_tests/example8.js b/frontend_tests/node_tests/example8.js
index 73a5a3b06e..d3931ae1ff 100644
--- a/frontend_tests/node_tests/example8.js
+++ b/frontend_tests/node_tests/example8.js
@@ -5,6 +5,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
+const {page_params} = require("../zjsunit/zpage_params");
/*
Until now, we had seen various testing techniques, learned
@@ -21,8 +22,11 @@ const $ = require("../zjsunit/zjquery");
as that would help better understand the below test.
*/
-const typing_events = zrequire("typing_events");
+const {Filter} = zrequire("filter");
+const narrow_state = zrequire("narrow_state");
const people = zrequire("people");
+const typing_data = zrequire("typing_data");
+const typing_events = zrequire("typing_events");
// Let us add a few users to use as typists.
const anna = {
@@ -65,20 +69,23 @@ people.add_active_user(kitty);
It's usage below will make it more clear to you.
*/
-run_test("typing_events.render_notifications_for_narrow", ({override_rewire, mock_template}) => {
+run_test("typing_events.render_notifications_for_narrow", ({override, mock_template}) => {
// All typists are rendered in `#typing_notifications`.
const $typing_notifications = $("#typing_notifications");
- const two_typing_users_ids = [anna.user_id, vronsky.user_id];
- const two_typing_users = [anna, vronsky];
+ // Narrow to a PM group with four users.
+ override(page_params, "user_id", anna.user_id);
+ const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
+ const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
+ narrow_state.set_current_filter(new Filter([{operator: "pm-with", operand: group_emails}]));
// Based on typing_events.MAX_USERS_TO_DISPLAY_NAME (which is currently 3),
// we display either the list of all users typing (if they do not exceed
// MAX_USERS_TO_DISPLAY_NAME) or 'Several people are typing…'
- // As we are not testing any functionality of `get_users_typing_for_narrow`,
- // let's override it to return two typists.
- override_rewire(typing_events, "get_users_typing_for_narrow", () => two_typing_users_ids);
+ // For now, set two of the users as being typists.
+ typing_data.add_typist(group, anna.user_id);
+ typing_data.add_typist(group, vronsky.user_id);
const two_typing_users_rendered_html = "Two typing users rendered html stub";
@@ -99,7 +106,7 @@ run_test("typing_events.render_notifications_for_narrow", ({override_rewire, moc
// We often use the function in third argument, like below, to make sure
// the arguments passed to the template are what we expect.
mock_template("typing_notifications.hbs", false, (args) => {
- assert.deepEqual(args.users, two_typing_users);
+ assert.deepEqual(args.users, [anna, vronsky]);
assert.ok(!args.several_users); // Whether to show 'Several people are typing…'
return two_typing_users_rendered_html;
});
@@ -124,8 +131,8 @@ run_test("typing_events.render_notifications_for_narrow", ({override_rewire, moc
// Change to having four typists and verify the rendered html has
// 'Several people are typing…' but not the list of users.
- const four_typing_users_ids = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
- override_rewire(typing_events, "get_users_typing_for_narrow", () => four_typing_users_ids);
+ typing_data.add_typist(group, levin.user_id);
+ typing_data.add_typist(group, kitty.user_id);
typing_events.render_notifications_for_narrow();
assert.ok($typing_notifications.html().includes("Several people are typing…"));
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js
index deb321e139..c31bae0898 100644
--- a/frontend_tests/node_tests/filter.js
+++ b/frontend_tests/node_tests/filter.js
@@ -4,6 +4,7 @@ const {strict: assert} = require("assert");
const {mock_esm, with_overrides, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params");
@@ -61,9 +62,9 @@ function make_sub(name, stream_id) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
stream_data.clear_subscriptions();
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -1666,13 +1667,13 @@ test("navbar_helpers", () => {
assert.equal(filter.generate_redirect_url(), default_redirect.redirect_url);
});
-test("error_cases", ({override_rewire}) => {
+test("error_cases", () => {
// This test just gives us 100% line coverage on defensive code that
// should not be reached unless we break other code.
- override_rewire(people, "pm_with_user_ids", () => {});
const predicate = get_predicate([["pm-with", "Joe@example.com"]]);
- assert.ok(!predicate({type: "private"}));
+ blueslip.expect("error", "Empty recipient list in message");
+ assert.ok(!predicate({type: "private", display_recipient: []}));
});
run_test("is_spectator_compatible", () => {
diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js
index 4a3f161c0c..ce17d5751c 100644
--- a/frontend_tests/node_tests/hashchange.js
+++ b/frontend_tests/node_tests/hashchange.js
@@ -22,8 +22,9 @@ const drafts = mock_esm("../../static/js/drafts");
const floating_recipient_bar = mock_esm("../../static/js/floating_recipient_bar");
const info_overlay = mock_esm("../../static/js/info_overlay");
const message_viewport = mock_esm("../../static/js/message_viewport");
-const narrow = zrequire("../../static/js/narrow");
+const narrow = mock_esm("../../static/js/narrow");
const overlays = mock_esm("../../static/js/overlays");
+const recent_topics_ui = mock_esm("../../static/js/recent_topics_ui");
const settings = mock_esm("../../static/js/settings");
const stream_settings_ui = mock_esm("../../static/js/stream_settings_ui");
const ui_util = mock_esm("../../static/js/ui_util");
@@ -39,9 +40,6 @@ const hash_util = zrequire("hash_util");
const hashchange = zrequire("hashchange");
const stream_data = zrequire("stream_data");
-const recent_topics_util = zrequire("recent_topics_util");
-const recent_topics_ui = zrequire("recent_topics_ui");
-
run_test("operators_round_trip", () => {
let operators;
let hash;
@@ -117,7 +115,7 @@ run_test("people_slugs", () => {
assert.equal(hash, "#narrow/pm-with/42-alice");
});
-function test_helper({override, override_rewire, change_tab}) {
+function test_helper({override, change_tab}) {
let events = [];
let narrow_terms;
@@ -143,7 +141,7 @@ function test_helper({override, override_rewire, change_tab}) {
events.push("change_tab_to " + hash);
});
- override_rewire(narrow, "activate", (terms) => {
+ override(narrow, "activate", (terms) => {
narrow_terms = terms;
events.push("narrow.activate");
});
@@ -164,15 +162,14 @@ function test_helper({override, override_rewire, change_tab}) {
};
}
-run_test("hash_interactions", ({override, override_rewire}) => {
+run_test("hash_interactions", ({override}) => {
$window_stub = $.create("window-stub");
user_settings.default_view = "recent_topics";
- override_rewire(recent_topics_util, "is_visible", () => false);
- const helper = test_helper({override, override_rewire, change_tab: true});
+ const helper = test_helper({override, change_tab: true});
let recent_topics_ui_shown = false;
- override_rewire(recent_topics_ui, "show", () => {
+ override(recent_topics_ui, "show", () => {
recent_topics_ui_shown = true;
});
window.location.hash = "#unknown_hash";
@@ -317,10 +314,8 @@ run_test("hash_interactions", ({override, override_rewire}) => {
helper.assert_events([[ui_util, "blur_active_element"]]);
});
-run_test("save_narrow", ({override, override_rewire}) => {
- override_rewire(recent_topics_util, "is_visible", () => false);
-
- const helper = test_helper({override, override_rewire});
+run_test("save_narrow", ({override}) => {
+ const helper = test_helper({override});
let operators = [{operator: "is", operand: "private"}];
diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js
index 871184eeeb..fb7eefa936 100644
--- a/frontend_tests/node_tests/lightbox.js
+++ b/frontend_tests/node_tests/lightbox.js
@@ -16,20 +16,20 @@ mock_esm("../../static/js/overlays", {
mock_esm("../../static/js/popovers", {
hide_all: () => {},
});
+const rows = mock_esm("../../static/js/rows");
const message_store = mock_esm("../../static/js/message_store");
-const rows = zrequire("rows");
const lightbox = zrequire("lightbox");
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
lightbox.clear_for_testing();
- f({override, override_rewire});
+ f(helpers);
});
}
-test("pan_and_zoom", ({override_rewire}) => {
+test("pan_and_zoom", ({override}) => {
const $img = $.create("img-stub");
const $link = $.create("link-stub");
const $msg = $.create("msg-stub");
@@ -39,7 +39,7 @@ test("pan_and_zoom", ({override_rewire}) => {
$img.set_parent($link);
$link.closest = () => $msg;
- override_rewire(rows, "id", ($row) => {
+ override(rows, "id", ($row) => {
assert.equal($row, $msg);
return 1234;
});
@@ -53,20 +53,20 @@ test("pan_and_zoom", ({override_rewire}) => {
return "message-stub";
};
- override_rewire(lightbox, "render_lightbox_list_images", () => {});
+ $.create(".focused_table .message_inline_image img", {children: []});
const open_image = lightbox.build_open_image_function();
open_image($img);
assert.equal(fetched_zid, 1234);
});
-test("youtube", ({override_rewire}) => {
+test("youtube", ({override}) => {
const href = "https://youtube.com/some-random-clip";
const $img = $.create("img-stub");
const $link = $.create("link-stub");
const $msg = $.create("msg-stub");
- override_rewire(rows, "id", ($row) => {
+ override(rows, "id", ($row) => {
assert.equal($row, $msg);
return 4321;
});
@@ -86,7 +86,7 @@ test("youtube", ({override_rewire}) => {
$link.closest = () => $msg;
$link.attr("href", href);
- override_rewire(lightbox, "render_lightbox_list_images", () => {});
+ $.create(".focused_table .message_inline_image img", {children: []});
const open_image = lightbox.build_open_image_function();
open_image($img);
diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js
index 4625a4016f..036195ab98 100644
--- a/frontend_tests/node_tests/markdown.js
+++ b/frontend_tests/node_tests/markdown.js
@@ -181,10 +181,10 @@ markdown.initialize(markdown_config.get_helpers());
linkifiers.initialize(example_realm_linkifiers);
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
page_params.realm_users = [];
linkifiers.update_linkifier_rules(example_realm_linkifiers);
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -824,7 +824,7 @@ test("parse_non_message", () => {
assert.equal(markdown.parse_non_message("type `/day`"), "type /day
");
});
-test("missing unicode emojis", ({override_rewire}) => {
+test("missing unicode emojis", ({override}) => {
const message = {raw_content: "\u{1F6B2}"};
markdown.apply_markdown(message);
@@ -833,11 +833,8 @@ test("missing unicode emojis", ({override_rewire}) => {
':bike:
',
);
- override_rewire(emoji, "get_emoji_name", (codepoint) => {
- // Now simulate that we don't know any emoji names.
- assert.equal(codepoint, "1f6b2");
- // return undefined
- });
+ // Now simulate that we don't know this emoji name.
+ override(emoji_codes.codepoint_to_name, "1f6b2", undefined);
markdown.initialize(markdown_config.get_helpers());
markdown.apply_markdown(message);
diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js
index 557c7550f2..2d05639abb 100644
--- a/frontend_tests/node_tests/message_list_data.js
+++ b/frontend_tests/node_tests/message_list_data.js
@@ -2,7 +2,7 @@
const {strict: assert} = require("assert");
-const {with_overrides, zrequire} = require("../zjsunit/namespace");
+const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip");
@@ -143,26 +143,20 @@ run_test("muting", () => {
{id: 9, type: "private", to_user_ids: "9", sender_id: 11}, // 1:1 PM to non-muted
];
+ muted_topics.add_muted_topic(1, "muted");
+ muted_users.add_muted_user(10);
+
// `messages_filtered_for_topic_mutes` should skip filtering
// messages if `excludes_muted_topics` is false.
- with_overrides(({disallow_rewire}) => {
- disallow_rewire(muted_topics, "is_topic_muted");
- const res = mld.messages_filtered_for_topic_mutes(msgs);
- assert.deepEqual(res, msgs);
- });
+ assert.deepEqual(mld.messages_filtered_for_topic_mutes(msgs), msgs);
// If we are in a 1:1 PM narrow, `messages_filtered_for_user_mutes` should skip
// filtering messages.
- with_overrides(({disallow_rewire}) => {
- disallow_rewire(muted_users, "is_user_muted");
- const res = mld.messages_filtered_for_user_mutes(msgs);
- assert.deepEqual(res, msgs);
- });
+ assert.deepEqual(mld.messages_filtered_for_user_mutes(msgs), msgs);
// Test actual behaviour of `messages_filtered_for_*` methods.
mld.excludes_muted_topics = true;
mld.filter = new Filter([{operator: "stream", operand: "general"}]);
- muted_topics.add_muted_topic(1, "muted");
const res = mld.messages_filtered_for_topic_mutes(msgs);
assert.deepEqual(res, [
{id: 2, type: "stream", stream_id: 1, topic: "whatever"},
@@ -177,7 +171,6 @@ run_test("muting", () => {
{id: 9, type: "private", to_user_ids: "9", sender_id: 11},
]);
- muted_users.add_muted_user(10);
const res_user = mld.messages_filtered_for_user_mutes(msgs);
assert.deepEqual(res_user, [
// `messages_filtered_for_user_mutes` does not affect stream messages
diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js
index 898c781e22..644b8af2c2 100644
--- a/frontend_tests/node_tests/narrow.js
+++ b/frontend_tests/node_tests/narrow.js
@@ -16,6 +16,7 @@ const stream_data = zrequire("stream_data");
const {Filter} = zrequire("../js/filter");
const narrow = zrequire("narrow");
+const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
mock_esm("../../static/js/spectators", {
login_to_access: () => {},
});
@@ -653,7 +654,7 @@ run_test("narrow_to_compose_target streams", ({override_rewire}) => {
assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);
});
-run_test("narrow_to_compose_target PMs", ({override_rewire}) => {
+run_test("narrow_to_compose_target PMs", ({override, override_rewire}) => {
const args = {called: false};
override_rewire(narrow, "activate", (operators, opts) => {
args.operators = operators;
@@ -662,7 +663,7 @@ run_test("narrow_to_compose_target PMs", ({override_rewire}) => {
});
let emails;
- override_rewire(compose_state, "private_message_recipient", () => emails);
+ override(compose_pm_pill, "get_emails", () => emails);
compose_state.set_message_type("private");
people.add_active_user(ray);
diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.js
index 213876f3a0..e3602baf4a 100644
--- a/frontend_tests/node_tests/notifications.js
+++ b/frontend_tests/node_tests/notifications.js
@@ -4,6 +4,7 @@ const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const $ = require("../zjsunit/zjquery");
const {page_params, user_settings} = require("../zjsunit/zpage_params");
// Dependencies
@@ -20,7 +21,6 @@ set_global("navigator", _navigator);
const muted_topics = zrequire("muted_topics");
const stream_data = zrequire("stream_data");
-const ui = zrequire("ui");
const spoilers = zrequire("spoilers");
spoilers.hide_spoilers_in_notification = () => {};
@@ -50,14 +50,14 @@ stream_data.add_sub(muted);
muted_topics.add_muted_topic(general.stream_id, "muted topic");
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
page_params.is_admin = false;
page_params.realm_users = [];
user_settings.enable_desktop_notifications = true;
user_settings.enable_sounds = true;
user_settings.wildcard_mentions_notify = true;
user_settings.notification_sound = "ding";
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -280,8 +280,8 @@ test("message_is_notifiable", () => {
assert.equal(notifications.message_is_notifiable(message), true);
});
-test("basic_notifications", ({override_rewire}) => {
- override_rewire(ui, "replace_emoji_with_text", () => {});
+test("basic_notifications", () => {
+ $("").set_find_results(".emoji", {replaceWith() {}});
let n; // Object for storing all notification data for assertions.
let last_closed_message_id = null;
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index ff24117586..f9d245d8a0 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -62,9 +62,9 @@ function initialize() {
}
function test_people(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
initialize();
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -815,7 +815,7 @@ test_people("message_methods", () => {
assert.equal(people.sender_is_guest(message), false);
});
-test_people("extract_people_from_message", ({override_rewire}) => {
+test_people("extract_people_from_message", () => {
let message = {
type: "stream",
sender_full_name: maria.full_name,
@@ -824,26 +824,12 @@ test_people("extract_people_from_message", ({override_rewire}) => {
};
assert.ok(!people.is_known_user_id(maria.user_id));
- let reported;
- override_rewire(people, "report_late_add", (user_id, email) => {
- assert.equal(user_id, maria.user_id);
- assert.equal(email, maria.email);
- reported = true;
- });
-
+ blueslip.expect("error", `Added user late: user_id=${maria.user_id} email=${maria.email}`);
people.extract_people_from_message(message);
assert.ok(people.is_known_user_id(maria.user_id));
- assert.ok(reported);
+ blueslip.reset();
// Get line coverage
- people.__Rewire__(
- "report_late_add",
- /* istanbul ignore next */
- () => {
- throw new Error("unexpected late add");
- },
- );
-
message = {
type: "private",
display_recipient: [unknown_user],
diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js
index 3cebb35fef..c414860d57 100644
--- a/frontend_tests/node_tests/people_errors.js
+++ b/frontend_tests/node_tests/people_errors.js
@@ -40,7 +40,7 @@ run_test("is_my_user_id", () => {
assert.equal(people.is_my_user_id(me.user_id.toString()), true);
});
-run_test("blueslip", ({override_rewire}) => {
+run_test("blueslip", () => {
const unknown_email = "alicebobfred@example.com";
blueslip.expect("debug", "User email operand unknown: " + unknown_email);
@@ -104,10 +104,9 @@ run_test("blueslip", ({override_rewire}) => {
const reply_to = people.pm_reply_to(message);
assert.ok(reply_to.includes("?"));
- override_rewire(people, "pm_with_user_ids", () => [42]);
- override_rewire(people, "get_by_user_id", () => {});
+ blueslip.expect("error", "Unknown user_id in get_by_user_id: 42");
blueslip.expect("error", "Unknown people in message");
- const uri = people.pm_with_url({});
+ const uri = people.pm_with_url({type: "private", display_recipient: [{id: 42}]});
assert.equal(uri.indexOf("unk"), uri.length - 3);
blueslip.expect("error", "Undefined field id");
diff --git a/frontend_tests/node_tests/pm_list_data.js b/frontend_tests/node_tests/pm_list_data.js
index 85e509b14d..6fa64a6452 100644
--- a/frontend_tests/node_tests/pm_list_data.js
+++ b/frontend_tests/node_tests/pm_list_data.js
@@ -96,10 +96,10 @@ people.add_active_user(bot_test);
people.initialize_current_user(me.user_id);
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
narrow_state.reset_current_filter();
pm_conversations.clear_for_testing();
- f({override, override_rewire});
+ f(helpers);
});
}
diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js
index 3d10e269aa..823bd92a5b 100644
--- a/frontend_tests/node_tests/popovers.js
+++ b/frontend_tests/node_tests/popovers.js
@@ -3,13 +3,18 @@
const {strict: assert} = require("assert");
const {$t} = require("../zjsunit/i18n");
-const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
+const {mock_cjs, mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params");
const noop = function () {};
+class Clipboard {
+ on() {}
+}
+mock_cjs("clipboard", Clipboard);
+
const rows = mock_esm("../../static/js/rows");
mock_esm("../../static/js/emoji_picker", {
hide_emoji_popover: noop,
@@ -97,16 +102,13 @@ function make_image_stubber() {
}
function test_ui(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (handlers) => {
page_params.is_admin = false;
page_params.realm_email_address_visibility = 3;
page_params.custom_profile_fields = [];
- override_rewire(popovers, "clipboard_enable", () => ({
- on: noop,
- }));
popovers.clear_for_testing();
popovers.register_click_handlers();
- f({override, override_rewire, mock_template});
+ f(handlers);
});
}
@@ -214,7 +216,7 @@ test_ui("sender_hover", ({override, mock_template}) => {
// todo: load image
});
-test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
+test_ui("actions_popover", ({override, mock_template}) => {
override($.fn, "popover", noop);
const $target = $.create("click target");
@@ -226,6 +228,7 @@ test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
topic: "Actions (1)",
type: "stream",
stream_id: 123,
+ sent_by_me: true,
};
message_lists.current.get = (msg_id) => {
@@ -240,7 +243,9 @@ test_ui("actions_popover", ({override, override_rewire, mock_template}) => {
};
};
- override_rewire(message_edit, "get_editability", () => 4);
+ override(page_params, "realm_allow_message_editing", true);
+ override(page_params, "realm_message_content_edit_limit_seconds", 0);
+ assert.equal(message_edit.get_editability(message), message_edit.editability_types.FULL);
$target.closest = (sel) => {
assert.equal(sel, ".message_row");
diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js
index 408a40e854..7a6814bc8e 100644
--- a/frontend_tests/node_tests/presence.js
+++ b/frontend_tests/node_tests/presence.js
@@ -2,7 +2,7 @@
const {strict: assert} = require("assert");
-const {mock_esm, with_overrides, zrequire} = require("../zjsunit/namespace");
+const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip");
const {user_settings} = require("../zjsunit/zpage_params");
@@ -100,11 +100,10 @@ test("unknown user", ({override}) => {
// If the server is suspected to be offline or reloading,
// then we suppress errors. The use case here is that we
// haven't gotten info for a brand new user yet.
- with_overrides(({override_rewire}) => {
- override_rewire(watchdog, "suspects_user_is_offline", () => true);
- presence.set_info(presences, now);
- });
+ watchdog.set_suspect_offline(true);
+ presence.set_info(presences, now);
+ watchdog.set_suspect_offline(false);
override(reload_state, "is_in_progress", () => true);
presence.set_info(presences, now);
});
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js
index c4bd7f1734..ff3ab87f94 100644
--- a/frontend_tests/node_tests/reactions.js
+++ b/frontend_tests/node_tests/reactions.js
@@ -110,9 +110,9 @@ people.add_active_user(cali);
people.add_active_user(alexus);
function test(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (helpers) => {
page_params.user_id = alice_user_id;
- f({override, override_rewire, mock_template});
+ f(helpers);
});
}
@@ -357,6 +357,23 @@ test("sending", ({override, override_rewire}) => {
});
});
+function stub_reactions(message_id) {
+ const $message_row = $.create("message-row-stub");
+ const $message_reactions = $.create("reactions-stub");
+ $(".message_table").set_find_results(`[zid='${CSS.escape(message_id)}']`, $message_row);
+ $message_row.set_find_results(".message_reactions", $message_reactions);
+ return $message_reactions;
+}
+
+function stub_reaction(message_id, local_id) {
+ const $reaction = $.create("reaction-stub");
+ stub_reactions(message_id).set_find_results(
+ `[data-reaction-id='${CSS.escape(local_id)}']`,
+ $reaction,
+ );
+ return $reaction;
+}
+
test("set_reaction_count", () => {
const $count_element = $.create("count-stub");
const $reaction_element = $.create("reaction-stub");
@@ -368,32 +385,16 @@ test("set_reaction_count", () => {
assert.equal($count_element.text(), "5");
});
-test("find_reaction", ({override_rewire}) => {
+test("find_reaction", () => {
const message_id = 99;
const local_id = "unicode_emoji,1f44b";
- const $reaction_section = $.create("section-stub");
+ const $reaction = stub_reaction(message_id, local_id);
- const reaction_stub = "reaction-stub";
- $reaction_section.set_find_results(
- `[data-reaction-id='${CSS.escape(local_id)}']`,
- reaction_stub,
- );
-
- override_rewire(reactions, "get_reaction_section", (arg) => {
- assert.equal(arg, message_id);
- return $reaction_section;
- });
-
- assert.equal(reactions.find_reaction(message_id, local_id), reaction_stub);
+ assert.equal(reactions.find_reaction(message_id, local_id), $reaction);
});
test("get_reaction_section", () => {
- const $message_table = $.create(".message_table");
- const $message_row = $.create("some-message-row");
- const $message_reactions = $.create("our-reactions-section");
-
- $message_table.set_find_results(`[zid='${CSS.escape(555)}']`, $message_row);
- $message_row.set_find_results(".message_reactions", $message_reactions);
+ const $message_reactions = stub_reactions(555);
const $section = reactions.get_reaction_section(555);
@@ -587,7 +588,7 @@ test("add_reaction/remove_reaction", ({override}) => {
});
});
-test("view.insert_new_reaction (me w/unicode emoji)", ({override_rewire, mock_template}) => {
+test("view.insert_new_reaction (me w/unicode emoji)", ({mock_template}) => {
const opts = {
message_id: 501,
reaction_type: "unicode_emoji",
@@ -596,13 +597,7 @@ test("view.insert_new_reaction (me w/unicode emoji)", ({override_rewire, mock_te
user_id: alice.user_id,
};
- const $message_reactions = $.create("our-reactions");
-
- override_rewire(reactions, "get_reaction_section", (message_id) => {
- assert.equal(message_id, opts.message_id);
- return $message_reactions;
- });
-
+ const $message_reactions = stub_reactions(opts.message_id);
$message_reactions.find = (selector) => {
assert.equal(selector, ".reaction_button");
return "reaction-button-stub";
@@ -634,7 +629,7 @@ test("view.insert_new_reaction (me w/unicode emoji)", ({override_rewire, mock_te
assert.ok(insert_called);
});
-test("view.insert_new_reaction (them w/zulip emoji)", ({override_rewire, mock_template}) => {
+test("view.insert_new_reaction (them w/zulip emoji)", ({mock_template}) => {
const opts = {
message_id: 502,
reaction_type: "realm_emoji",
@@ -643,13 +638,7 @@ test("view.insert_new_reaction (them w/zulip emoji)", ({override_rewire, mock_te
user_id: bob.user_id,
};
- const $message_reactions = $.create("our-reactions");
-
- override_rewire(reactions, "get_reaction_section", (message_id) => {
- assert.equal(message_id, opts.message_id);
- return $message_reactions;
- });
-
+ const $message_reactions = stub_reactions(opts.message_id);
$message_reactions.find = (selector) => {
assert.equal(selector, ".reaction_button");
return "reaction-button-stub";
@@ -683,7 +672,7 @@ test("view.insert_new_reaction (them w/zulip emoji)", ({override_rewire, mock_te
assert.ok(insert_called);
});
-test("view.update_existing_reaction (me)", ({override_rewire}) => {
+test("view.update_existing_reaction (me)", () => {
const opts = {
message_id: 503,
reaction_type: "unicode_emoji",
@@ -693,21 +682,13 @@ test("view.update_existing_reaction (me)", ({override_rewire}) => {
user_list: [alice.user_id, bob.user_id],
};
- const $our_reaction = $.create("our-reaction-stub");
-
- override_rewire(reactions, "find_reaction", (message_id, local_id) => {
- assert.equal(message_id, opts.message_id);
- assert.equal(local_id, "unicode_emoji,1f3b1");
- return $our_reaction;
- });
-
- override_rewire(reactions, "set_reaction_count", (reaction, count) => {
- assert.equal(reaction, $our_reaction);
- assert.equal(count, 2);
- });
+ const $our_reaction = stub_reaction(opts.message_id, "unicode_emoji,1f3b1");
+ const $reaction_count = $.create("reaction-count-stub");
+ $our_reaction.set_find_results(".message_reaction_count", $reaction_count);
reactions.view.update_existing_reaction(opts);
+ assert.equal($reaction_count.text(), "2");
assert.ok($our_reaction.hasClass("reacted"));
assert.equal(
$our_reaction.attr("aria-label"),
@@ -715,7 +696,7 @@ test("view.update_existing_reaction (me)", ({override_rewire}) => {
);
});
-test("view.update_existing_reaction (them)", ({override_rewire}) => {
+test("view.update_existing_reaction (them)", () => {
const opts = {
message_id: 504,
reaction_type: "unicode_emoji",
@@ -725,21 +706,13 @@ test("view.update_existing_reaction (them)", ({override_rewire}) => {
user_list: [alice.user_id, bob.user_id, cali.user_id, alexus.user_id],
};
- const $our_reaction = $.create("our-reaction-stub");
-
- override_rewire(reactions, "find_reaction", (message_id, local_id) => {
- assert.equal(message_id, opts.message_id);
- assert.equal(local_id, "unicode_emoji,1f3b1");
- return $our_reaction;
- });
-
- override_rewire(reactions, "set_reaction_count", (reaction, count) => {
- assert.equal(reaction, $our_reaction);
- assert.equal(count, 4);
- });
+ const $our_reaction = stub_reaction(opts.message_id, "unicode_emoji,1f3b1");
+ const $reaction_count = $.create("reaction-count-stub");
+ $our_reaction.set_find_results(".message_reaction_count", $reaction_count);
reactions.view.update_existing_reaction(opts);
+ assert.equal($reaction_count.text(), "4");
assert.ok(!$our_reaction.hasClass("reacted"));
assert.equal(
$our_reaction.attr("aria-label"),
@@ -747,7 +720,7 @@ test("view.update_existing_reaction (them)", ({override_rewire}) => {
);
});
-test("view.remove_reaction (me)", ({override_rewire}) => {
+test("view.remove_reaction (me)", () => {
const opts = {
message_id: 505,
reaction_type: "unicode_emoji",
@@ -757,22 +730,14 @@ test("view.remove_reaction (me)", ({override_rewire}) => {
user_list: [bob.user_id, cali.user_id],
};
- const $our_reaction = $.create("our-reaction-stub");
+ const $our_reaction = stub_reaction(opts.message_id, "unicode_emoji,1f3b1");
+ const $reaction_count = $.create("reaction-count-stub");
$our_reaction.addClass("reacted");
-
- override_rewire(reactions, "find_reaction", (message_id, local_id) => {
- assert.equal(message_id, opts.message_id);
- assert.equal(local_id, "unicode_emoji,1f3b1");
- return $our_reaction;
- });
-
- override_rewire(reactions, "set_reaction_count", (reaction, count) => {
- assert.equal(reaction, $our_reaction);
- assert.equal(count, 2);
- });
+ $our_reaction.set_find_results(".message_reaction_count", $reaction_count);
reactions.view.remove_reaction(opts);
+ assert.equal($reaction_count.text(), "2");
assert.ok(!$our_reaction.hasClass("reacted"));
assert.equal(
$our_reaction.attr("aria-label"),
@@ -780,7 +745,7 @@ test("view.remove_reaction (me)", ({override_rewire}) => {
);
});
-test("view.remove_reaction (them)", ({override_rewire}) => {
+test("view.remove_reaction (them)", () => {
const opts = {
message_id: 506,
reaction_type: "unicode_emoji",
@@ -790,23 +755,15 @@ test("view.remove_reaction (them)", ({override_rewire}) => {
user_list: [alice.user_id],
};
- const $our_reaction = $.create("our-reaction-stub");
+ const $our_reaction = stub_reaction(opts.message_id, "unicode_emoji,1f3b1");
+ const $reaction_count = $.create("reaction-count-stub");
$our_reaction.addClass("reacted");
-
- override_rewire(reactions, "find_reaction", (message_id, local_id) => {
- assert.equal(message_id, opts.message_id);
- assert.equal(local_id, "unicode_emoji,1f3b1");
- return $our_reaction;
- });
-
- override_rewire(reactions, "set_reaction_count", (reaction, count) => {
- assert.equal(reaction, $our_reaction);
- assert.equal(count, 1);
- });
+ $our_reaction.set_find_results(".message_reaction_count", $reaction_count);
$our_reaction.addClass("reacted");
reactions.view.remove_reaction(opts);
+ assert.equal($reaction_count.text(), "1");
assert.ok($our_reaction.hasClass("reacted"));
assert.equal(
$our_reaction.attr("aria-label"),
@@ -814,7 +771,7 @@ test("view.remove_reaction (them)", ({override_rewire}) => {
);
});
-test("view.remove_reaction (last person)", ({override_rewire}) => {
+test("view.remove_reaction (last person)", () => {
const opts = {
message_id: 507,
reaction_type: "unicode_emoji",
@@ -824,13 +781,7 @@ test("view.remove_reaction (last person)", ({override_rewire}) => {
user_list: [],
};
- const $our_reaction = $.create("our-reaction-stub");
-
- override_rewire(reactions, "find_reaction", (message_id, local_id) => {
- assert.equal(message_id, opts.message_id);
- assert.equal(local_id, "unicode_emoji,1f3b1");
- return $our_reaction;
- });
+ const $our_reaction = stub_reaction(opts.message_id, "unicode_emoji,1f3b1");
let removed;
$our_reaction.remove = () => {
diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js
index 3ed46d4d26..28cfb8678e 100644
--- a/frontend_tests/node_tests/recent_topics.js
+++ b/frontend_tests/node_tests/recent_topics.js
@@ -107,6 +107,9 @@ const narrow = mock_esm("../../static/js/narrow", {
handle_middle_pane_transition: noop,
has_shown_message_list_view: true,
});
+mock_esm("../../static/js/popovers", {
+ any_active: () => false,
+});
mock_esm("../../static/js/recent_senders", {
get_topic_recent_senders: () => [1, 2],
});
@@ -153,6 +156,7 @@ mock_esm("../../static/js/unread", {
const {all_messages_data} = zrequire("all_messages_data");
const people = zrequire("people");
const rt = zrequire("recent_topics_ui");
+const recent_topics_util = zrequire("recent_topics_util");
const rt_data = zrequire("recent_topics_data");
people.is_my_user_id = (id) => id === 1;
@@ -320,11 +324,11 @@ function stub_out_filter_buttons() {
}
function test(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (helpers) => {
$(".header").css = () => {};
messages = sample_messages.map((message) => ({...message}));
- f({override, override_rewire, mock_template});
+ f(helpers);
});
}
@@ -363,7 +367,7 @@ test("test_recent_topics_show", ({mock_template, override}) => {
assert.equal(rt.inplace_rerender("stream_unknown:topic_unknown"), false);
});
-test("test_filter_all", ({override_rewire, mock_template}) => {
+test("test_filter_all", ({mock_template}) => {
// Just tests inplace rerender of a message
// in All topics filter.
page_params.is_spectator = true;
@@ -392,7 +396,7 @@ test("test_filter_all", ({override_rewire, mock_template}) => {
i = row_data.length;
rt.clear_for_tests();
stub_out_filter_buttons();
- override_rewire(rt, "is_visible", () => true);
+ recent_topics_util.set_visible(true);
rt.set_filter("all");
rt.process_messages([messages[0]]);
@@ -412,11 +416,11 @@ test("test_filter_all", ({override_rewire, mock_template}) => {
row_data = generate_topic_data([[1, "topic-1", 0, false, true]]);
i = row_data.length;
rt.set_default_focus();
- override_rewire(rt, "is_in_focus", () => false);
+ $(".home-page-input").trigger("focus");
assert.equal(rt.inplace_rerender("1:topic-1"), true);
});
-test("test_filter_unread", ({override_rewire, mock_template}) => {
+test("test_filter_unread", ({mock_template}) => {
let expected_filter_unread = false;
page_params.is_spectator = false;
@@ -460,12 +464,12 @@ test("test_filter_unread", ({override_rewire, mock_template}) => {
});
rt.clear_for_tests();
- override_rewire(rt, "is_visible", () => true);
+ recent_topics_util.set_visible(true);
rt.set_default_focus();
stub_out_filter_buttons();
rt.process_messages(messages);
- override_rewire(rt, "is_in_focus", () => false);
+ $(".home-page-input").trigger("focus");
assert.equal(rt.inplace_rerender("1:topic-1"), true);
$("#recent_topics_filter_buttons").removeClass("btn-recent-selected");
@@ -526,7 +530,7 @@ test("test_filter_unread", ({override_rewire, mock_template}) => {
rt.set_filter("all");
});
-test("test_filter_participated", ({override_rewire, mock_template}) => {
+test("test_filter_participated", ({mock_template}) => {
let expected_filter_participated;
page_params.is_spectator = false;
@@ -569,13 +573,13 @@ test("test_filter_participated", ({override_rewire, mock_template}) => {
});
rt.clear_for_tests();
- override_rewire(rt, "is_visible", () => true);
+ recent_topics_util.set_visible(true);
rt.set_default_focus();
stub_out_filter_buttons();
expected_filter_participated = false;
rt.process_messages(messages);
- override_rewire(rt, "is_in_focus", () => false);
+ $(".home-page-input").trigger("focus");
assert.equal(rt.inplace_rerender("1:topic-4"), true);
// Set muted filter
@@ -635,8 +639,8 @@ test("test_filter_participated", ({override_rewire, mock_template}) => {
rt.set_filter("all");
});
-test("test_update_unread_count", ({override_rewire}) => {
- override_rewire(rt, "is_visible", () => false);
+test("test_update_unread_count", () => {
+ recent_topics_util.set_visible(false);
rt.clear_for_tests();
stub_out_filter_buttons();
rt.set_filter("all");
@@ -647,7 +651,7 @@ test("test_update_unread_count", ({override_rewire}) => {
rt.update_topic_unread_count(messages[9]);
});
-test("basic assertions", ({override_rewire, mock_template}) => {
+test("basic assertions", ({mock_template}) => {
rt.clear_for_tests();
mock_template("recent_topics_table.hbs", false, () => {});
@@ -656,7 +660,7 @@ test("basic assertions", ({override_rewire, mock_template}) => {
});
stub_out_filter_buttons();
- override_rewire(rt, "is_visible", () => true);
+ recent_topics_util.set_visible(true);
rt.set_default_focus();
rt.set_filter("all");
rt.process_messages(messages);
@@ -764,19 +768,19 @@ test("basic assertions", ({override_rewire, mock_template}) => {
// update_topic_is_muted now relies on external libraries completely
// so we don't need to check anythere here.
generate_topic_data([[1, topic1, 0, false, true]]);
- override_rewire(rt, "is_in_focus", () => false);
+ $(".home-page-input").trigger("focus");
assert.equal(rt.update_topic_is_muted(stream1, topic1), true);
// a topic gets muted which we are not tracking
assert.equal(rt.update_topic_is_muted(stream1, "topic-10"), false);
});
-test("test_reify_local_echo_message", ({override_rewire, mock_template}) => {
+test("test_reify_local_echo_message", ({mock_template}) => {
mock_template("recent_topics_table.hbs", false, () => {});
mock_template("recent_topic_row.hbs", false, () => {});
rt.clear_for_tests();
stub_out_filter_buttons();
- override_rewire(rt, "is_visible", () => true);
+ recent_topics_util.set_visible(true);
rt.set_filter("all");
rt.process_messages(messages);
@@ -822,8 +826,8 @@ test("test_reify_local_echo_message", ({override_rewire, mock_template}) => {
);
});
-test("test_delete_messages", ({override, override_rewire}) => {
- override_rewire(rt, "is_visible", () => false);
+test("test_delete_messages", ({override}) => {
+ recent_topics_util.set_visible(false);
rt.clear_for_tests();
stub_out_filter_buttons();
rt.set_filter("all");
@@ -861,9 +865,9 @@ test("test_delete_messages", ({override, override_rewire}) => {
rt.update_topics_of_deleted_message_ids([-1]);
});
-test("test_topic_edit", ({override, override_rewire}) => {
+test("test_topic_edit", ({override}) => {
override(all_messages_data, "all_messages", () => messages);
- override_rewire(rt, "is_visible", () => false);
+ recent_topics_util.set_visible(false);
// NOTE: This test should always run in the end as it modified the messages data.
rt.clear_for_tests();
diff --git a/frontend_tests/node_tests/search_pill.js b/frontend_tests/node_tests/search_pill.js
index 2414d6ae6f..565e203b44 100644
--- a/frontend_tests/node_tests/search_pill.js
+++ b/frontend_tests/node_tests/search_pill.js
@@ -2,11 +2,12 @@
const {strict: assert} = require("assert");
-const {zrequire} = require("../zjsunit/namespace");
+const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const input_pill = mock_esm("../../static/js/input_pill");
+
const search_pill = zrequire("search_pill");
-const input_pill = zrequire("input_pill");
const is_starred_item = {
display_value: "is:starred",
@@ -70,10 +71,10 @@ run_test("get_items", () => {
);
});
-run_test("create_pills", ({override_rewire}) => {
+run_test("create_pills", ({override}) => {
let input_pill_create_called = false;
- override_rewire(input_pill, "create", () => {
+ override(input_pill, "create", () => {
input_pill_create_called = true;
return {dummy: "dummy"};
});
diff --git a/frontend_tests/node_tests/search_suggestion_future.js b/frontend_tests/node_tests/search_suggestion_future.js
index 3117b33155..a28935186d 100644
--- a/frontend_tests/node_tests/search_suggestion_future.js
+++ b/frontend_tests/node_tests/search_suggestion_future.js
@@ -6,13 +6,13 @@ const {mock_esm, with_overrides, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params");
+const narrow_state = mock_esm("../../static/js/narrow_state");
const stream_topic_history_util = mock_esm("../../static/js/stream_topic_history_util");
const settings_config = zrequire("settings_config");
const huddle_data = zrequire("huddle_data");
-const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
@@ -69,6 +69,7 @@ function init() {
stream_topic_history.reset();
huddle_data.clear_for_testing();
+ stream_data.clear_subscriptions();
}
function get_suggestions(base_query, query) {
@@ -76,18 +77,16 @@ function get_suggestions(base_query, query) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
init();
- f({override, override_rewire});
+ f(helpers);
});
}
-test("basic_get_suggestions", ({override_rewire}) => {
+test("basic_get_suggestions", ({override}) => {
const query = "fred";
- override_rewire(stream_data, "subscribed_streams", () => []);
-
- override_rewire(narrow_state, "stream", () => "office");
+ override(narrow_state, "stream", () => "office");
const suggestions = get_suggestions("", query);
@@ -95,8 +94,7 @@ test("basic_get_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("basic_get_suggestions_for_spectator", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => []);
+test("basic_get_suggestions_for_spectator", () => {
page_params.is_spectator = true;
const query = "";
@@ -362,10 +360,11 @@ test("group_suggestions", () => {
assert.deepEqual(suggestions.strings, expected);
});
-test("empty_query_suggestions", ({override_rewire}) => {
+test("empty_query_suggestions", () => {
const query = "";
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
const suggestions = get_suggestions("", query);
@@ -403,12 +402,13 @@ test("empty_query_suggestions", ({override_rewire}) => {
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
});
-test("has_suggestions", ({override_rewire}) => {
+test("has_suggestions", ({override}) => {
// Checks that category wise suggestions are displayed instead of a single
// default suggestion when suggesting `has` operator.
let query = "h";
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
- override_rewire(narrow_state, "stream", () => {});
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => {});
let suggestions = get_suggestions("", query);
let expected = ["h", "has:link", "has:image", "has:attachment"];
@@ -459,10 +459,11 @@ test("has_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("check_is_suggestions", ({override_rewire}) => {
+test("check_is_suggestions", ({override}) => {
let query = "i";
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
- override_rewire(narrow_state, "stream", () => {});
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => {});
let suggestions = get_suggestions("", query);
let expected = [
@@ -583,10 +584,8 @@ test("check_is_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("sent_by_me_suggestions", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => []);
-
- override_rewire(narrow_state, "stream", () => {});
+test("sent_by_me_suggestions", ({override}) => {
+ override(narrow_state, "stream", () => {});
let query = "";
let suggestions = get_suggestions("", query);
@@ -659,28 +658,18 @@ test("sent_by_me_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("topic_suggestions", ({override, override_rewire}) => {
+test("topic_suggestions", ({override}) => {
let suggestions;
let expected;
override(stream_topic_history_util, "get_server_history", () => {});
- override_rewire(stream_data, "subscribed_streams", () => ["office"]);
- override_rewire(narrow_state, "stream", () => "office");
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => "office");
const devel_id = 44;
const office_id = 77;
-
- override_rewire(stream_data, "get_stream_id", (stream_name) => {
- switch (stream_name) {
- case "office":
- return office_id;
- case "devel":
- return devel_id;
- /* istanbul ignore next */
- default:
- throw new Error(`unknown stream ${stream_name}`);
- }
- });
+ stream_data.add_sub({stream_id: devel_id, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
suggestions = get_suggestions("", "te");
expected = [
@@ -792,10 +781,11 @@ test("topic_suggestions (limits)", () => {
assert_result("z", []);
});
-test("whitespace_glitch", ({override_rewire}) => {
+test("whitespace_glitch", ({override}) => {
const query = "stream:office "; // note trailing space
- override_rewire(stream_data, "subscribed_streams", () => ["office"]);
+ override(stream_topic_history_util, "get_server_history", () => {});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
const suggestions = get_suggestions("", query);
@@ -804,10 +794,11 @@ test("whitespace_glitch", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("stream_completion", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
+test("stream_completion", ({override}) => {
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ stream_data.add_sub({stream_id: 88, name: "dev help", subscribed: true});
- override_rewire(narrow_state, "stream", () => {});
+ override(narrow_state, "stream", () => {});
let query = "stream:of";
let suggestions = get_suggestions("", query);
@@ -848,8 +839,8 @@ function people_suggestion_setup() {
people.add_active_user(alice);
}
-test("people_suggestions", ({override_rewire}) => {
- override_rewire(narrow_state, "stream", noop);
+test("people_suggestions", ({override}) => {
+ override(narrow_state, "stream", noop);
people_suggestion_setup();
let query = "te";
@@ -912,10 +903,10 @@ test("people_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("people_suggestion (Admin only email visibility)", ({override_rewire}) => {
+test("people_suggestion (Admin only email visibility)", ({override}) => {
/* Suggestions when realm_email_address_visibility is set to admin
only */
- override_rewire(narrow_state, "stream", noop);
+ override(narrow_state, "stream", noop);
people_suggestion_setup();
const query = "te";
@@ -945,7 +936,9 @@ test("people_suggestion (Admin only email visibility)", ({override_rewire}) => {
assert.equal(describe("sender:ted@zulip.com"), "Sent by Ted Smith");
});
-test("operator_suggestions", () => {
+test("operator_suggestions", ({override}) => {
+ override(narrow_state, "stream", () => undefined);
+
// Completed operator should return nothing
let query = "stream:";
let suggestions = get_suggestions("", query);
@@ -974,8 +967,9 @@ test("operator_suggestions", () => {
assert.deepEqual(suggestions.strings, expected);
});
-test("queries_with_spaces", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
+test("queries_with_spaces", () => {
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ stream_data.add_sub({stream_id: 88, name: "dev help", subscribed: true});
// test allowing spaces with quotes surrounding operand
let query = 'stream:"dev he"';
diff --git a/frontend_tests/node_tests/search_suggestion_now.js b/frontend_tests/node_tests/search_suggestion_now.js
index b2a2497c04..982d1799bb 100644
--- a/frontend_tests/node_tests/search_suggestion_now.js
+++ b/frontend_tests/node_tests/search_suggestion_now.js
@@ -6,13 +6,13 @@ const {mock_esm, with_overrides, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params");
+const narrow_state = mock_esm("../../static/js/narrow_state");
const stream_topic_history_util = mock_esm("../../static/js/stream_topic_history_util");
const settings_config = zrequire("settings_config");
const huddle_data = zrequire("huddle_data");
-const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
@@ -67,6 +67,7 @@ function init() {
stream_topic_history.reset();
huddle_data.clear_for_testing();
+ stream_data.clear_subscriptions();
}
function get_suggestions(base_query, query) {
@@ -74,18 +75,16 @@ function get_suggestions(base_query, query) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
init();
- f({override, override_rewire});
+ f(helpers);
});
}
-test("basic_get_suggestions", ({override_rewire}) => {
+test("basic_get_suggestions", ({override}) => {
const query = "fred";
- override_rewire(stream_data, "subscribed_streams", () => []);
-
- override_rewire(narrow_state, "stream", () => "office");
+ override(narrow_state, "stream", () => "office");
const suggestions = get_suggestions("", query);
@@ -93,8 +92,7 @@ test("basic_get_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("basic_get_suggestions_for_spectator", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => []);
+test("basic_get_suggestions_for_spectator", () => {
page_params.is_spectator = true;
const query = "";
@@ -366,10 +364,11 @@ test("group_suggestions", () => {
assert.deepEqual(suggestions.strings, expected);
});
-test("empty_query_suggestions", ({override_rewire}) => {
+test("empty_query_suggestions", () => {
const query = "";
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
const suggestions = get_suggestions("", query);
@@ -407,12 +406,13 @@ test("empty_query_suggestions", ({override_rewire}) => {
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
});
-test("has_suggestions", ({override_rewire}) => {
+test("has_suggestions", ({override}) => {
// Checks that category wise suggestions are displayed instead of a single
// default suggestion when suggesting `has` operator.
let query = "h";
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
- override_rewire(narrow_state, "stream", () => {});
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => {});
let suggestions = get_suggestions("", query);
let expected = ["h", "has:link", "has:image", "has:attachment"];
@@ -466,9 +466,10 @@ test("has_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("check_is_suggestions", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
- override_rewire(narrow_state, "stream", () => {});
+test("check_is_suggestions", ({override}) => {
+ stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => {});
let query = "i";
let suggestions = get_suggestions("", query);
@@ -553,10 +554,8 @@ test("check_is_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("sent_by_me_suggestions", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => []);
-
- override_rewire(narrow_state, "stream", () => {});
+test("sent_by_me_suggestions", ({override}) => {
+ override(narrow_state, "stream", () => {});
let query = "";
let suggestions = get_suggestions("", query);
@@ -624,28 +623,18 @@ test("sent_by_me_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("topic_suggestions", ({override, override_rewire}) => {
+test("topic_suggestions", ({override}) => {
let suggestions;
let expected;
override(stream_topic_history_util, "get_server_history", () => {});
- override_rewire(stream_data, "subscribed_streams", () => ["office"]);
- override_rewire(narrow_state, "stream", () => "office");
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ override(narrow_state, "stream", () => "office");
const devel_id = 44;
const office_id = 77;
-
- override_rewire(stream_data, "get_stream_id", (stream_name) => {
- switch (stream_name) {
- case "office":
- return office_id;
- case "devel":
- return devel_id;
- /* istanbul ignore next */
- default:
- throw new Error(`unknown stream ${stream_name}`);
- }
- });
+ stream_data.add_sub({stream_id: devel_id, name: "devel", subscribed: true});
+ stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
suggestions = get_suggestions("", "te");
expected = [
@@ -763,10 +752,11 @@ test("topic_suggestions (limits)", () => {
assert_result("z", []);
});
-test("whitespace_glitch", ({override_rewire}) => {
+test("whitespace_glitch", ({override}) => {
const query = "stream:office "; // note trailing space
- override_rewire(stream_data, "subscribed_streams", () => ["office"]);
+ override(stream_topic_history_util, "get_server_history", () => {});
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
const suggestions = get_suggestions("", query);
@@ -775,10 +765,11 @@ test("whitespace_glitch", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("stream_completion", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
+test("stream_completion", ({override}) => {
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ stream_data.add_sub({stream_id: 88, name: "dev help", subscribed: true});
- override_rewire(narrow_state, "stream", () => {});
+ override(narrow_state, "stream", () => {});
let query = "stream:of";
let suggestions = get_suggestions("", query);
@@ -796,12 +787,10 @@ test("stream_completion", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("people_suggestions", ({override_rewire}) => {
+test("people_suggestions", ({override}) => {
let query = "te";
- override_rewire(stream_data, "subscribed_streams", () => []);
-
- override_rewire(narrow_state, "stream", () => {});
+ override(narrow_state, "stream", () => {});
const ted = {
email: "ted@zulip.com",
@@ -876,7 +865,9 @@ test("people_suggestions", ({override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
-test("operator_suggestions", () => {
+test("operator_suggestions", ({override}) => {
+ override(narrow_state, "stream", () => undefined);
+
// Completed operator should return nothing
let query = "stream:";
let suggestions = get_suggestions("", query);
@@ -910,8 +901,9 @@ test("operator_suggestions", () => {
assert.deepEqual(suggestions.strings, expected);
});
-test("queries_with_spaces", ({override_rewire}) => {
- override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
+test("queries_with_spaces", () => {
+ stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
+ stream_data.add_sub({stream_id: 88, name: "dev help", subscribed: true});
// test allowing spaces with quotes surrounding operand
let query = 'stream:"dev he"';
@@ -955,10 +947,10 @@ function people_suggestion_setup() {
people.add_active_user(alice);
}
-test("people_suggestion (Admin only email visibility)", ({override_rewire}) => {
+test("people_suggestion (Admin only email visibility)", ({override}) => {
/* Suggestions when realm_email_address_visibility is set to admin
only */
- override_rewire(narrow_state, "stream", () => {});
+ override(narrow_state, "stream", () => {});
people_suggestion_setup();
const query = "te";
diff --git a/frontend_tests/node_tests/settings_muted_topics.js b/frontend_tests/node_tests/settings_muted_topics.js
index d8e9740b1f..b8fe740a95 100644
--- a/frontend_tests/node_tests/settings_muted_topics.js
+++ b/frontend_tests/node_tests/settings_muted_topics.js
@@ -6,6 +6,7 @@ const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
+const list_widget = mock_esm("../../static/js/list_widget");
const muted_topics_ui = mock_esm("../../static/js/muted_topics_ui");
const settings_muted_topics = zrequire("settings_muted_topics");
@@ -20,12 +21,11 @@ const frontend = {
};
stream_data.add_sub(frontend);
-run_test("settings", ({override_rewire}) => {
+run_test("settings", ({override}) => {
muted_topics.add_muted_topic(frontend.stream_id, "js", 1577836800);
let populate_list_called = false;
- override_rewire(settings_muted_topics, "populate_list", () => {
- const opts = muted_topics.get_muted_topics();
- assert.deepEqual(opts, [
+ override(list_widget, "create", ($container, list) => {
+ assert.deepEqual(list, [
{
date_muted: 1577836800000,
date_muted_str: "Jan\u00A001,\u00A02020",
diff --git a/frontend_tests/node_tests/settings_muted_users.js b/frontend_tests/node_tests/settings_muted_users.js
index ae1815e87c..16607e324e 100644
--- a/frontend_tests/node_tests/settings_muted_users.js
+++ b/frontend_tests/node_tests/settings_muted_users.js
@@ -6,23 +6,25 @@ const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
+const list_widget = mock_esm("../../static/js/list_widget");
const muted_users_ui = mock_esm("../../static/js/muted_users_ui");
const settings_muted_users = zrequire("settings_muted_users");
const muted_users = zrequire("muted_users");
+const people = zrequire("people");
const noop = () => {};
-run_test("settings", ({override_rewire}) => {
+run_test("settings", ({override}) => {
+ people.add_active_user({user_id: 5, email: "five@zulip.com", full_name: "Feivel Fiverson"});
muted_users.add_muted_user(5, 1577836800);
let populate_list_called = false;
- override_rewire(settings_muted_users, "populate_list", () => {
- const opts = muted_users.get_muted_users();
- assert.deepEqual(opts, [
+ override(list_widget, "create", ($container, list) => {
+ assert.deepEqual(list, [
{
- date_muted: 1577836800000,
date_muted_str: "Jan\u00A001,\u00A02020",
- id: 5,
+ user_id: 5,
+ user_name: "Feivel Fiverson",
},
]);
populate_list_called = true;
diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js
index ecd26766e4..6b538268de 100644
--- a/frontend_tests/node_tests/settings_org.js
+++ b/frontend_tests/node_tests/settings_org.js
@@ -42,7 +42,7 @@ const settings_org = zrequire("settings_org");
const dropdown_list_widget = zrequire("dropdown_list_widget");
function test(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (helpers) => {
$("#realm-icon-upload-widget .upload-spinner-background").css = () => {};
page_params.is_admin = false;
page_params.realm_domains = [
@@ -51,7 +51,7 @@ function test(label, f) {
];
page_params.realm_authentication_methods = {};
settings_org.reset();
- f({override, override_rewire, mock_template});
+ f(helpers);
});
}
@@ -506,12 +506,8 @@ function test_discard_changes_button(discard_changes) {
$message_content_delete_limit_minutes,
];
- $("#org-discard-msg-editing").closest = () => $discard_button_parent;
-
- const stubbed_function = settings_org.change_save_button_state;
- settings_org.__Rewire__("change_save_button_state", (save_button_controls, state) => {
- assert.equal(state, "discarded");
- });
+ const {$discard_button, props} = createSaveButtons("msg-editing");
+ $discard_button.closest = (selector) => $(selector);
discard_changes(ev);
@@ -524,8 +520,7 @@ function test_discard_changes_button(discard_changes) {
assert.equal($message_content_edit_limit_minutes.val(), "60");
assert.equal($msg_delete_limit_setting.val(), "upto_two_min");
assert.equal($message_content_delete_limit_minutes.val(), "2");
-
- settings_org.__Rewire__("change_save_button_state", stubbed_function);
+ assert.ok(props.hidden);
}
test("set_up", ({override, override_rewire}) => {
@@ -575,7 +570,7 @@ test("set_up", ({override, override_rewire}) => {
// TEST set_up() here, but this mostly just allows us to
// get access to the click handlers.
- override_rewire(settings_org, "maybe_disable_widgets", noop);
+ override(page_params, "is_owner", true);
settings_org.set_up();
test_submit_settings_form(
diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js
index 2b80022fbe..d1bb45103b 100644
--- a/frontend_tests/node_tests/settings_user_groups.js
+++ b/frontend_tests/node_tests/settings_user_groups.js
@@ -86,7 +86,7 @@ const name_selector = `#user-groups #${CSS.escape(1)} .name`;
const description_selector = `#user-groups #${CSS.escape(1)} .description`;
const instructions_selector = `#user-groups #${CSS.escape(1)} .save-instructions`;
-test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
+test_ui("populate_user_groups", ({mock_template}) => {
const realm_user_group = {
id: 1,
name: "Mobile",
@@ -147,7 +147,7 @@ test_ui("populate_user_groups", ({override_rewire, mock_template}) => {
return people.get_by_user_id !== undefined && people.get_by_user_id !== noop;
};
- override_rewire(settings_user_groups, "can_edit", () => true);
+ page_params.is_admin = true;
const all_pills = new Map();
@@ -500,7 +500,7 @@ test_ui("on_events", ({override_rewire, mock_template}) => {
return "stub";
});
- override_rewire(settings_user_groups, "can_edit", () => true);
+ page_params.is_admin = true;
(function test_admin_user_group_form_submit_triggered() {
const handler = settings_user_groups.add_user_group;
diff --git a/frontend_tests/node_tests/starred_messages.js b/frontend_tests/node_tests/starred_messages.js
index 0579f0cc13..57e4aea688 100644
--- a/frontend_tests/node_tests/starred_messages.js
+++ b/frontend_tests/node_tests/starred_messages.js
@@ -2,28 +2,33 @@
const {strict: assert} = require("assert");
-const {with_overrides, zrequire} = require("../zjsunit/namespace");
+const {mock_esm, with_overrides, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
const {page_params, user_settings} = require("../zjsunit/zpage_params");
+const top_left_corner = mock_esm("../../static/js/top_left_corner", {
+ update_starred_count() {},
+});
+const stream_popover = mock_esm("../../static/js/stream_popover", {
+ hide_topic_popover() {},
+ hide_starred_messages_popover() {},
+});
+
const message_store = zrequire("message_store");
const starred_messages = zrequire("starred_messages");
-const stream_popover = zrequire("stream_popover");
-const top_left_corner = zrequire("top_left_corner");
-run_test("add starred", ({override_rewire}) => {
+run_test("add starred", () => {
starred_messages.starred_ids.clear();
assert.deepEqual(starred_messages.get_starred_msg_ids(), []);
assert.equal(starred_messages.get_count(), 0);
- override_rewire(starred_messages, "rerender_ui", () => {});
starred_messages.add([1, 2]);
assert.deepEqual(starred_messages.get_starred_msg_ids(), [1, 2]);
assert.equal(starred_messages.get_count(), 2);
});
-run_test("remove starred", ({override_rewire}) => {
+run_test("remove starred", () => {
starred_messages.starred_ids.clear();
assert.deepEqual(starred_messages.get_starred_msg_ids(), []);
@@ -32,7 +37,6 @@ run_test("remove starred", ({override_rewire}) => {
}
assert.deepEqual(starred_messages.get_starred_msg_ids(), [1, 2, 3]);
- override_rewire(starred_messages, "rerender_ui", () => {});
starred_messages.remove([2, 3]);
assert.deepEqual(starred_messages.get_starred_msg_ids(), [1]);
assert.equal(starred_messages.get_count(), 1);
@@ -77,14 +81,13 @@ run_test("get starred ids in topic", () => {
assert.deepEqual(starred_messages.get_count_in_topic(20, "topic"), 1);
});
-run_test("initialize", ({override_rewire}) => {
+run_test("initialize", () => {
starred_messages.starred_ids.clear();
for (const id of [1, 2, 3]) {
starred_messages.starred_ids.add(id);
}
page_params.starred_messages = [4, 5, 6];
- override_rewire(starred_messages, "rerender_ui", () => {});
starred_messages.initialize();
assert.deepEqual(starred_messages.get_starred_msg_ids(), [4, 5, 6]);
});
@@ -96,10 +99,10 @@ run_test("rerender_ui", () => {
}
user_settings.starred_message_counts = true;
- with_overrides(({override_rewire}) => {
+ with_overrides(({override}) => {
const stub = make_stub();
- override_rewire(stream_popover, "hide_topic_popover", () => {});
- override_rewire(top_left_corner, "update_starred_count", stub.f);
+ override(stream_popover, "hide_topic_popover", () => {});
+ override(top_left_corner, "update_starred_count", stub.f);
starred_messages.rerender_ui();
assert.equal(stub.num_calls, 1);
const args = stub.get_args("count");
@@ -107,10 +110,10 @@ run_test("rerender_ui", () => {
});
user_settings.starred_message_counts = false;
- with_overrides(({override_rewire}) => {
+ with_overrides(({override}) => {
const stub = make_stub();
- override_rewire(stream_popover, "hide_topic_popover", () => {});
- override_rewire(top_left_corner, "update_starred_count", stub.f);
+ override(stream_popover, "hide_topic_popover", () => {});
+ override(top_left_corner, "update_starred_count", stub.f);
starred_messages.rerender_ui();
assert.equal(stub.num_calls, 1);
const args = stub.get_args("count");
diff --git a/frontend_tests/node_tests/stream_create_subscribers_data.js b/frontend_tests/node_tests/stream_create_subscribers_data.js
index 534eb640e2..9b0be72eb8 100644
--- a/frontend_tests/node_tests/stream_create_subscribers_data.js
+++ b/frontend_tests/node_tests/stream_create_subscribers_data.js
@@ -34,7 +34,7 @@ const test_user103 = {
};
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
page_params.is_admin = false;
people.init();
people.add_active_user(me);
@@ -43,7 +43,7 @@ function test(label, f) {
people.add_active_user(test_user103);
page_params.user_id = me.user_id;
people.initialize_current_user(me.user_id);
- f({override, override_rewire});
+ f(helpers);
});
}
diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js
index 302d4ab4ba..4aba7bdc50 100644
--- a/frontend_tests/node_tests/stream_data.js
+++ b/frontend_tests/node_tests/stream_data.js
@@ -40,7 +40,7 @@ function contains_sub(subs, sub) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
page_params.is_admin = false;
page_params.realm_users = [];
page_params.is_guest = false;
@@ -48,7 +48,7 @@ function test(label, f) {
people.add_active_user(me);
people.initialize_current_user(me.user_id);
stream_data.clear_subscriptions();
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -764,7 +764,7 @@ test("canonicalized_name", () => {
assert.deepStrictEqual(stream_data.canonicalized_name("Stream_Bar"), "stream_bar");
});
-test("create_sub", ({override_rewire}) => {
+test("create_sub", () => {
const india = {
stream_id: 102,
name: "India",
@@ -783,11 +783,9 @@ test("create_sub", ({override_rewire}) => {
color: "#76ce90",
};
- override_rewire(color_data, "pick_color", () => "#bd86e5");
-
const india_sub = stream_data.create_sub_from_server_data(india);
assert.ok(india_sub);
- assert.equal(india_sub.color, "#bd86e5");
+ assert.equal(india_sub.color, color_data.colors[0]);
const new_sub = stream_data.create_sub_from_server_data(india);
// make sure sub doesn't get created twice
assert.equal(india_sub, new_sub);
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js
index 81a71459e0..4dcdb0a77f 100644
--- a/frontend_tests/node_tests/stream_events.js
+++ b/frontend_tests/node_tests/stream_events.js
@@ -29,6 +29,9 @@ mock_esm("../../static/js/all_messages_data", {
const message_lists = mock_esm("../../static/js/message_lists", {
current: {},
});
+const message_view_header = mock_esm("../../static/js/message_view_header", {
+ maybe_rerender_title_area_for_stream() {},
+});
mock_esm("../../static/js/recent_topics_ui", {
complete_rerender: () => {},
});
@@ -39,7 +42,6 @@ mock_esm("../../static/js/settings_notifications", {
mock_esm("../../static/js/overlays", {streams_open: () => true});
const {Filter} = zrequire("../js/filter");
-const message_view_header = zrequire("message_view_header");
const narrow_state = zrequire("narrow_state");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
@@ -84,9 +86,9 @@ function narrow_to_frontend() {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
stream_data.clear_subscriptions();
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -263,10 +265,9 @@ test("marked_subscribed (error)", () => {
blueslip.reset();
});
-test("marked_subscribed (normal)", ({override, override_rewire}) => {
+test("marked_subscribed (normal)", ({override}) => {
const sub = {...frontend};
stream_data.add_sub(sub);
- override_rewire(stream_data, "subscribe_myself", noop);
override(stream_color, "update_stream_color", noop);
narrow_to_frontend();
@@ -280,7 +281,11 @@ test("marked_subscribed (normal)", ({override, override_rewire}) => {
override(stream_list, "add_sidebar_row", stream_list_stub.f);
override(message_util, "do_unread_count_updates", message_util_stub.f);
- override_rewire(message_view_header, "render_title_area", message_view_header_stub.f);
+ override(
+ message_view_header,
+ "maybe_rerender_title_area_for_stream",
+ message_view_header_stub.f,
+ );
override(message_lists.current, "update_trailing_bookend", () => {
list_updated = true;
});
@@ -300,8 +305,7 @@ test("marked_subscribed (normal)", ({override, override_rewire}) => {
narrow_state.reset_current_filter();
});
-test("marked_subscribed (color)", ({override, override_rewire}) => {
- override_rewire(stream_data, "subscribe_myself", noop);
+test("marked_subscribed (color)", ({override}) => {
override(message_util, "do_unread_count_updates", noop);
override(stream_list, "add_sidebar_row", noop);
@@ -312,6 +316,7 @@ test("marked_subscribed (color)", ({override, override_rewire}) => {
is_muted: true,
invite_only: false,
};
+ stream_data.add_sub(sub);
override(color_data, "pick_color", () => "green");
@@ -353,31 +358,34 @@ test("marked_subscribed (emails)", ({override}) => {
assert.deepEqual(sub, args.sub);
});
-test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override, override_rewire}) => {
+test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override}) => {
// Test unsubscribe
const sub = {...dev_help};
- assert.ok(sub.subscribed);
+ stream_data.add_sub(sub);
+ stream_data.subscribe_myself(sub);
const stub = make_stub();
override(stream_settings_ui, "update_settings_for_unsubscribed", stub.f);
override(stream_list, "remove_sidebar_row", noop);
- override_rewire(stream_data, "unsubscribe_myself", noop);
stream_events.mark_unsubscribed(sub);
const args = stub.get_args("sub");
assert.deepEqual(args.sub, sub);
});
-test("mark_unsubscribed (render_title_area)", ({override, override_rewire}) => {
+test("mark_unsubscribed (render_title_area)", ({override}) => {
const sub = {...frontend, subscribed: true};
stream_data.add_sub(sub);
// Test update bookend and remove done event
narrow_to_frontend();
const message_view_header_stub = make_stub();
- override_rewire(message_view_header, "render_title_area", message_view_header_stub.f);
- override_rewire(stream_data, "unsubscribe_myself", noop);
+ override(
+ message_view_header,
+ "maybe_rerender_title_area_for_stream",
+ message_view_header_stub.f,
+ );
override(stream_settings_ui, "update_settings_for_unsubscribed", noop);
override(message_lists.current, "update_trailing_bookend", noop);
override(stream_list, "remove_sidebar_row", noop);
diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js
index f096217259..9f57d5c2ba 100644
--- a/frontend_tests/node_tests/stream_list.js
+++ b/frontend_tests/node_tests/stream_list.js
@@ -14,18 +14,24 @@ page_params.realm_users = [];
const noop = () => {};
+let num_unread_for_stream;
+
const narrow_state = mock_esm("../../static/js/narrow_state");
const topic_list = mock_esm("../../static/js/topic_list");
mock_esm("../../static/js/keydown_util", {
handle: noop,
});
+const scroll_util = mock_esm("../../static/js/scroll_util", {
+ scroll_element_into_container() {},
+});
mock_esm("../../static/js/ui", {get_scroll_element: ($element) => $element});
+mock_esm("../../static/js/unread", {
+ num_unread_for_stream: () => num_unread_for_stream,
+});
const {Filter} = zrequire("../js/filter");
const stream_sort = zrequire("stream_sort");
-const unread = zrequire("unread");
const stream_data = zrequire("stream_data");
-const scroll_util = zrequire("scroll_util");
const stream_list = zrequire("stream_list");
const devel = {
@@ -43,9 +49,6 @@ const social = {
subscribed: true,
};
-// We use this with override.
-let num_unread_for_stream;
-
function create_devel_sidebar_row({mock_template}) {
const $devel_count = $.create("devel-count");
const $subscription_block = $.create("devel-block");
@@ -85,10 +88,10 @@ function create_social_sidebar_row({mock_template}) {
}
function test_ui(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (helpers) => {
stream_data.clear_subscriptions();
stream_list.stream_sidebar.rows.clear();
- f({override, override_rewire, mock_template});
+ f(helpers);
});
}
@@ -96,7 +99,6 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
// Make a couple calls to create_sidebar_row() and make sure they
// generate the right markup as well as play nice with get_stream_li().
user_settings.demote_inactive_streams = 1;
- override_rewire(unread, "num_unread_for_stream", () => num_unread_for_stream);
stream_data.add_sub(devel);
stream_data.add_sub(social);
@@ -174,8 +176,6 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
});
test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
- override_rewire(unread, "num_unread_for_stream", () => num_unread_for_stream);
-
stream_data.add_sub(devel);
stream_data.add_sub(social);
@@ -363,14 +363,13 @@ test_ui("zoom_in_and_zoom_out", () => {
assert.ok($("#streams_list").hasClass("zoom-out"));
});
-test_ui("narrowing", ({override_rewire}) => {
+test_ui("narrowing", () => {
initialize_stream_data();
topic_list.close = noop;
topic_list.rebuild = noop;
topic_list.active_stream_id = noop;
topic_list.get_stream_li = noop;
- override_rewire(scroll_util, "scroll_element_into_container", noop);
assert.ok(!$("").hasClass("active-filter"));
@@ -417,8 +416,7 @@ test_ui("focusout_user_filter", () => {
click_handler(e);
});
-test_ui("focus_user_filter", ({override_rewire}) => {
- override_rewire(scroll_util, "scroll_element_into_container", noop);
+test_ui("focus_user_filter", () => {
stream_list.set_event_handlers();
initialize_stream_data();
@@ -432,8 +430,6 @@ test_ui("focus_user_filter", ({override_rewire}) => {
});
test_ui("sort_streams", ({override_rewire}) => {
- override_rewire(scroll_util, "scroll_element_into_container", noop);
-
// Get coverage on early-exit.
stream_list.build_stream_list();
@@ -583,7 +579,7 @@ test_ui("separators_only_pinned", () => {
narrow_state.active = () => false;
-test_ui("rename_stream", ({override_rewire, mock_template}) => {
+test_ui("rename_stream", ({mock_template}) => {
initialize_stream_data();
const sub = stream_data.get_sub_by_name("devel");
@@ -609,21 +605,18 @@ test_ui("rename_stream", ({override_rewire, mock_template}) => {
return {to_$: () => $li_stub};
});
- let count_updated;
- override_rewire(stream_list, "update_count_in_dom", ($li) => {
- assert.equal($li, $li_stub);
- count_updated = true;
- });
+ const $subscription_block = $.create("development-block");
+ const $unread_count = $.create("development-count");
+ $li_stub.set_find_results(".subscription_block", $subscription_block);
+ $subscription_block.set_find_results(".unread_count", $unread_count);
stream_list.rename_stream(sub);
- assert.ok(count_updated);
+ assert.equal($unread_count.text(), "99");
});
-test_ui("refresh_pin", ({override_rewire, mock_template}) => {
+test_ui("refresh_pin", ({override, override_rewire, mock_template}) => {
initialize_stream_data();
- override_rewire(scroll_util, "scroll_element_into_container", noop);
-
const sub = {
name: "maybe_pin",
stream_id: 100,
@@ -639,7 +632,7 @@ test_ui("refresh_pin", ({override_rewire, mock_template}) => {
};
const $li_stub = $.create("li stub");
- $li_stub.length = 0;
+ $li_stub.length = 1;
mock_template("stream_sidebar_row.hbs", false, () => ({to_$: () => $li_stub}));
@@ -647,9 +640,10 @@ test_ui("refresh_pin", ({override_rewire, mock_template}) => {
$("#stream_filters").append = noop;
let scrolled;
- override_rewire(stream_list, "scroll_stream_into_view", ($li) => {
- assert.equal($li, $li_stub);
- scrolled = true;
+ override(scroll_util, "scroll_element_into_container", ($li) => {
+ if ($li === $li_stub) {
+ scrolled = true;
+ }
});
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);
diff --git a/frontend_tests/node_tests/stream_sort.js b/frontend_tests/node_tests/stream_sort.js
index da89246903..95e3cefee0 100644
--- a/frontend_tests/node_tests/stream_sort.js
+++ b/frontend_tests/node_tests/stream_sort.js
@@ -45,9 +45,9 @@ function sort_groups(query) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
stream_data.clear_subscriptions();
- f({override, override_rewire});
+ f(helpers);
});
}
diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js
index 0d56bfdeed..e6282fead6 100644
--- a/frontend_tests/node_tests/top_left_corner.js
+++ b/frontend_tests/node_tests/top_left_corner.js
@@ -6,25 +6,25 @@ const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
+const pm_list = mock_esm("../../static/js/pm_list");
mock_esm("../../static/js/resize", {
resize_stream_filters_container: () => {},
});
const {Filter} = zrequire("../js/filter");
const people = zrequire("people");
-const pm_list = zrequire("pm_list");
const top_left_corner = zrequire("top_left_corner");
-run_test("narrowing", ({override_rewire}) => {
+run_test("narrowing", ({override}) => {
// activating narrow
let pm_expanded;
let pm_closed;
- override_rewire(pm_list, "close", () => {
+ override(pm_list, "close", () => {
pm_closed = true;
});
- override_rewire(pm_list, "expand", () => {
+ override(pm_list, "expand", () => {
pm_expanded = true;
});
diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js
index dbad7f6a7c..179c924653 100644
--- a/frontend_tests/node_tests/topic_generator.js
+++ b/frontend_tests/node_tests/topic_generator.js
@@ -2,16 +2,17 @@
const {strict: assert} = require("assert");
-const {zrequire} = require("../zjsunit/namespace");
+const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const muted_topics = mock_esm("../../static/js/muted_topics");
+const stream_data = mock_esm("../../static/js/stream_data");
+const stream_topic_history = mock_esm("../../static/js/stream_topic_history");
+const unread = mock_esm("../../static/js/unread");
+
const pm_conversations = zrequire("pm_conversations");
pm_conversations.recent = {};
-const muted_topics = zrequire("muted_topics");
-const unread = zrequire("unread");
-const stream_data = zrequire("stream_data");
-const stream_topic_history = zrequire("stream_topic_history");
const stream_sort = zrequire("stream_sort");
const tg = zrequire("topic_generator");
@@ -39,7 +40,7 @@ run_test("streams", () => {
assert_prev_stream("announce", "test here");
});
-run_test("topics", ({override_rewire}) => {
+run_test("topics", ({override}) => {
const streams = [1, 2, 3, 4];
const topics = new Map([
[1, ["read", "read", "1a", "1b", "read", "1c"]],
@@ -85,7 +86,7 @@ run_test("topics", ({override_rewire}) => {
devel: devel_stream_id,
};
- override_rewire(stream_topic_history, "get_recent_topic_names", (stream_id) => {
+ override(stream_topic_history, "get_recent_topic_names", (stream_id) => {
switch (stream_id) {
case muted_stream_id:
return ["ms-topic1", "ms-topic2"];
@@ -96,19 +97,15 @@ run_test("topics", ({override_rewire}) => {
return [];
});
- override_rewire(stream_data, "get_stream_id", (stream_name) => stream_id_dct[stream_name]);
+ override(stream_data, "get_stream_id", (stream_name) => stream_id_dct[stream_name]);
- override_rewire(
- stream_data,
- "is_stream_muted_by_name",
- (stream_name) => stream_name === "muted",
- );
+ override(stream_data, "is_stream_muted_by_name", (stream_name) => stream_name === "muted");
- override_rewire(unread, "topic_has_any_unread", (stream_id) =>
+ override(unread, "topic_has_any_unread", (stream_id) =>
[devel_stream_id, muted_stream_id].includes(stream_id),
);
- override_rewire(muted_topics, "is_topic_muted", (stream_name, topic) => topic === "muted");
+ override(muted_topics, "is_topic_muted", (stream_name, topic) => topic === "muted");
let next_item = tg.get_next_topic("announce", "whatever");
assert.deepEqual(next_item, {
@@ -123,10 +120,10 @@ run_test("topics", ({override_rewire}) => {
});
});
-run_test("get_next_unread_pm_string", ({override_rewire}) => {
+run_test("get_next_unread_pm_string", ({override}) => {
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
- override_rewire(unread, "num_unread_for_person", (user_ids_string) => {
+ override(unread, "num_unread_for_person", (user_ids_string) => {
if (user_ids_string === "unk") {
return undefined;
}
@@ -146,7 +143,7 @@ run_test("get_next_unread_pm_string", ({override_rewire}) => {
assert.equal(tg.get_next_unread_pm_string("read"), "2,3");
assert.equal(tg.get_next_unread_pm_string("2,3"), "4");
- override_rewire(unread, "num_unread_for_person", () => 0);
+ override(unread, "num_unread_for_person", () => 0);
assert.equal(tg.get_next_unread_pm_string("2,3"), undefined);
});
diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js
index a1c20da1c6..8939aa7b1c 100644
--- a/frontend_tests/node_tests/topic_list_data.js
+++ b/frontend_tests/node_tests/topic_list_data.js
@@ -38,9 +38,9 @@ function get_list_info(zoomed) {
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
stream_topic_history.reset();
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -120,18 +120,29 @@ test("get_list_info w/real stream_topic_history", ({override}) => {
assert.equal(list_info.num_possible_topics, 2);
});
-test("get_list_info unreads", ({override, override_rewire}) => {
+test("get_list_info unreads", ({override}) => {
let list_info;
- override_rewire(stream_topic_history, "get_recent_topic_names", () =>
- _.range(15).map((i) => "topic " + i),
- );
+ let message_id = 0;
+ for (let i = 14; i >= 0; i -= 1) {
+ stream_topic_history.add_message({
+ stream_id: general.stream_id,
+ message_id: (message_id += 1),
+ topic_name: `topic ${i}`,
+ });
+ }
- const unread_cnt = new Map();
- override_rewire(unread, "num_unread_for_topic", (stream_id, topic_name) => {
- assert.equal(stream_id, general.stream_id);
- return unread_cnt.get(topic_name) || 0;
- });
+ function add_unreads(topic, count) {
+ unread.process_loaded_messages(
+ Array.from({length: count}, () => ({
+ id: (message_id += 1),
+ stream_id: general.stream_id,
+ topic,
+ type: "stream",
+ unread: true,
+ })),
+ );
+ }
/*
We have 15 topics, but we only show up
@@ -142,8 +153,8 @@ test("get_list_info unreads", ({override, override_rewire}) => {
So first we'll get 7 topics, where 2 are
unread.
*/
- unread_cnt.set("topic 8", 8);
- unread_cnt.set("topic 9", 9);
+ add_unreads("topic 8", 8);
+ add_unreads("topic 9", 9);
list_info = get_list_info();
assert.equal(list_info.items.length, 7);
@@ -155,8 +166,8 @@ test("get_list_info unreads", ({override, override_rewire}) => {
["topic 0", "topic 1", "topic 2", "topic 3", "topic 4", "topic 8", "topic 9"],
);
- unread_cnt.set("topic 6", 6);
- unread_cnt.set("topic 7", 7);
+ add_unreads("topic 6", 6);
+ add_unreads("topic 7", 7);
list_info = get_list_info();
assert.equal(list_info.items.length, 8);
@@ -168,9 +179,9 @@ test("get_list_info unreads", ({override, override_rewire}) => {
["topic 0", "topic 1", "topic 2", "topic 3", "topic 4", "topic 6", "topic 7", "topic 8"],
);
- unread_cnt.set("topic 4", 4);
- unread_cnt.set("topic 5", 5);
- unread_cnt.set("topic 13", 13);
+ add_unreads("topic 4", 4);
+ add_unreads("topic 5", 5);
+ add_unreads("topic 13", 13);
override(muted_topics, "is_topic_muted", (stream_id, topic_name) => {
assert.equal(stream_id, general.stream_id);
diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js
index ade9e8a3ff..c1ad7aef72 100644
--- a/frontend_tests/node_tests/transmit.js
+++ b/frontend_tests/node_tests/transmit.js
@@ -95,7 +95,7 @@ run_test("transmit_message_ajax_reload_pending", () => {
assert.ok(reload_initiated);
});
-run_test("reply_message_stream", ({override_rewire}) => {
+run_test("reply_message_stream", ({override}) => {
const stream_message = {
type: "stream",
stream: "social",
@@ -108,8 +108,8 @@ run_test("reply_message_stream", ({override_rewire}) => {
let send_message_args;
- override_rewire(transmit, "send_message", (args) => {
- send_message_args = args;
+ override(channel, "post", ({data}) => {
+ send_message_args = data;
});
page_params.user_id = 44;
@@ -132,7 +132,7 @@ run_test("reply_message_stream", ({override_rewire}) => {
});
});
-run_test("reply_message_private", ({override_rewire}) => {
+run_test("reply_message_private", ({override}) => {
const fred = {
user_id: 3,
email: "fred@example.com",
@@ -149,8 +149,8 @@ run_test("reply_message_private", ({override_rewire}) => {
let send_message_args;
- override_rewire(transmit, "send_message", (args) => {
- send_message_args = args;
+ override(channel, "post", ({data}) => {
+ send_message_args = data;
});
page_params.user_id = 155;
diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js
index 5d73d0b695..e0f9be17bf 100644
--- a/frontend_tests/node_tests/typeahead_helper.js
+++ b/frontend_tests/node_tests/typeahead_helper.js
@@ -2,9 +2,11 @@
const {strict: assert} = require("assert");
-const {zrequire} = require("../zjsunit/namespace");
+const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const {page_params} = require("../zjsunit/zpage_params");
+const {page_params, user_settings} = require("../zjsunit/zpage_params");
+
+const stream_topic_history = mock_esm("../../static/js/stream_topic_history");
const settings_config = zrequire("settings_config");
const pm_conversations = zrequire("pm_conversations");
@@ -97,7 +99,7 @@ stream_data.create_streams([
]);
function test(label, f) {
- run_test(label, ({override, override_rewire, mock_template}) => {
+ run_test(label, (helpers) => {
pm_conversations.clear_for_testing();
recent_senders.clear_for_testing();
peer_data.clear_for_testing();
@@ -107,11 +109,11 @@ function test(label, f) {
page_params.realm_email_address_visibility =
settings_config.email_address_visibility_values.admins_only.code;
- f({override, override_rewire, mock_template});
+ f(helpers);
});
}
-test("sort_streams", ({override_rewire}) => {
+test("sort_streams", ({override}) => {
let test_streams = [
{
stream_id: 101,
@@ -150,7 +152,17 @@ test("sort_streams", ({override_rewire}) => {
},
];
- override_rewire(stream_data, "is_active", (sub) => sub.name !== "dead");
+ override(
+ user_settings,
+ "demote_inactive_streams",
+ settings_config.demote_inactive_streams_values.always.code,
+ );
+ stream_data.set_filter_out_inactives();
+ override(
+ stream_topic_history,
+ "stream_has_topics",
+ (stream_id) => ![105, 205].includes(stream_id),
+ );
test_streams = th.sort_streams(test_streams, "d");
assert.deepEqual(test_streams[0].name, "Denmark"); // Pinned streams first
diff --git a/frontend_tests/node_tests/typing_events.js b/frontend_tests/node_tests/typing_events.js
index 95ecd488a4..1153ecd96f 100644
--- a/frontend_tests/node_tests/typing_events.js
+++ b/frontend_tests/node_tests/typing_events.js
@@ -5,9 +5,13 @@ const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
+const {page_params} = require("../zjsunit/zpage_params");
-const typing_events = zrequire("typing_events");
+const {Filter} = zrequire("filter");
+const narrow_state = zrequire("narrow_state");
const people = zrequire("people");
+const typing_data = zrequire("typing_data");
+const typing_events = zrequire("typing_events");
const anna = {
email: "anna@example.com",
@@ -38,18 +42,20 @@ people.add_active_user(vronsky);
people.add_active_user(levin);
people.add_active_user(kitty);
-run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) => {
- const $typing_notifications = $("#typing_notifications");
+run_test("render_notifications_for_narrow", ({override, mock_template}) => {
+ override(page_params, "user_id", anna.user_id);
+ const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
+ const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
+ narrow_state.set_current_filter(new Filter([{operator: "pm-with", operand: group_emails}]));
- const two_typing_users_ids = [anna.user_id, vronsky.user_id];
- const three_typing_users_ids = [anna.user_id, vronsky.user_id, levin.user_id];
- const four_typing_users_ids = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
+ const $typing_notifications = $("#typing_notifications");
mock_template("typing_notifications.hbs", true, (args, rendered_html) => rendered_html);
// Having only two( two_typing_users_ids);
+ typing_data.add_typist(group, anna.user_id);
+ typing_data.add_typist(group, vronsky.user_id);
typing_events.render_notifications_for_narrow();
assert.ok($typing_notifications.visible());
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
@@ -57,7 +63,7 @@ run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) =
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
// Having 3(=MAX_USERS_TO_DISPLAY_NAME) typists should also display only names
- override_rewire(typing_events, "get_users_typing_for_narrow", () => three_typing_users_ids);
+ typing_data.add_typist(group, levin.user_id);
typing_events.render_notifications_for_narrow();
assert.ok($typing_notifications.visible());
assert.ok($typing_notifications.html().includes(`${anna.full_name} is typing…`));
@@ -66,7 +72,7 @@ run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) =
assert.ok(!$typing_notifications.html().includes("Several people are typing…"));
// Having 4(>MAX_USERS_TO_DISPLAY_NAME) typists should display "Several people are typing…"
- override_rewire(typing_events, "get_users_typing_for_narrow", () => four_typing_users_ids);
+ typing_data.add_typist(group, kitty.user_id);
typing_events.render_notifications_for_narrow();
assert.ok($typing_notifications.visible());
assert.ok($typing_notifications.html().includes("Several people are typing…"));
@@ -76,7 +82,10 @@ run_test("render_notifications_for_narrow", ({override_rewire, mock_template}) =
assert.ok(!$typing_notifications.html().includes(`${kitty.full_name} is typing…`));
// #typing_notifications should be hidden when there are no typists.
- override_rewire(typing_events, "get_users_typing_for_narrow", () => []);
+ typing_data.remove_typist(group, anna.user_id);
+ typing_data.remove_typist(group, vronsky.user_id);
+ typing_data.remove_typist(group, levin.user_id);
+ typing_data.remove_typist(group, kitty.user_id);
typing_events.render_notifications_for_narrow();
assert.ok(!$typing_notifications.visible());
});
diff --git a/frontend_tests/node_tests/typing_status.js b/frontend_tests/node_tests/typing_status.js
index e132a94984..5526deed0e 100644
--- a/frontend_tests/node_tests/typing_status.js
+++ b/frontend_tests/node_tests/typing_status.js
@@ -2,11 +2,12 @@
const {strict: assert} = require("assert");
-const {set_global, zrequire} = require("../zjsunit/namespace");
+const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
+const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
+
const typing = zrequire("typing");
-const compose_pm_pill = zrequire("compose_pm_pill");
const typing_status = zrequire("../shared/js/typing_status");
function make_time(secs) {
@@ -20,7 +21,7 @@ function returns_time(secs) {
};
}
-run_test("basics", ({override_rewire}) => {
+run_test("basics", ({override, override_rewire}) => {
typing_status.initialize_state();
// invalid conversation basically does nothing
@@ -263,7 +264,7 @@ run_test("basics", ({override_rewire}) => {
// test that we correctly detect if worker.get_recipient
// and typing_status.state.current_recipient are the same
- override_rewire(compose_pm_pill, "get_user_ids_string", () => "1,2,3");
+ override(compose_pm_pill, "get_user_ids_string", () => "1,2,3");
typing_status.state.current_recipient = typing.get_recipient();
const call_count = {
@@ -294,14 +295,14 @@ run_test("basics", ({override_rewire}) => {
// change in recipient and new_recipient should make us
// call typing_status.stop_last_notification
- override_rewire(compose_pm_pill, "get_user_ids_string", () => "2,3,4");
+ override(compose_pm_pill, "get_user_ids_string", () => "2,3,4");
typing_status.update(worker, typing.get_recipient());
assert.deepEqual(call_count.maybe_ping_server, 2);
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
assert.deepEqual(call_count.stop_last_notification, 1);
// Stream messages are represented as get_user_ids_string being empty
- override_rewire(compose_pm_pill, "get_user_ids_string", () => "");
+ override(compose_pm_pill, "get_user_ids_string", () => "");
typing_status.update(worker, typing.get_recipient());
assert.deepEqual(call_count.maybe_ping_server, 2);
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js
index 53e533c65b..ab6d5839c7 100644
--- a/frontend_tests/node_tests/unread.js
+++ b/frontend_tests/node_tests/unread.js
@@ -55,10 +55,10 @@ function test_notifiable_count(home_unread_messages, expected_notifiable_count)
}
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
unread.declare_bankruptcy();
muted_topics.set_muted_topics([]);
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -244,15 +244,11 @@ test("muting", () => {
assert.equal(unread.num_unread_for_stream(unknown_stream_id), 0);
});
-test("num_unread_for_topic", ({override_rewire}) => {
+test("num_unread_for_topic", () => {
// Test the num_unread_for_topic() function using many
// messages.
const stream_id = 301;
-
- override_rewire(sub_store, "get", (arg) => {
- assert.equal(arg, stream_id);
- return {name: "Some stream"};
- });
+ sub_store.add_hydrated_sub(stream_id, {stream_id, name: "Some stream"});
let count = unread.num_unread_for_topic(stream_id, "lunch");
assert.equal(count, 0);
@@ -315,15 +311,15 @@ test("num_unread_for_topic", ({override_rewire}) => {
assert.deepEqual(msg_ids, []);
});
-test("home_messages", ({override_rewire}) => {
- override_rewire(stream_data, "is_subscribed", () => true);
- override_rewire(stream_data, "is_muted", () => false);
-
+test("home_messages", () => {
const stream_id = 401;
-
- override_rewire(sub_store, "get", () => ({
+ const sub = {
+ stream_id,
name: "whatever",
- }));
+ subscribed: true,
+ is_muted: false,
+ };
+ sub_store.add_hydrated_sub(stream_id, sub);
const message = {
id: 15,
@@ -354,7 +350,7 @@ test("home_messages", ({override_rewire}) => {
test_notifiable_count(counts.home_unread_messages, 0);
// Now unsubscribe all our streams.
- override_rewire(stream_data, "is_subscribed", () => false);
+ sub.subscribed = false;
counts = unread.get_counts();
assert.equal(counts.home_unread_messages, 0);
test_notifiable_count(counts.home_unread_messages, 0);
diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js
index 8e8a593796..c0148f6b01 100644
--- a/frontend_tests/node_tests/upload.js
+++ b/frontend_tests/node_tests/upload.js
@@ -18,16 +18,16 @@ function Uppy(options) {
Uppy.UIPlugin = class UIPlugin {};
mock_cjs("@uppy/core", Uppy);
+const compose_actions = mock_esm("../../static/js/compose_actions");
+const compose_ui = mock_esm("../../static/js/compose_ui");
mock_esm("../../static/js/csrf", {csrf_token: "csrf_token"});
-const compose_ui = zrequire("compose_ui");
-const compose_actions = zrequire("compose_actions");
const upload = zrequire("upload");
function test(label, f) {
- run_test(label, ({override, override_rewire}) => {
+ run_test(label, (helpers) => {
page_params.max_file_upload_size_mib = 25;
- f({override, override_rewire});
+ f(helpers);
});
}
@@ -183,7 +183,7 @@ test("show_error_message", () => {
assert.equal($("#compose-error-msg").text(), "translated: An unknown error occurred.");
});
-test("upload_files", ({override_rewire}) => {
+test("upload_files", ({override, override_rewire}) => {
let uppy_cancel_all_called = false;
let files = [
{
@@ -216,17 +216,12 @@ test("upload_files", ({override_rewire}) => {
assert.ok(!$("#compose-send-button").prop("disabled"));
page_params.max_file_upload_size_mib = 0;
- let show_error_message_called = false;
- override_rewire(upload, "show_error_message", (config, message) => {
- show_error_message_called = true;
- assert.equal(config.mode, "compose");
- assert.equal(
- message,
- "translated: File and image uploads have been disabled for this organization.",
- );
- });
+ $("#compose-error-msg").text("");
upload.upload_files(uppy, config, files);
- assert.ok(show_error_message_called);
+ assert.equal(
+ $("#compose-error-msg").text(),
+ "translated: File and image uploads have been disabled for this organization.",
+ );
page_params.max_file_upload_size_mib = 25;
let on_click_close_button_callback;
@@ -235,13 +230,13 @@ test("upload_files", ({override_rewire}) => {
on_click_close_button_callback = callback;
};
let compose_ui_insert_syntax_and_focus_called = false;
- override_rewire(compose_ui, "insert_syntax_and_focus", (syntax, textarea) => {
+ override(compose_ui, "insert_syntax_and_focus", (syntax, textarea) => {
assert.equal(syntax, "[translated: Uploading budapest.png…]()");
assert.equal(textarea, $("#compose-textarea"));
compose_ui_insert_syntax_and_focus_called = true;
});
let compose_ui_autosize_textarea_called = false;
- override_rewire(compose_ui, "autosize_textarea", () => {
+ override(compose_ui, "autosize_textarea", () => {
compose_ui_autosize_textarea_called = true;
});
let markdown_preview_hide_button_clicked = false;
@@ -292,7 +287,7 @@ test("upload_files", ({override_rewire}) => {
type: "image/png",
},
];
- override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
+ override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
compose_ui_replace_syntax_called = true;
assert.equal(old_syntax, "[translated: Uploading budapest.png…]()");
assert.equal(new_syntax, "");
@@ -460,7 +455,7 @@ test("copy_paste", ({override_rewire}) => {
assert.equal(upload_files_called, false);
});
-test("uppy_events", ({override_rewire}) => {
+test("uppy_events", ({override, override_rewire}) => {
const callbacks = {};
let uppy_cancel_all_called = false;
let state = {};
@@ -502,11 +497,11 @@ test("uppy_events", ({override_rewire}) => {
},
};
let compose_actions_start_called = false;
- override_rewire(compose_actions, "start", () => {
+ override(compose_actions, "start", () => {
compose_actions_start_called = true;
});
let compose_ui_replace_syntax_called = false;
- override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
+ override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
compose_ui_replace_syntax_called = true;
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
assert.equal(
@@ -516,7 +511,7 @@ test("uppy_events", ({override_rewire}) => {
assert.equal(textarea, $("#compose-textarea"));
});
let compose_ui_autosize_textarea_called = false;
- override_rewire(compose_ui, "autosize_textarea", () => {
+ override(compose_ui, "autosize_textarea", () => {
compose_ui_autosize_textarea_called = true;
});
on_upload_success_callback(file, response);
@@ -595,19 +590,14 @@ test("uppy_events", ({override_rewire}) => {
message: "Some error message",
};
const on_info_visible_callback = callbacks["info-visible"];
- let show_error_message_called = false;
+ $("#compose-error-msg").text("");
uppy_cancel_all_called = false;
compose_ui_replace_syntax_called = false;
const on_restriction_failed_callback = callbacks["restriction-failed"];
- override_rewire(upload, "show_error_message", (config, message) => {
- show_error_message_called = true;
- assert.equal(config.mode, "compose");
- assert.equal(message, "Some error message");
- });
on_info_visible_callback();
assert.ok(uppy_cancel_all_called);
- assert.ok(show_error_message_called);
- override_rewire(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
+ assert.equal($("#compose-error-msg").text(), "Some error message");
+ override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
compose_ui_replace_syntax_called = true;
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
assert.equal(new_syntax, "");
@@ -636,13 +626,8 @@ test("uppy_events", ({override_rewire}) => {
on_info_visible_callback();
const on_upload_error_callback = callbacks["upload-error"];
- show_error_message_called = false;
+ $("#compose-error-msg").text("");
compose_ui_replace_syntax_called = false;
- override_rewire(upload, "show_error_message", (config, message) => {
- show_error_message_called = true;
- assert.equal(config.mode, "compose");
- assert.equal(message, "Response message");
- });
response = {
body: {
msg: "Response message",
@@ -651,26 +636,21 @@ test("uppy_events", ({override_rewire}) => {
uppy_cancel_all_called = false;
on_upload_error_callback(file, null, response);
assert.ok(uppy_cancel_all_called);
- assert.ok(show_error_message_called);
+ assert.equal($("#compose-error-msg").text(), "Response message");
assert.ok(compose_ui_replace_syntax_called);
compose_ui_replace_syntax_called = false;
- override_rewire(upload, "show_error_message", (config, message) => {
- show_error_message_called = true;
- assert.equal(config.mode, "compose");
- assert.equal(message, undefined);
- });
uppy_cancel_all_called = false;
on_upload_error_callback(file, null, null);
assert.ok(uppy_cancel_all_called);
- assert.ok(show_error_message_called);
+ assert.equal($("#compose-error-msg").text(), "translated: An unknown error occurred.");
assert.ok(compose_ui_replace_syntax_called);
- show_error_message_called = false;
+ $("#compose-error-msg").text("");
$("#compose-textarea").val("user modified text");
uppy_cancel_all_called = false;
on_upload_error_callback(file, null);
assert.ok(uppy_cancel_all_called);
- assert.ok(show_error_message_called);
+ assert.equal($("#compose-error-msg").text(), "translated: An unknown error occurred.");
assert.ok(compose_ui_replace_syntax_called);
assert.equal($("#compose-textarea").val(), "user modified text");
});
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index 6b9744f3f7..0b678833d2 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -134,7 +134,6 @@ EXEMPT_FILES = make_set(
"static/js/realm_playground.js",
"static/js/realm_user_settings_defaults.ts",
"static/js/recent_topics_ui.js",
- "static/js/recent_topics_util.js",
"static/js/reload.js",
"static/js/reminder.js",
"static/js/resize.js",