mirror of https://github.com/zulip/zulip.git
node_tests: Remove low-hanging uses of __Rewire__.
When we were preparing the conversion to ES modules in 2019, the primary obstacle was that the Node tests extensively relied on the ability to reach into modules and mutate their CommonJS exports in order to mock things. ES module bindings are not mutable, so in commit173c9cee42
we added babel-plugin-rewire-ts as a kludgy transpilation-based workaround for this to unblock the conversion. However, babel-plugin-rewire-ts is slow, buggy, nonstandard, confusing, and unmaintained. It’s incompatible with running our ES modules as native ES modules, and prevents us from taking advantage of modern tools for ES modules. So we want to excise all use of __Rewire__ (and the disallow_rewire, override_rewire helper functions that rely on it) from the tests and remove babel-plugin-rewire-ts. Commits64abdc199e
ande17ba5260a
(#20730) prepared for this by letting us see where __Rewire__ is being used. Now we go through and remove most of the uses that are easy to remove without modifying the production code at all. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
f7f5f7a0b1
commit
c520890f54
|
@ -20,6 +20,7 @@ const _document = {
|
|||
|
||||
const channel = mock_esm("../../static/js/channel");
|
||||
const compose_state = mock_esm("../../static/js/compose_state");
|
||||
const narrow = mock_esm("../../static/js/narrow");
|
||||
const padded_widget = mock_esm("../../static/js/padded_widget");
|
||||
const pm_list = mock_esm("../../static/js/pm_list");
|
||||
const popovers = mock_esm("../../static/js/popovers");
|
||||
|
@ -33,7 +34,6 @@ const huddle_data = zrequire("huddle_data");
|
|||
const compose_fade = zrequire("compose_fade");
|
||||
const keydown_util = zrequire("keydown_util");
|
||||
const muted_users = zrequire("muted_users");
|
||||
const narrow = zrequire("narrow");
|
||||
const presence = zrequire("presence");
|
||||
const people = zrequire("people");
|
||||
const buddy_data = zrequire("buddy_data");
|
||||
|
@ -94,8 +94,6 @@ function clear_buddy_list() {
|
|||
});
|
||||
}
|
||||
|
||||
let presence_info;
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
user_settings.presence_enabled = true;
|
||||
|
@ -109,16 +107,13 @@ function test(label, f) {
|
|||
});
|
||||
});
|
||||
|
||||
presence_info = new Map();
|
||||
presence.__Rewire__("presence_info", presence_info);
|
||||
|
||||
presence_info.set(alice.user_id, {status: "active"});
|
||||
presence_info.set(fred.user_id, {status: "active"});
|
||||
presence_info.set(jill.user_id, {status: "active"});
|
||||
presence_info.set(mark.user_id, {status: "idle"});
|
||||
presence_info.set(norbert.user_id, {status: "active"});
|
||||
presence_info.set(zoe.user_id, {status: "active"});
|
||||
presence_info.set(me.user_id, {status: "active"});
|
||||
presence.presence_info.set(alice.user_id, {status: "active"});
|
||||
presence.presence_info.set(fred.user_id, {status: "active"});
|
||||
presence.presence_info.set(jill.user_id, {status: "active"});
|
||||
presence.presence_info.set(mark.user_id, {status: "idle"});
|
||||
presence.presence_info.set(norbert.user_id, {status: "active"});
|
||||
presence.presence_info.set(zoe.user_id, {status: "active"});
|
||||
presence.presence_info.set(me.user_id, {status: "active"});
|
||||
|
||||
clear_buddy_list();
|
||||
muted_users.set_muted_users([]);
|
||||
|
@ -127,6 +122,8 @@ function test(label, f) {
|
|||
activity.set_cursor_and_filter();
|
||||
|
||||
f(helpers);
|
||||
|
||||
presence.clear_internal_data();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -150,17 +147,17 @@ test("get_status", () => {
|
|||
user_settings.presence_enabled = true;
|
||||
assert.equal(presence.get_status(page_params.user_id), "active");
|
||||
|
||||
presence_info.delete(zoe.user_id);
|
||||
presence.presence_info.delete(zoe.user_id);
|
||||
assert.equal(presence.get_status(zoe.user_id), "offline");
|
||||
|
||||
presence_info.set(alice.user_id, {status: "whatever"});
|
||||
presence.presence_info.set(alice.user_id, {status: "whatever"});
|
||||
assert.equal(presence.get_status(alice.user_id), "whatever");
|
||||
});
|
||||
|
||||
test("sort_users", () => {
|
||||
const user_ids = [alice.user_id, fred.user_id, jill.user_id];
|
||||
|
||||
presence_info.delete(alice.user_id);
|
||||
presence.presence_info.delete(alice.user_id);
|
||||
|
||||
buddy_data.sort_users(user_ids);
|
||||
|
||||
|
@ -271,7 +268,7 @@ test("PM_update_dom_counts", () => {
|
|||
assert.equal($count.text(), "");
|
||||
});
|
||||
|
||||
test("handlers", ({override, override_rewire, mock_template}) => {
|
||||
test("handlers", ({override, mock_template}) => {
|
||||
let filter_key_handlers;
|
||||
|
||||
mock_template("presence_rows.hbs", false, () => {});
|
||||
|
@ -294,7 +291,7 @@ test("handlers", ({override, override_rewire, mock_template}) => {
|
|||
|
||||
let narrowed;
|
||||
|
||||
override_rewire(narrow, "by", (method, email) => {
|
||||
override(narrow, "by", (method, email) => {
|
||||
assert.equal(email, "alice@zulip.com");
|
||||
narrowed = true;
|
||||
});
|
||||
|
@ -562,7 +559,7 @@ test("redraw_muted_user", () => {
|
|||
assert.equal($("#user_presences").html(), "never-been-set");
|
||||
});
|
||||
|
||||
test("update_presence_info", ({override, override_rewire}) => {
|
||||
test("update_presence_info", ({override}) => {
|
||||
override(pm_list, "update_private_messages", () => {});
|
||||
|
||||
page_params.realm_presence_disabled = false;
|
||||
|
@ -575,8 +572,6 @@ test("update_presence_info", ({override, override_rewire}) => {
|
|||
},
|
||||
};
|
||||
|
||||
override_rewire(buddy_data, "matches_filter", () => true);
|
||||
|
||||
const $alice_li = $.create("alice stub");
|
||||
buddy_list_add(alice.user_id, $alice_li);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ const helpers = mock_esm("../../static/js/billing/helpers", {
|
|||
set_tab: () => {},
|
||||
});
|
||||
|
||||
const billing = zrequire("billing/billing");
|
||||
zrequire("billing/billing");
|
||||
|
||||
run_test("initialize", ({override}) => {
|
||||
let set_tab_called = false;
|
||||
|
@ -76,10 +76,9 @@ run_test("planchange", ({override}) => {
|
|||
assert.ok(create_ajax_request_called);
|
||||
});
|
||||
|
||||
run_test("licensechange", ({override, override_rewire}) => {
|
||||
run_test("licensechange", ({override}) => {
|
||||
override(helpers, "set_tab", () => {});
|
||||
let create_ajax_request_called = false;
|
||||
create_ajax_request_called = false;
|
||||
function license_change_ajax(url, form_name, ignored_inputs, method, success_callback) {
|
||||
assert.equal(url, "/json/billing/plan");
|
||||
assert.equal(form_name, "licensechange");
|
||||
|
@ -92,13 +91,6 @@ run_test("licensechange", ({override, override_rewire}) => {
|
|||
create_ajax_request_called = true;
|
||||
}
|
||||
override(helpers, "create_ajax_request", license_change_ajax);
|
||||
billing.create_update_license_request();
|
||||
assert.ok(create_ajax_request_called);
|
||||
|
||||
let create_update_license_request_called = false;
|
||||
override_rewire(billing, "create_update_license_request", () => {
|
||||
create_update_license_request_called = true;
|
||||
});
|
||||
|
||||
$.get_initialize_function()();
|
||||
|
||||
|
@ -106,7 +98,7 @@ run_test("licensechange", ({override, override_rewire}) => {
|
|||
"click",
|
||||
);
|
||||
confirm_license_update_click_handler({preventDefault: () => {}});
|
||||
assert.ok(create_update_license_request_called);
|
||||
assert.ok(create_ajax_request_called);
|
||||
|
||||
let confirm_license_modal_shown = false;
|
||||
override(helpers, "is_valid_input", () => true);
|
||||
|
@ -119,17 +111,17 @@ run_test("licensechange", ({override, override_rewire}) => {
|
|||
return 20;
|
||||
};
|
||||
$("#new_licenses_input").val = () => 15;
|
||||
create_update_license_request_called = false;
|
||||
create_ajax_request_called = false;
|
||||
const update_licenses_button_click_handler =
|
||||
$("#update-licenses-button").get_on_handler("click");
|
||||
update_licenses_button_click_handler({preventDefault: () => {}});
|
||||
assert.ok(create_update_license_request_called);
|
||||
assert.ok(create_ajax_request_called);
|
||||
assert.ok(!confirm_license_modal_shown);
|
||||
|
||||
$("#new_licenses_input").val = () => 25;
|
||||
create_update_license_request_called = false;
|
||||
create_ajax_request_called = false;
|
||||
update_licenses_button_click_handler({preventDefault: () => {}});
|
||||
assert.ok(!create_update_license_request_called);
|
||||
assert.ok(!create_ajax_request_called);
|
||||
assert.ok(confirm_license_modal_shown);
|
||||
|
||||
override(helpers, "is_valid_input", () => false);
|
||||
|
|
|
@ -96,7 +96,7 @@ function add_canned_users() {
|
|||
}
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override, override_rewire}) => {
|
||||
run_test(label, (helpers) => {
|
||||
user_settings.presence_enabled = true;
|
||||
compose_fade_helper.clear_focused_recipient();
|
||||
stream_data.clear_subscriptions();
|
||||
|
@ -107,7 +107,10 @@ function test(label, f) {
|
|||
people.add_active_user(me);
|
||||
people.initialize_current_user(me.user_id);
|
||||
muted_users.set_muted_users([]);
|
||||
f({override, override_rewire});
|
||||
|
||||
f(helpers);
|
||||
|
||||
presence.clear_internal_data();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -423,16 +426,11 @@ test("bulk_data_hacks", ({override_rewire}) => {
|
|||
assert.equal(user_ids.length, 700);
|
||||
});
|
||||
|
||||
test("always show me", ({override_rewire}) => {
|
||||
const present_user_ids = [];
|
||||
override_rewire(presence, "get_user_ids", () => present_user_ids);
|
||||
test("always show me", () => {
|
||||
assert.deepEqual(buddy_data.get_filtered_and_sorted_user_ids(""), [me.user_id]);
|
||||
|
||||
// Make sure we didn't mutate the list passed to us.
|
||||
assert.deepEqual(present_user_ids, []);
|
||||
|
||||
// try to make us show twice
|
||||
present_user_ids.push(me.user_id);
|
||||
presence.presence_info.set(me.user_id, {status: "active"});
|
||||
assert.deepEqual(buddy_data.get_filtered_and_sorted_user_ids(""), [me.user_id]);
|
||||
});
|
||||
|
||||
|
@ -473,7 +471,7 @@ test("level", () => {
|
|||
assert.equal(buddy_data.level(selma.user_id), 3);
|
||||
});
|
||||
|
||||
test("user_last_seen_time_status", ({override, override_rewire}) => {
|
||||
test("user_last_seen_time_status", ({override}) => {
|
||||
set_presence(selma.user_id, "active");
|
||||
set_presence(me.user_id, "active");
|
||||
|
||||
|
@ -490,10 +488,7 @@ test("user_last_seen_time_status", ({override, override_rewire}) => {
|
|||
"translated: Last active: translated: More than 2 weeks ago",
|
||||
);
|
||||
|
||||
override_rewire(presence, "last_active_date", (user_id) => {
|
||||
assert.equal(user_id, old_user.user_id);
|
||||
return new Date(1526137743000);
|
||||
});
|
||||
presence.presence_info.set(old_user.user_id, {last_active: 1526137743});
|
||||
|
||||
override(timerender, "last_seen_status_from_date", (date) => {
|
||||
assert.deepEqual(date, new Date(1526137743000));
|
||||
|
@ -509,19 +504,23 @@ test("user_last_seen_time_status", ({override, override_rewire}) => {
|
|||
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Idle");
|
||||
});
|
||||
|
||||
test("get_items_for_users", ({override_rewire}) => {
|
||||
test("get_items_for_users", () => {
|
||||
people.add_active_user(alice);
|
||||
people.add_active_user(fred);
|
||||
user_status.set_away(alice.user_id);
|
||||
user_settings.emojiset = "google";
|
||||
const status_emoji_info = {
|
||||
emoji_alt_code: false,
|
||||
emoji_name: "car",
|
||||
emoji_code: "1f697",
|
||||
reaction_type: "unicode_emoji",
|
||||
};
|
||||
override_rewire(user_status, "get_status_emoji", () => status_emoji_info);
|
||||
|
||||
const user_ids = [me.user_id, alice.user_id, fred.user_id];
|
||||
for (const user_id of user_ids) {
|
||||
user_status.set_status_emoji({user_id, ...status_emoji_info});
|
||||
}
|
||||
|
||||
assert.deepEqual(buddy_data.get_items_for_users(user_ids), [
|
||||
{
|
||||
faded: false,
|
||||
|
@ -562,8 +561,8 @@ test("get_items_for_users", ({override_rewire}) => {
|
|||
]);
|
||||
});
|
||||
|
||||
test("error handling", ({override_rewire}) => {
|
||||
override_rewire(presence, "get_user_ids", () => [42]);
|
||||
test("error handling", () => {
|
||||
presence.presence_info.set(42, {status: "active"});
|
||||
blueslip.expect("error", "Unknown user_id in get_by_user_id: 42");
|
||||
blueslip.expect("warn", "Got user_id in presence but not people: 42");
|
||||
buddy_data.get_filtered_and_sorted_user_ids();
|
||||
|
|
|
@ -8,39 +8,29 @@ const {run_test} = require("../zjsunit/test");
|
|||
const color_data = zrequire("color_data");
|
||||
|
||||
run_test("pick_color", () => {
|
||||
color_data.__Rewire__("colors", ["blue", "orange", "red", "yellow"]);
|
||||
|
||||
color_data.reset();
|
||||
|
||||
color_data.claim_colors([
|
||||
{color: "orange"},
|
||||
{color: color_data.colors[1]},
|
||||
{foo: "whatever"},
|
||||
{color: "yellow"},
|
||||
{color: color_data.colors[3]},
|
||||
{color: "bogus"},
|
||||
]);
|
||||
|
||||
const expected_colors = [
|
||||
"blue",
|
||||
"red",
|
||||
color_data.colors[0],
|
||||
color_data.colors[2],
|
||||
...color_data.colors.slice(4),
|
||||
// ok, now we'll cycle through all colors
|
||||
"blue",
|
||||
"orange",
|
||||
"red",
|
||||
"yellow",
|
||||
"blue",
|
||||
"orange",
|
||||
"red",
|
||||
"yellow",
|
||||
"blue",
|
||||
"orange",
|
||||
"red",
|
||||
"yellow",
|
||||
...color_data.colors,
|
||||
...color_data.colors,
|
||||
...color_data.colors,
|
||||
];
|
||||
|
||||
for (const expected_color of expected_colors) {
|
||||
assert.equal(color_data.pick_color(), expected_color);
|
||||
}
|
||||
|
||||
color_data.claim_color("blue");
|
||||
assert.equal(color_data.pick_color(), "orange");
|
||||
color_data.claim_color(color_data.colors[0]);
|
||||
assert.equal(color_data.pick_color(), color_data.colors[1]);
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ mock_esm("tippy.js", {
|
|||
});
|
||||
|
||||
set_global("document", {});
|
||||
const navigator = set_global("navigator", {});
|
||||
|
||||
const common = zrequire("common");
|
||||
|
||||
|
@ -79,8 +80,8 @@ run_test("copy_data_attribute_value", ({override}) => {
|
|||
assert.ok(faded_out);
|
||||
});
|
||||
|
||||
run_test("adjust_mac_shortcuts non-mac", ({override_rewire}) => {
|
||||
override_rewire(common, "has_mac_keyboard", () => false);
|
||||
run_test("adjust_mac_shortcuts non-mac", ({override}) => {
|
||||
override(navigator, "platform", "Windows");
|
||||
|
||||
// The adjust_mac_shortcuts has a really simple guard
|
||||
// at the top, and we just test the early-return behavior
|
||||
|
@ -90,7 +91,7 @@ run_test("adjust_mac_shortcuts non-mac", ({override_rewire}) => {
|
|||
|
||||
// Test non-default value of adjust_mac_shortcuts boolean parameter:
|
||||
// `kbd_elem = false`.
|
||||
run_test("adjust_mac_shortcuts mac non-defaults", ({override_rewire}) => {
|
||||
run_test("adjust_mac_shortcuts mac non-defaults", ({override}) => {
|
||||
const keys_to_test_mac = new Map([
|
||||
["Backspace", "Delete"],
|
||||
["Enter", "Return"],
|
||||
|
@ -109,7 +110,7 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override_rewire}) => {
|
|||
const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]);
|
||||
const inserted_fn_key = "<code>Fn</code> + ";
|
||||
|
||||
override_rewire(common, "has_mac_keyboard", () => true);
|
||||
override(navigator, "platform", "MacIntel");
|
||||
|
||||
const test_items = [];
|
||||
let key_no = 1;
|
||||
|
@ -143,7 +144,7 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override_rewire}) => {
|
|||
|
||||
// Test default value of adjust_mac_shortcuts boolean parameter:
|
||||
// `kbd_elem = true`.
|
||||
run_test("adjust_mac_shortcuts mac defaults", ({override_rewire}) => {
|
||||
run_test("adjust_mac_shortcuts mac defaults", ({override}) => {
|
||||
const keys_to_test_mac = new Map([
|
||||
["Backspace", "Delete"],
|
||||
["Enter", "Return"],
|
||||
|
@ -159,7 +160,7 @@ run_test("adjust_mac_shortcuts mac defaults", ({override_rewire}) => {
|
|||
const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]);
|
||||
const inserted_fn_key = "<kbd>Fn</kbd> + ";
|
||||
|
||||
override_rewire(common, "has_mac_keyboard", () => true);
|
||||
override(navigator, "platform", "MacIntel");
|
||||
|
||||
const test_items = [];
|
||||
let key_no = 1;
|
||||
|
|
|
@ -28,6 +28,8 @@ const fake_now = 555;
|
|||
|
||||
const channel = mock_esm("../../static/js/channel");
|
||||
const compose_actions = mock_esm("../../static/js/compose_actions");
|
||||
const compose_fade = mock_esm("../../static/js/compose_fade");
|
||||
const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
|
||||
const loading = mock_esm("../../static/js/loading");
|
||||
const markdown = mock_esm("../../static/js/markdown");
|
||||
const notifications = mock_esm("../../static/js/notifications");
|
||||
|
@ -39,16 +41,14 @@ const server_events = mock_esm("../../static/js/server_events");
|
|||
const stream_settings_ui = mock_esm("../../static/js/stream_settings_ui");
|
||||
const subscriber_api = mock_esm("../../static/js/subscriber_api");
|
||||
const transmit = mock_esm("../../static/js/transmit");
|
||||
const upload = mock_esm("../../static/js/upload");
|
||||
|
||||
const compose_closed_ui = zrequire("compose_closed_ui");
|
||||
const compose_fade = zrequire("compose_fade");
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose = zrequire("compose");
|
||||
const echo = zrequire("echo");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const upload = zrequire("upload");
|
||||
|
||||
function reset_jquery() {
|
||||
// Avoid leaks.
|
||||
|
@ -100,9 +100,11 @@ function test_ui(label, f) {
|
|||
run_test(label, f);
|
||||
}
|
||||
|
||||
function initialize_handlers({override, override_rewire}) {
|
||||
override_rewire(compose, "compute_show_video_chat_button", () => false);
|
||||
override_rewire(upload, "setup_upload", () => undefined);
|
||||
function initialize_handlers({override}) {
|
||||
override(page_params, "realm_available_video_chat_providers", {disabled: {id: 0}});
|
||||
override(page_params, "realm_video_chat_provider", 0);
|
||||
override(upload, "setup_upload", () => undefined);
|
||||
override(upload, "feature_check", () => {});
|
||||
override(resize, "watch_manual_resize", () => {});
|
||||
compose.initialize();
|
||||
}
|
||||
|
@ -155,7 +157,7 @@ test_ui("send_message", ({override, override_rewire}) => {
|
|||
compose_state.topic("");
|
||||
compose_state.set_message_type("private");
|
||||
page_params.user_id = new_user.user_id;
|
||||
override_rewire(compose_state, "private_message_recipient", () => "alice@example.com");
|
||||
override(compose_pm_pill, "get_emails", () => "alice@example.com");
|
||||
|
||||
const server_message_id = 127;
|
||||
override_rewire(echo, "insert_message", (message) => {
|
||||
|
@ -359,8 +361,8 @@ test_ui("finish", ({override, override_rewire}) => {
|
|||
$("#compose .markdown_preview").hide();
|
||||
$("#compose-textarea").val("foobarfoobar");
|
||||
compose_state.set_message_type("private");
|
||||
override_rewire(compose_state, "private_message_recipient", () => "bob@example.com");
|
||||
override_rewire(compose_pm_pill, "get_user_ids", () => []);
|
||||
override(compose_pm_pill, "get_emails", () => "bob@example.com");
|
||||
override(compose_pm_pill, "get_user_ids", () => []);
|
||||
|
||||
let compose_finished_event_checked = false;
|
||||
$(document).on("compose_finished.zulip", () => {
|
||||
|
@ -384,7 +386,7 @@ test_ui("finish", ({override, override_rewire}) => {
|
|||
$("#compose .markdown_preview").hide();
|
||||
$("#compose-textarea").val("foobarfoobar");
|
||||
compose_state.set_message_type("stream");
|
||||
override_rewire(compose_state, "stream_name", () => "social");
|
||||
compose_state.stream_name("social");
|
||||
override_rewire(people, "get_by_user_id", () => []);
|
||||
compose_finished_event_checked = false;
|
||||
let schedule_message = false;
|
||||
|
@ -402,7 +404,7 @@ test_ui("finish", ({override, override_rewire}) => {
|
|||
})();
|
||||
});
|
||||
|
||||
test_ui("initialize", ({override, override_rewire}) => {
|
||||
test_ui("initialize", ({override}) => {
|
||||
let compose_actions_expected_opts;
|
||||
let compose_actions_start_checked;
|
||||
|
||||
|
@ -416,7 +418,8 @@ test_ui("initialize", ({override, override_rewire}) => {
|
|||
// normal workflow of the function. All the tests for the on functions are
|
||||
// done in subsequent tests directly below this test.
|
||||
|
||||
override_rewire(compose, "compute_show_video_chat_button", () => false);
|
||||
override(page_params, "realm_available_video_chat_providers", {disabled: {id: 0}});
|
||||
override(page_params, "realm_video_chat_provider", 0);
|
||||
|
||||
let resize_watch_manual_resize_checked = false;
|
||||
override(resize, "watch_manual_resize", (elem) => {
|
||||
|
@ -424,23 +427,11 @@ test_ui("initialize", ({override, override_rewire}) => {
|
|||
resize_watch_manual_resize_checked = true;
|
||||
});
|
||||
|
||||
let xmlhttprequest_checked = false;
|
||||
set_global(
|
||||
"XMLHttpRequest",
|
||||
class XMLHTTPRequest {
|
||||
upload = true;
|
||||
constructor() {
|
||||
xmlhttprequest_checked = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
$("#compose .compose_upload_file").addClass("notdisplayed");
|
||||
|
||||
page_params.max_file_upload_size_mib = 512;
|
||||
|
||||
let setup_upload_called = false;
|
||||
let uppy_cancel_all_called = false;
|
||||
override_rewire(upload, "setup_upload", (config) => {
|
||||
override(upload, "setup_upload", (config) => {
|
||||
assert.equal(config.mode, "compose");
|
||||
setup_upload_called = true;
|
||||
return {
|
||||
|
@ -449,12 +440,11 @@ test_ui("initialize", ({override, override_rewire}) => {
|
|||
},
|
||||
};
|
||||
});
|
||||
override(upload, "feature_check", () => {});
|
||||
|
||||
compose.initialize();
|
||||
|
||||
assert.ok(resize_watch_manual_resize_checked);
|
||||
assert.ok(xmlhttprequest_checked);
|
||||
assert.ok(!$("#compose .compose_upload_file").hasClass("notdisplayed"));
|
||||
assert.ok(setup_upload_called);
|
||||
|
||||
function set_up_compose_start_mock(expected_opts) {
|
||||
|
@ -495,8 +485,8 @@ test_ui("initialize", ({override, override_rewire}) => {
|
|||
})();
|
||||
});
|
||||
|
||||
test_ui("update_fade", ({override, override_rewire}) => {
|
||||
initialize_handlers({override, override_rewire});
|
||||
test_ui("update_fade", ({override}) => {
|
||||
initialize_handlers({override});
|
||||
|
||||
const selector =
|
||||
"#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient";
|
||||
|
@ -506,12 +496,12 @@ test_ui("update_fade", ({override, override_rewire}) => {
|
|||
let update_all_called = false;
|
||||
let update_narrow_to_recipient_visibility_called = false;
|
||||
|
||||
override_rewire(compose_fade, "set_focused_recipient", (msg_type) => {
|
||||
override(compose_fade, "set_focused_recipient", (msg_type) => {
|
||||
assert.equal(msg_type, "private");
|
||||
set_focused_recipient_checked = true;
|
||||
});
|
||||
|
||||
override_rewire(compose_fade, "update_all", () => {
|
||||
override(compose_fade, "update_all", () => {
|
||||
update_all_called = true;
|
||||
});
|
||||
|
||||
|
@ -535,7 +525,7 @@ test_ui("update_fade", ({override, override_rewire}) => {
|
|||
});
|
||||
|
||||
test_ui("trigger_submit_compose_form", ({override, override_rewire}) => {
|
||||
initialize_handlers({override, override_rewire});
|
||||
initialize_handlers({override});
|
||||
|
||||
let prevent_default_checked = false;
|
||||
let compose_finish_checked = false;
|
||||
|
@ -557,7 +547,7 @@ test_ui("trigger_submit_compose_form", ({override, override_rewire}) => {
|
|||
});
|
||||
|
||||
test_ui("on_events", ({override, override_rewire}) => {
|
||||
initialize_handlers({override, override_rewire});
|
||||
initialize_handlers({override});
|
||||
|
||||
override(rendered_markdown, "update_elements", () => {});
|
||||
|
||||
|
@ -917,12 +907,12 @@ test_ui("on_events", ({override, override_rewire}) => {
|
|||
})();
|
||||
});
|
||||
|
||||
test_ui("create_message_object", ({override_rewire}) => {
|
||||
test_ui("create_message_object", ({override, override_rewire}) => {
|
||||
$("#stream_message_recipient_stream").val("social");
|
||||
$("#stream_message_recipient_topic").val("lunch");
|
||||
$("#compose-textarea").val("burrito");
|
||||
|
||||
override_rewire(compose_state, "get_message_type", () => "stream");
|
||||
compose_state.set_message_type("stream");
|
||||
|
||||
let message = compose.create_message_object();
|
||||
assert.equal(message.to, social.stream_id);
|
||||
|
@ -937,11 +927,8 @@ test_ui("create_message_object", ({override_rewire}) => {
|
|||
assert.equal(message.topic, "lunch");
|
||||
assert.equal(message.content, "burrito");
|
||||
|
||||
override_rewire(compose_state, "get_message_type", () => "private");
|
||||
compose_state.__Rewire__(
|
||||
"private_message_recipient",
|
||||
() => "alice@example.com, bob@example.com",
|
||||
);
|
||||
compose_state.set_message_type("private");
|
||||
override(compose_pm_pill, "get_emails", () => "alice@example.com,bob@example.com");
|
||||
|
||||
message = compose.create_message_object();
|
||||
assert.deepEqual(message.to, [alice.user_id, bob.user_id]);
|
||||
|
|
|
@ -17,6 +17,10 @@ const compose_fade = mock_esm("../../static/js/compose_fade", {
|
|||
clear_compose: noop,
|
||||
});
|
||||
const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
|
||||
const compose_ui = mock_esm("../../static/js/compose_ui", {
|
||||
autosize_textarea: noop,
|
||||
is_full_size: () => false,
|
||||
});
|
||||
const hash_util = mock_esm("../../static/js/hash_util");
|
||||
const narrow_state = mock_esm("../../static/js/narrow_state", {
|
||||
set_compose_defaults: noop,
|
||||
|
@ -50,7 +54,6 @@ mock_esm("../../static/js/resize", {
|
|||
|
||||
const people = zrequire("people");
|
||||
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const compose = zrequire("compose");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose_actions = zrequire("compose_actions");
|
||||
|
@ -72,23 +75,12 @@ function assert_hidden(sel) {
|
|||
assert.ok(!$(sel).visible());
|
||||
}
|
||||
|
||||
function override_private_message_recipient({override_rewire}) {
|
||||
override_rewire(
|
||||
compose_state,
|
||||
"private_message_recipient",
|
||||
(function () {
|
||||
let recipient;
|
||||
|
||||
return function (arg) {
|
||||
if (arg === undefined) {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
recipient = arg;
|
||||
return undefined;
|
||||
};
|
||||
})(),
|
||||
);
|
||||
function override_private_message_recipient({override}) {
|
||||
let recipient;
|
||||
override(compose_pm_pill, "set_from_emails", (value) => {
|
||||
recipient = value;
|
||||
});
|
||||
override(compose_pm_pill, "get_emails", () => recipient, {unused: false});
|
||||
}
|
||||
|
||||
function test(label, f) {
|
||||
|
@ -110,7 +102,7 @@ test("initial_state", () => {
|
|||
});
|
||||
|
||||
test("start", ({override, override_rewire}) => {
|
||||
override_private_message_recipient({override_rewire});
|
||||
override_private_message_recipient({override});
|
||||
override_rewire(compose_actions, "autosize_message_content", () => {});
|
||||
override_rewire(compose_actions, "expand_compose_box", () => {});
|
||||
override_rewire(compose_actions, "set_focus", () => {});
|
||||
|
@ -236,7 +228,7 @@ test("respond_to_message", ({override, override_rewire}) => {
|
|||
override_rewire(compose_actions, "set_focus", () => {});
|
||||
override_rewire(compose_actions, "complete_starting_tasks", () => {});
|
||||
override_rewire(compose_actions, "clear_textarea", () => {});
|
||||
override_private_message_recipient({override_rewire});
|
||||
override_private_message_recipient({override});
|
||||
|
||||
// Test PM
|
||||
const person = {
|
||||
|
@ -277,7 +269,7 @@ test("reply_with_mention", ({override, override_rewire}) => {
|
|||
override_rewire(compose_actions, "set_focus", () => {});
|
||||
override_rewire(compose_actions, "complete_starting_tasks", () => {});
|
||||
override_rewire(compose_actions, "clear_textarea", () => {});
|
||||
override_private_message_recipient({override_rewire});
|
||||
override_private_message_recipient({override});
|
||||
|
||||
const msg = {
|
||||
type: "stream",
|
||||
|
@ -289,7 +281,7 @@ test("reply_with_mention", ({override, override_rewire}) => {
|
|||
override(message_lists.current, "selected_message", () => msg);
|
||||
|
||||
let syntax_to_insert;
|
||||
override_rewire(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
syntax_to_insert = syntax;
|
||||
});
|
||||
|
||||
|
@ -330,14 +322,14 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
|
|||
override_rewire(compose_actions, "set_focus", () => {});
|
||||
override_rewire(compose_actions, "complete_starting_tasks", () => {});
|
||||
override_rewire(compose_actions, "clear_textarea", () => {});
|
||||
override_private_message_recipient({override_rewire});
|
||||
override_private_message_recipient({override});
|
||||
|
||||
let selected_message;
|
||||
override(message_lists.current, "selected_message", () => selected_message);
|
||||
|
||||
let expected_replacement;
|
||||
let replaced;
|
||||
override_rewire(compose_ui, "replace_syntax", (syntax, replacement) => {
|
||||
override(compose_ui, "replace_syntax", (syntax, replacement) => {
|
||||
assert.equal(syntax, "translated: [Quoting…]");
|
||||
assert.equal(replacement, expected_replacement);
|
||||
replaced = true;
|
||||
|
@ -360,7 +352,7 @@ test("quote_and_reply", ({disallow, override, override_rewire}) => {
|
|||
|
||||
override(message_lists.current, "selected_id", () => 100);
|
||||
|
||||
override_rewire(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
assert.equal(syntax, "translated: [Quoting…]\n");
|
||||
});
|
||||
|
||||
|
@ -428,13 +420,13 @@ test("get_focus_area", () => {
|
|||
);
|
||||
});
|
||||
|
||||
test("focus_in_empty_compose", ({override_rewire}) => {
|
||||
test("focus_in_empty_compose", () => {
|
||||
document.activeElement = {id: "compose-textarea"};
|
||||
override_rewire(compose_state, "composing", () => true);
|
||||
compose_state.set_message_type("stream");
|
||||
$("#compose-textarea").val("");
|
||||
assert.ok(compose_state.focus_in_empty_compose());
|
||||
|
||||
override_rewire(compose_state, "composing", () => false);
|
||||
compose_state.set_message_type(false);
|
||||
assert.ok(!compose_state.focus_in_empty_compose());
|
||||
|
||||
$("#compose-textarea").val("foo");
|
||||
|
@ -451,9 +443,6 @@ test("on_narrow", ({override, override_rewire}) => {
|
|||
let narrowed_by_pm_reply;
|
||||
override(narrow_state, "narrowed_by_pm_reply", () => narrowed_by_pm_reply);
|
||||
|
||||
let has_message_content;
|
||||
override_rewire(compose_state, "has_message_content", () => has_message_content);
|
||||
|
||||
let cancel_called = false;
|
||||
override_rewire(compose_actions, "cancel", () => {
|
||||
cancel_called = true;
|
||||
|
@ -478,13 +467,13 @@ test("on_narrow", ({override, override_rewire}) => {
|
|||
compose_fade.update_message_list = () => {
|
||||
update_message_list_called = true;
|
||||
};
|
||||
has_message_content = true;
|
||||
compose_state.message_content("foo");
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
});
|
||||
assert.ok(update_message_list_called);
|
||||
|
||||
has_message_content = false;
|
||||
compose_state.message_content("");
|
||||
let start_called = false;
|
||||
override_rewire(compose_actions, "start", () => {
|
||||
start_called = true;
|
||||
|
|
|
@ -7,10 +7,10 @@ const {run_test} = require("../zjsunit/test");
|
|||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const compose_actions = mock_esm("../../static/js/compose_actions");
|
||||
const input_pill = mock_esm("../../static/js/input_pill");
|
||||
const people = zrequire("people");
|
||||
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
const input_pill = zrequire("input_pill");
|
||||
|
||||
let pills = {
|
||||
pill: {},
|
||||
|
@ -140,7 +140,7 @@ run_test("pills", ({override}) => {
|
|||
return pills;
|
||||
}
|
||||
|
||||
input_pill.__Rewire__("create", input_pill_stub);
|
||||
override(input_pill, "create", input_pill_stub);
|
||||
|
||||
// We stub the return value of input_pill.create(), manually add widget functions to it.
|
||||
pills.onPillCreate = (callback) => {
|
||||
|
@ -185,28 +185,21 @@ run_test("pills", ({override}) => {
|
|||
assert.ok(text_cleared);
|
||||
});
|
||||
|
||||
run_test("has_unconverted_data", () => {
|
||||
compose_pm_pill.__Rewire__("widget", {
|
||||
is_pending: () => true,
|
||||
});
|
||||
run_test("has_unconverted_data", ({override}) => {
|
||||
override(compose_pm_pill.widget, "is_pending", () => true);
|
||||
|
||||
// If the pill itself has pending data, we have unconverted
|
||||
// data.
|
||||
assert.equal(compose_pm_pill.has_unconverted_data(), true);
|
||||
|
||||
compose_pm_pill.__Rewire__("widget", {
|
||||
is_pending: () => false,
|
||||
items: () => [{user_id: 99}],
|
||||
});
|
||||
override(compose_pm_pill.widget, "is_pending", () => false);
|
||||
override(compose_pm_pill.widget, "items", () => [{user_id: 99}]);
|
||||
|
||||
// Our pill is complete and all items contain user_id, so
|
||||
// we do NOT have unconverted data.
|
||||
assert.equal(compose_pm_pill.has_unconverted_data(), false);
|
||||
|
||||
compose_pm_pill.__Rewire__("widget", {
|
||||
is_pending: () => false,
|
||||
items: () => [{user_id: 99}, {email: "random@mit.edu"}],
|
||||
});
|
||||
override(compose_pm_pill.widget, "items", () => [{user_id: 99}, {email: "random@mit.edu"}]);
|
||||
|
||||
// One of our items only knows email (as in a bridge-with-zephyr
|
||||
// scenario where we might not have registered the user yet), so
|
||||
|
|
|
@ -60,9 +60,9 @@ people.add_cross_realm_user(welcome_bot);
|
|||
|
||||
function test_ui(label, f) {
|
||||
// The sloppy_$ flag lets us re-use setup from prior tests.
|
||||
run_test(label, ({override, override_rewire, mock_template}) => {
|
||||
run_test(label, (helpers) => {
|
||||
$("#compose-textarea").val("some message");
|
||||
f({override, override_rewire, mock_template});
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ const {page_params} = require("../zjsunit/zpage_params");
|
|||
const events = require("./lib/events");
|
||||
|
||||
const channel = mock_esm("../../static/js/channel");
|
||||
const compose_ui = mock_esm("../../static/js/compose_ui");
|
||||
const upload = mock_esm("../../static/js/upload");
|
||||
mock_esm("../../static/js/resize", {
|
||||
watch_manual_resize() {},
|
||||
|
@ -26,7 +27,6 @@ set_global(
|
|||
);
|
||||
|
||||
const server_events_dispatch = zrequire("server_events_dispatch");
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const compose_closed = zrequire("compose_closed_ui");
|
||||
const compose = zrequire("compose");
|
||||
function stub_out_video_calls() {
|
||||
|
@ -61,13 +61,13 @@ const realm_available_video_chat_providers = {
|
|||
};
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override, override_rewire}) => {
|
||||
run_test(label, (helpers) => {
|
||||
page_params.realm_available_video_chat_providers = realm_available_video_chat_providers;
|
||||
f({override, override_rewire});
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
test("videos", ({override, override_rewire}) => {
|
||||
test("videos", ({override}) => {
|
||||
page_params.realm_video_chat_provider = realm_available_video_chat_providers.disabled.id;
|
||||
|
||||
override(upload, "setup_upload", () => {});
|
||||
|
@ -92,8 +92,8 @@ test("videos", ({override, override_rewire}) => {
|
|||
const handler = $("body").get_on_handler("click", ".video_link");
|
||||
$("#compose-textarea").val("");
|
||||
|
||||
with_overrides(({disallow_rewire}) => {
|
||||
disallow_rewire(compose_ui, "insert_syntax_and_focus");
|
||||
with_overrides(({disallow}) => {
|
||||
disallow(compose_ui, "insert_syntax_and_focus");
|
||||
handler(ev);
|
||||
});
|
||||
})();
|
||||
|
@ -113,7 +113,7 @@ test("videos", ({override, override_rewire}) => {
|
|||
},
|
||||
};
|
||||
|
||||
override_rewire(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
syntax_to_insert = syntax;
|
||||
called = true;
|
||||
});
|
||||
|
@ -151,7 +151,7 @@ test("videos", ({override, override_rewire}) => {
|
|||
},
|
||||
};
|
||||
|
||||
override_rewire(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
syntax_to_insert = syntax;
|
||||
called = true;
|
||||
});
|
||||
|
@ -197,7 +197,7 @@ test("videos", ({override, override_rewire}) => {
|
|||
},
|
||||
};
|
||||
|
||||
override_rewire(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||
syntax_to_insert = syntax;
|
||||
called = true;
|
||||
});
|
||||
|
|
|
@ -12,10 +12,16 @@ const noop = () => {};
|
|||
const compose = mock_esm("../../static/js/compose", {
|
||||
finish: noop,
|
||||
});
|
||||
const compose_validate = mock_esm("../../static/js/compose_validate", {
|
||||
warn_for_text_overflow_when_tries_to_send: () => true,
|
||||
});
|
||||
const input_pill = mock_esm("../../static/js/input_pill");
|
||||
const message_user_ids = mock_esm("../../static/js/message_user_ids", {
|
||||
user_ids: () => [],
|
||||
});
|
||||
const stream_topic_history = mock_esm("../../static/js/stream_topic_history");
|
||||
const stream_topic_history = mock_esm("../../static/js/stream_topic_history", {
|
||||
stream_has_topics: () => false,
|
||||
});
|
||||
const stream_topic_history_util = mock_esm("../../static/js/stream_topic_history_util");
|
||||
|
||||
let autosize_called;
|
||||
|
@ -35,14 +41,12 @@ set_global("document", "document-stub");
|
|||
|
||||
const typeahead = zrequire("../shared/js/typeahead");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose_validate = zrequire("compose_validate");
|
||||
const emoji = zrequire("emoji");
|
||||
const typeahead_helper = zrequire("typeahead_helper");
|
||||
const muted_users = zrequire("muted_users");
|
||||
const people = zrequire("people");
|
||||
const user_groups = zrequire("user_groups");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const user_pill = zrequire("user_pill");
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
const composebox_typeahead = zrequire("composebox_typeahead");
|
||||
const settings_config = zrequire("settings_config");
|
||||
|
@ -329,7 +333,7 @@ const make_emoji = (emoji_dict) => ({
|
|||
});
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override, override_rewire, mock_template}) => {
|
||||
run_test(label, (helpers) => {
|
||||
people.init();
|
||||
user_groups.init();
|
||||
|
||||
|
@ -353,7 +357,7 @@ function test(label, f) {
|
|||
|
||||
muted_users.set_muted_users([]);
|
||||
|
||||
f({override, override_rewire, mock_template});
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -377,7 +381,7 @@ test("topics_seen_for", ({override}) => {
|
|||
assert.deepEqual(ct.topics_seen_for("non-existing-stream"), []);
|
||||
});
|
||||
|
||||
test("content_typeahead_selected", ({override_rewire}) => {
|
||||
test("content_typeahead_selected", ({override}) => {
|
||||
const fake_this = {
|
||||
query: "",
|
||||
$element: {},
|
||||
|
@ -426,7 +430,7 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
// mention
|
||||
fake_this.completing = "mention";
|
||||
|
||||
override_rewire(compose_validate, "warn_if_mentioning_unsubscribed_user", () => {});
|
||||
override(compose_validate, "warn_if_mentioning_unsubscribed_user", () => {});
|
||||
|
||||
fake_this.query = "@**Mark Tw";
|
||||
fake_this.token = "Mark Tw";
|
||||
|
@ -435,7 +439,7 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
assert.equal(actual_value, expected_value);
|
||||
|
||||
let warned_for_mention = false;
|
||||
override_rewire(compose_validate, "warn_if_mentioning_unsubscribed_user", (mentioned) => {
|
||||
override(compose_validate, "warn_if_mentioning_unsubscribed_user", (mentioned) => {
|
||||
assert.equal(mentioned, othello);
|
||||
warned_for_mention = true;
|
||||
});
|
||||
|
@ -467,8 +471,8 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
|
||||
fake_this.query = "@back";
|
||||
fake_this.token = "back";
|
||||
with_overrides(({disallow_rewire}) => {
|
||||
disallow_rewire(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
with_overrides(({disallow}) => {
|
||||
disallow(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
|
||||
});
|
||||
expected_value = "@*Backend* ";
|
||||
|
@ -484,8 +488,8 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
fake_this.completing = "silent_mention";
|
||||
fake_this.query = "@_kin";
|
||||
fake_this.token = "kin";
|
||||
with_overrides(({disallow_rewire}) => {
|
||||
disallow_rewire(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
with_overrides(({disallow}) => {
|
||||
disallow(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
||||
});
|
||||
|
||||
|
@ -512,8 +516,8 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
|
||||
fake_this.query = "@_back";
|
||||
fake_this.token = "back";
|
||||
with_overrides(({disallow_rewire}) => {
|
||||
disallow_rewire(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
with_overrides(({disallow}) => {
|
||||
disallow(compose_validate, "warn_if_mentioning_unsubscribed_user");
|
||||
actual_value = ct.content_typeahead_selected.call(fake_this, backend);
|
||||
});
|
||||
expected_value = "@_*Backend* ";
|
||||
|
@ -558,7 +562,7 @@ test("content_typeahead_selected", ({override_rewire}) => {
|
|||
// stream
|
||||
fake_this.completing = "stream";
|
||||
let warned_for_stream_link = false;
|
||||
override_rewire(compose_validate, "warn_if_private_stream_is_linked", (linked_stream) => {
|
||||
override(compose_validate, "warn_if_private_stream_is_linked", (linked_stream) => {
|
||||
assert.equal(linked_stream, sweden_stream);
|
||||
warned_for_stream_link = true;
|
||||
});
|
||||
|
@ -643,7 +647,23 @@ function sorted_names_from(subs) {
|
|||
return subs.map((sub) => sub.name).sort();
|
||||
}
|
||||
|
||||
test("initialize", ({override, override_rewire, mock_template}) => {
|
||||
test("initialize", ({override, mock_template}) => {
|
||||
let pill_items = [];
|
||||
let cleared = false;
|
||||
let appended_names = [];
|
||||
override(input_pill, "create", () => ({
|
||||
clear_text() {
|
||||
cleared = true;
|
||||
},
|
||||
items: () => pill_items,
|
||||
onPillCreate() {},
|
||||
onPillRemove() {},
|
||||
appendValidatedData(item) {
|
||||
appended_names.push(item.display_value);
|
||||
},
|
||||
}));
|
||||
compose_pm_pill.initialize();
|
||||
|
||||
let expected_value;
|
||||
|
||||
mock_template("typeahead_list_item.hbs", true, (data, html) => {
|
||||
|
@ -762,8 +782,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
|
||||
let pm_recipient_typeahead_called = false;
|
||||
$("#private_message_recipient").typeahead = (options) => {
|
||||
let inserted_users = [];
|
||||
override_rewire(user_pill, "get_user_ids", () => inserted_users);
|
||||
pill_items = [];
|
||||
|
||||
// This should match the users added at the beginning of this test file.
|
||||
let actual_value = options.source("");
|
||||
|
@ -872,45 +891,33 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
target: "#doesnotmatter",
|
||||
};
|
||||
|
||||
let appended_name;
|
||||
override_rewire(compose_pm_pill, "set_from_typeahead", (item) => {
|
||||
appended_name = item.full_name;
|
||||
});
|
||||
|
||||
// options.updater()
|
||||
options.query = "othello";
|
||||
appended_names = [];
|
||||
options.updater(othello, event);
|
||||
assert.equal(appended_name, "Othello, the Moor of Venice");
|
||||
assert.deepEqual(appended_names, ["Othello, the Moor of Venice"]);
|
||||
|
||||
options.query = "othello@zulip.com, cor";
|
||||
appended_names = [];
|
||||
actual_value = options.updater(cordelia, event);
|
||||
assert.equal(appended_name, "Cordelia, Lear's daughter");
|
||||
assert.deepEqual(appended_names, ["Cordelia, Lear's daughter"]);
|
||||
|
||||
const click_event = {type: "click", target: "#doesnotmatter"};
|
||||
options.query = "othello";
|
||||
// Focus lost (caused by the click event in the typeahead list)
|
||||
$("#private_message_recipient").trigger("blur");
|
||||
appended_names = [];
|
||||
actual_value = options.updater(othello, click_event);
|
||||
assert.equal(appended_name, "Othello, the Moor of Venice");
|
||||
|
||||
let appended_names = [];
|
||||
|
||||
override_rewire(compose_pm_pill, "set_from_typeahead", (item) => {
|
||||
appended_names.push(item.full_name);
|
||||
});
|
||||
|
||||
let cleared = false;
|
||||
function fake_clear() {
|
||||
cleared = true;
|
||||
}
|
||||
compose_pm_pill.__Rewire__("widget", {clear_text: fake_clear});
|
||||
assert.deepEqual(appended_names, ["Othello, the Moor of Venice"]);
|
||||
|
||||
cleared = false;
|
||||
options.query = "hamletchar";
|
||||
appended_names = [];
|
||||
options.updater(hamletcharacters, event);
|
||||
assert.deepEqual(appended_names, ["King Lear"]);
|
||||
assert.ok(cleared);
|
||||
|
||||
inserted_users = [lear.user_id];
|
||||
pill_items = [{user_id: lear.user_id}];
|
||||
appended_names = [];
|
||||
cleared = false;
|
||||
options.updater(hamletcharacters, event);
|
||||
|
@ -1048,13 +1055,23 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
subscribed: false,
|
||||
};
|
||||
// Subscribed stream is active
|
||||
override_rewire(stream_data, "is_active", () => false);
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.never.code,
|
||||
);
|
||||
stream_data.set_filter_out_inactives();
|
||||
fake_this = {completing: "stream", token: "s"};
|
||||
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
||||
expected_value = [sweden_stream, serbia_stream];
|
||||
assert.deepEqual(actual_value, expected_value);
|
||||
// Subscribed stream is inactive
|
||||
override_rewire(stream_data, "is_active", () => true);
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.always.code,
|
||||
);
|
||||
stream_data.set_filter_out_inactives();
|
||||
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
||||
expected_value = [sweden_stream, serbia_stream];
|
||||
assert.deepEqual(actual_value, expected_value);
|
||||
|
|
|
@ -28,6 +28,7 @@ const activity = mock_esm("../../static/js/activity");
|
|||
const alert_words_ui = mock_esm("../../static/js/alert_words_ui");
|
||||
const attachments_ui = mock_esm("../../static/js/attachments_ui");
|
||||
const bot_data = mock_esm("../../static/js/bot_data");
|
||||
const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
|
||||
const composebox_typeahead = mock_esm("../../static/js/composebox_typeahead");
|
||||
const dark_theme = mock_esm("../../static/js/dark_theme");
|
||||
const emoji_picker = mock_esm("../../static/js/emoji_picker");
|
||||
|
@ -66,8 +67,13 @@ const settings_user_groups = mock_esm("../../static/js/settings_user_groups");
|
|||
const settings_users = mock_esm("../../static/js/settings_users");
|
||||
const stream_data = mock_esm("../../static/js/stream_data");
|
||||
const stream_events = mock_esm("../../static/js/stream_events");
|
||||
const stream_list = mock_esm("../../static/js/stream_list");
|
||||
const stream_settings_ui = mock_esm("../../static/js/stream_settings_ui");
|
||||
const stream_topic_history = mock_esm("../../static/js/stream_topic_history");
|
||||
const submessage = mock_esm("../../static/js/submessage");
|
||||
mock_esm("../../static/js/top_left_corner", {
|
||||
update_starred_count() {},
|
||||
});
|
||||
const typing_events = mock_esm("../../static/js/typing_events");
|
||||
const ui = mock_esm("../../static/js/ui");
|
||||
const unread_ops = mock_esm("../../static/js/unread_ops");
|
||||
|
@ -89,14 +95,10 @@ page_params.realm_description = "already set description";
|
|||
// For data-oriented modules, just use them, don't stub them.
|
||||
const alert_words = zrequire("alert_words");
|
||||
const emoji = zrequire("emoji");
|
||||
const stream_topic_history = zrequire("stream_topic_history");
|
||||
const stream_list = zrequire("stream_list");
|
||||
const message_helper = zrequire("message_helper");
|
||||
const message_store = zrequire("message_store");
|
||||
const people = zrequire("people");
|
||||
const starred_messages = zrequire("starred_messages");
|
||||
const user_status = zrequire("user_status");
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
|
||||
const server_events_dispatch = zrequire("server_events_dispatch");
|
||||
|
||||
|
@ -723,7 +725,7 @@ run_test("typing", ({override}) => {
|
|||
dispatch(event);
|
||||
});
|
||||
|
||||
run_test("user_settings", ({override, override_rewire}) => {
|
||||
run_test("user_settings", ({override}) => {
|
||||
settings_display.set_default_language_name = () => {};
|
||||
let event = event_fixtures.user_settings__default_language;
|
||||
user_settings.default_language = "en";
|
||||
|
@ -859,7 +861,6 @@ run_test("user_settings", ({override, override_rewire}) => {
|
|||
assert_same(user_settings.emojiset, "google");
|
||||
}
|
||||
|
||||
override_rewire(starred_messages, "rerender_ui", noop);
|
||||
event = event_fixtures.user_settings__starred_message_counts;
|
||||
user_settings.starred_message_counts = false;
|
||||
dispatch(event);
|
||||
|
@ -875,7 +876,7 @@ run_test("user_settings", ({override, override_rewire}) => {
|
|||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__demote_inactive_streams;
|
||||
override(stream_data, "set_filter_out_inactives", noop);
|
||||
override_rewire(stream_list, "update_streams_sidebar", stub.f);
|
||||
override(stream_list, "update_streams_sidebar", stub.f);
|
||||
user_settings.demote_inactive_streams = 1;
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
|
@ -931,9 +932,7 @@ run_test("update_message (unread)", ({override}) => {
|
|||
});
|
||||
});
|
||||
|
||||
run_test("update_message (add star)", ({override, override_rewire}) => {
|
||||
override_rewire(starred_messages, "rerender_ui", noop);
|
||||
|
||||
run_test("update_message (add star)", ({override}) => {
|
||||
const event = event_fixtures.update_message_flags__starred_add;
|
||||
const stub = make_stub();
|
||||
override(ui, "update_starred_view", stub.f);
|
||||
|
@ -946,8 +945,7 @@ run_test("update_message (add star)", ({override, override_rewire}) => {
|
|||
assert.equal(msg.starred, true);
|
||||
});
|
||||
|
||||
run_test("update_message (remove star)", ({override, override_rewire}) => {
|
||||
override_rewire(starred_messages, "rerender_ui", noop);
|
||||
run_test("update_message (remove star)", ({override}) => {
|
||||
const event = event_fixtures.update_message_flags__starred_remove;
|
||||
const stub = make_stub();
|
||||
override(ui, "update_starred_view", stub.f);
|
||||
|
@ -960,8 +958,7 @@ run_test("update_message (remove star)", ({override, override_rewire}) => {
|
|||
assert.equal(msg.starred, false);
|
||||
});
|
||||
|
||||
run_test("update_message (wrong data)", ({override_rewire}) => {
|
||||
override_rewire(starred_messages, "rerender_ui", noop);
|
||||
run_test("update_message (wrong data)", () => {
|
||||
const event = {
|
||||
...event_fixtures.update_message_flags__starred_add,
|
||||
messages: [0], // message does not exist
|
||||
|
@ -970,10 +967,10 @@ run_test("update_message (wrong data)", ({override_rewire}) => {
|
|||
// update_starred_view never gets invoked, early return is successful
|
||||
});
|
||||
|
||||
run_test("delete_message", ({override, override_rewire}) => {
|
||||
run_test("delete_message", ({override}) => {
|
||||
const event = event_fixtures.delete_message;
|
||||
|
||||
override_rewire(stream_list, "update_streams_sidebar", noop);
|
||||
override(stream_list, "update_streams_sidebar", noop);
|
||||
|
||||
const message_events_stub = make_stub();
|
||||
override(message_events, "remove_messages", message_events_stub.f);
|
||||
|
@ -982,7 +979,7 @@ run_test("delete_message", ({override, override_rewire}) => {
|
|||
override(unread_ops, "process_read_messages_event", unread_ops_stub.f);
|
||||
|
||||
const stream_topic_history_stub = make_stub();
|
||||
override_rewire(stream_topic_history, "remove_messages", stream_topic_history_stub.f);
|
||||
override(stream_topic_history, "remove_messages", stream_topic_history_stub.f);
|
||||
|
||||
dispatch(event);
|
||||
|
||||
|
@ -1001,7 +998,7 @@ run_test("delete_message", ({override, override_rewire}) => {
|
|||
assert_same(args.opts.max_removed_msg_id, 1337);
|
||||
});
|
||||
|
||||
run_test("user_status", ({override, override_rewire}) => {
|
||||
run_test("user_status", ({override}) => {
|
||||
let event = event_fixtures.user_status__set_away;
|
||||
{
|
||||
const stub = make_stub();
|
||||
|
@ -1044,7 +1041,7 @@ run_test("user_status", ({override, override_rewire}) => {
|
|||
{
|
||||
const stub = make_stub();
|
||||
override(activity, "redraw_user", stub.f);
|
||||
override_rewire(compose_pm_pill, "get_user_ids", () => [event.user_id]);
|
||||
override(compose_pm_pill, "get_user_ids", () => [event.user_id]);
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
const args = stub.get_args("user_id");
|
||||
|
|
|
@ -26,8 +26,9 @@ message_lists.current = {};
|
|||
|
||||
const peer_data = zrequire("peer_data");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const server_events_dispatch = zrequire("server_events_dispatch");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const sub_store = zrequire("sub_store");
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
|
@ -44,9 +45,9 @@ people.initialize_current_user(me.user_id);
|
|||
const dispatch = server_events_dispatch.dispatch_normal_event;
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override, override_rewire}) => {
|
||||
run_test(label, (helpers) => {
|
||||
stream_data.clear_subscriptions();
|
||||
f({override, override_rewire});
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -181,23 +182,21 @@ test("stream update", ({override}) => {
|
|||
assert.equal(args.value, event.value);
|
||||
});
|
||||
|
||||
test("stream create", ({override, override_rewire}) => {
|
||||
test("stream create", ({override}) => {
|
||||
assert.equal(sub_store.get(101), undefined);
|
||||
assert.equal(sub_store.get(102), undefined);
|
||||
|
||||
const event = event_fixtures.stream__create;
|
||||
|
||||
const stub = make_stub();
|
||||
override_rewire(stream_data, "create_streams", stub.f);
|
||||
override(stream_settings_ui, "add_sub_to_table", noop);
|
||||
override(overlays, "streams_open", () => true);
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
const args = stub.get_args("streams");
|
||||
assert.deepEqual(
|
||||
args.streams.map((stream) => stream.stream_id),
|
||||
[101, 102],
|
||||
);
|
||||
|
||||
assert.deepEqual(sub_store.get(101).name, "devel");
|
||||
assert.deepEqual(sub_store.get(102).name, "test");
|
||||
});
|
||||
|
||||
test("stream delete (normal)", ({override, override_rewire}) => {
|
||||
test("stream delete (normal)", ({override}) => {
|
||||
const event = event_fixtures.stream__delete;
|
||||
|
||||
for (const stream of event.streams) {
|
||||
|
@ -206,7 +205,6 @@ test("stream delete (normal)", ({override, override_rewire}) => {
|
|||
|
||||
stream_data.subscribe_myself(event.streams[0]);
|
||||
|
||||
override_rewire(stream_data, "delete_sub", noop);
|
||||
override(settings_streams, "update_default_streams_table", noop);
|
||||
|
||||
narrow_state.is_for_stream_id = () => true;
|
||||
|
|
|
@ -18,6 +18,9 @@ const compose_state = mock_esm("../../static/js/compose_state");
|
|||
mock_esm("../../static/js/markdown", {
|
||||
apply_markdown: noop,
|
||||
});
|
||||
mock_esm("../../static/js/overlays", {
|
||||
open_overlay: noop,
|
||||
});
|
||||
mock_esm("../../static/js/stream_data", {
|
||||
get_color() {
|
||||
return "#FFFFFF";
|
||||
|
@ -89,10 +92,10 @@ const short_msg = {
|
|||
};
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override, override_rewire, mock_template}) => {
|
||||
run_test(label, (helpers) => {
|
||||
$("#draft_overlay").css = () => {};
|
||||
window.localStorage.clear();
|
||||
f({override, override_rewire, mock_template});
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -419,7 +422,6 @@ test("format_drafts", ({override_rewire, mock_template}) => {
|
|||
return "<draft table stub>";
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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…"));
|
||||
|
|
|
@ -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", () => {
|
||||
|
|
|
@ -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"}];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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`"), "<p>type <code>/day</code></p>");
|
||||
});
|
||||
|
||||
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}) => {
|
|||
'<p><span aria-label="bike" class="emoji emoji-1f6b2" role="img" title="bike">:bike:</span></p>',
|
||||
);
|
||||
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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", () => {
|
||||
$("<div>").set_find_results(".emoji", {replaceWith() {}});
|
||||
|
||||
let n; // Object for storing all notification data for assertions.
|
||||
let last_closed_message_id = null;
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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 = () => {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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"};
|
||||
});
|
||||
|
|
|
@ -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 <strong>Te</strong>d 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"';
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(!$("<devel-sidebar-row-stub>").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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(<MAX_USERS_TO_DISPLAY_NAME) typists, both of them
|
||||
// should be rendered but not 'Several people are typing…'
|
||||
override_rewire(typing_events, "get_users_typing_for_narrow", () => 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());
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue