mirror of https://github.com/zulip/zulip.git
tests: Replace unneeded override_rewire uses by whole-module mocks.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
15db564246
commit
959e51fe58
|
@ -63,7 +63,6 @@ mock_esm("../src/popovers", {
|
|||
|
||||
const people = zrequire("people");
|
||||
|
||||
const compose_setup = zrequire("compose_setup");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose_actions = zrequire("compose_actions");
|
||||
const compose_reply = zrequire("compose_reply");
|
||||
|
@ -223,11 +222,9 @@ test("start", ({override, override_rewire, mock_template}) => {
|
|||
};
|
||||
|
||||
let abort_xhr_called = false;
|
||||
override_rewire(compose_setup, "abort_xhr", () => {
|
||||
compose_actions.register_compose_cancel_hook(() => {
|
||||
abort_xhr_called = true;
|
||||
});
|
||||
|
||||
compose_actions.register_compose_cancel_hook(compose_setup.abort_xhr);
|
||||
$("textarea#compose-textarea").set_height(50);
|
||||
|
||||
assert_hidden("#compose_controls");
|
||||
|
|
|
@ -46,7 +46,6 @@ const people = zrequire("people");
|
|||
const user_groups = zrequire("user_groups");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const stream_list_sort = zrequire("stream_list_sort");
|
||||
const compose = zrequire("compose");
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
const compose_recipient = zrequire("compose_recipient");
|
||||
const composebox_typeahead = zrequire("composebox_typeahead");
|
||||
|
@ -1154,12 +1153,12 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
|
||||
user_settings.enter_sends = false;
|
||||
let compose_finish_called = false;
|
||||
override_rewire(compose, "finish", () => {
|
||||
function finish() {
|
||||
compose_finish_called = true;
|
||||
});
|
||||
}
|
||||
|
||||
ct.initialize({
|
||||
on_enter_send: compose.finish,
|
||||
on_enter_send: finish,
|
||||
});
|
||||
|
||||
$("#private_message_recipient").val("othello@zulip.com, ");
|
||||
|
@ -1301,7 +1300,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
$("#private_message_recipient").off("blur");
|
||||
$("#send_later").css = noop;
|
||||
ct.initialize({
|
||||
on_enter_send: compose.finish,
|
||||
on_enter_send: finish,
|
||||
});
|
||||
|
||||
// Now let's make sure that all the stub functions have been called
|
||||
|
|
|
@ -12,6 +12,7 @@ const {realm} = require("./lib/zpage_params");
|
|||
const event_fixtures = events.fixtures;
|
||||
const test_user = events.test_user;
|
||||
|
||||
const compose_recipient = mock_esm("../src/compose_recipient");
|
||||
const message_lists = mock_esm("../src/message_lists");
|
||||
const narrow_state = mock_esm("../src/narrow_state");
|
||||
const overlays = mock_esm("../src/overlays");
|
||||
|
@ -22,7 +23,6 @@ const stream_list = mock_esm("../src/stream_list");
|
|||
const stream_settings_ui = mock_esm("../src/stream_settings_ui");
|
||||
message_lists.current = {};
|
||||
|
||||
const compose_recipient = zrequire("compose_recipient");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const peer_data = zrequire("peer_data");
|
||||
const people = zrequire("people");
|
||||
|
@ -259,8 +259,8 @@ test("stream delete (special streams)", ({override}) => {
|
|||
assert.equal(realm.realm_zulip_update_announcements_stream_id, -1);
|
||||
});
|
||||
|
||||
test("stream delete (stream is selected in compose)", ({override, override_rewire}) => {
|
||||
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
||||
test("stream delete (stream is selected in compose)", ({override}) => {
|
||||
override(compose_recipient, "on_compose_select_recipient_update", noop);
|
||||
|
||||
const event = event_fixtures.stream__delete;
|
||||
|
||||
|
|
|
@ -8,8 +8,10 @@ const {run_test, noop} = require("./lib/test");
|
|||
const $ = require("./lib/zjquery");
|
||||
const {user_settings} = require("./lib/zpage_params");
|
||||
|
||||
const user_pill = mock_esm("../src/user_pill");
|
||||
const messages_overlay_ui = mock_esm("../src/messages_overlay_ui");
|
||||
|
||||
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||
const user_pill = zrequire("user_pill");
|
||||
const people = zrequire("people");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose_recipient = zrequire("compose_recipient");
|
||||
|
@ -60,7 +62,6 @@ user_settings.twenty_four_hour_time = false;
|
|||
const {localstorage} = zrequire("localstorage");
|
||||
const drafts = zrequire("drafts");
|
||||
const drafts_overlay_ui = zrequire("drafts_overlay_ui");
|
||||
const messages_overlay_ui = zrequire("messages_overlay_ui");
|
||||
const timerender = zrequire("timerender");
|
||||
|
||||
const mock_current_timestamp = 1234;
|
||||
|
@ -189,7 +190,7 @@ test("draft_model delete", ({override_rewire}) => {
|
|||
});
|
||||
|
||||
test("snapshot_message", ({override, override_rewire}) => {
|
||||
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
||||
mock_banners();
|
||||
|
||||
|
@ -287,7 +288,7 @@ test("update_draft", ({override, override_rewire}) => {
|
|||
assert.equal(draft_id, undefined);
|
||||
|
||||
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
||||
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
compose_state.set_message_type("private");
|
||||
compose_state.message_content("dummy content");
|
||||
compose_state.private_message_recipient(aaron.email);
|
||||
|
@ -443,7 +444,7 @@ test("delete_all_drafts", ({override_rewire}) => {
|
|||
assert.deepEqual(draft_model.get(), {});
|
||||
});
|
||||
|
||||
test("format_drafts", ({override_rewire, mock_template}) => {
|
||||
test("format_drafts", ({override, override_rewire, mock_template}) => {
|
||||
override_rewire(stream_data, "get_color", () => "#FFFFFF");
|
||||
function feb12() {
|
||||
return new Date(1549958107000); // 2/12/2019 07:55:07 AM (UTC+0)
|
||||
|
@ -560,7 +561,7 @@ test("format_drafts", ({override_rewire, mock_template}) => {
|
|||
return {name: "stream 2", stream_id, invite_only: false, is_web_public: false};
|
||||
});
|
||||
|
||||
override_rewire(user_pill, "get_user_ids", () => []);
|
||||
override(user_pill, "get_user_ids", () => []);
|
||||
compose_state.set_message_type("private");
|
||||
compose_state.private_message_recipient(null);
|
||||
|
||||
|
@ -571,7 +572,7 @@ test("format_drafts", ({override_rewire, mock_template}) => {
|
|||
return "<draft table stub>";
|
||||
});
|
||||
|
||||
override_rewire(messages_overlay_ui, "set_initial_element", noop);
|
||||
override(messages_overlay_ui, "set_initial_element", noop);
|
||||
|
||||
const $unread_count = $("<unread-count-stub>");
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
@ -600,7 +601,7 @@ test("format_drafts", ({override_rewire, mock_template}) => {
|
|||
drafts_overlay_ui.launch();
|
||||
});
|
||||
|
||||
test("filter_drafts", ({override_rewire, mock_template}) => {
|
||||
test("filter_drafts", ({override, override_rewire, mock_template}) => {
|
||||
override_rewire(stream_data, "get_color", () => "#FFFFFF");
|
||||
function feb12() {
|
||||
return new Date(1549958107000); // 2/12/2019 07:55:07 AM (UTC+0)
|
||||
|
@ -733,12 +734,12 @@ test("filter_drafts", ({override_rewire, mock_template}) => {
|
|||
return "<draft table stub>";
|
||||
});
|
||||
|
||||
override_rewire(messages_overlay_ui, "set_initial_element", noop);
|
||||
override(messages_overlay_ui, "set_initial_element", noop);
|
||||
|
||||
const $unread_count = $("<unread-count-stub>");
|
||||
$(".top_left_drafts").set_find_results(".unread_count", $unread_count);
|
||||
|
||||
override_rewire(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
override(user_pill, "get_user_ids", () => [aaron.user_id]);
|
||||
override_rewire(compose_pm_pill, "set_from_emails", noop);
|
||||
compose_state.set_message_type("private");
|
||||
compose_state.private_message_recipient(aaron.email);
|
||||
|
|
|
@ -32,6 +32,7 @@ set_global("navigator", {
|
|||
// jQuery stuff should go away if we make an initialize() method.
|
||||
set_global("document", "document-stub");
|
||||
|
||||
const activity_ui = mock_esm("../src/activity_ui");
|
||||
const browser_history = mock_esm("../src/browser_history");
|
||||
const compose_actions = mock_esm("../src/compose_actions");
|
||||
const compose_reply = mock_esm("../src/compose_reply");
|
||||
|
@ -121,7 +122,6 @@ message_lists.current = {
|
|||
},
|
||||
};
|
||||
|
||||
const activity_ui = zrequire("activity_ui");
|
||||
const emoji = zrequire("emoji");
|
||||
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
|
||||
const hotkey = zrequire("hotkey");
|
||||
|
@ -139,14 +139,6 @@ function stubbing(module, func_name_to_stub, test_function) {
|
|||
});
|
||||
}
|
||||
|
||||
function stubbing_rewire(module, func_name_to_stub, test_function) {
|
||||
with_overrides(({override_rewire}) => {
|
||||
const stub = make_stub();
|
||||
override_rewire(module, func_name_to_stub, stub.f);
|
||||
test_function(stub);
|
||||
});
|
||||
}
|
||||
|
||||
// Set up defaults for most tests.
|
||||
hotkey.__Rewire__("processing_text", () => false);
|
||||
|
||||
|
@ -263,13 +255,6 @@ function assert_mapping(c, module, func_name, shiftKey, keydown) {
|
|||
});
|
||||
}
|
||||
|
||||
function assert_mapping_rewire(c, module, func_name, shiftKey) {
|
||||
stubbing_rewire(module, func_name, (stub) => {
|
||||
assert.ok(process(c, shiftKey));
|
||||
assert.equal(stub.num_calls, 1);
|
||||
});
|
||||
}
|
||||
|
||||
function assert_unmapped(s) {
|
||||
for (const c of s) {
|
||||
assert.equal(process(c), false);
|
||||
|
@ -327,7 +312,7 @@ run_test("streams", ({override}) => {
|
|||
run_test("basic mappings", () => {
|
||||
assert_mapping("?", browser_history, "go_to_location");
|
||||
assert_mapping("/", search, "initiate_search");
|
||||
assert_mapping_rewire("w", activity_ui, "initiate_search");
|
||||
assert_mapping("w", activity_ui, "initiate_search");
|
||||
assert_mapping("q", stream_list, "initiate_search");
|
||||
|
||||
assert_mapping("A", narrow, "stream_cycle_backward");
|
||||
|
|
|
@ -9,6 +9,7 @@ const blueslip = require("./lib/zblueslip");
|
|||
const $ = require("./lib/zjquery");
|
||||
|
||||
const color_data = mock_esm("../src/color_data");
|
||||
const compose_recipient = mock_esm("../src/compose_recipient");
|
||||
const stream_color_events = mock_esm("../src/stream_color_events");
|
||||
const stream_list = mock_esm("../src/stream_list");
|
||||
const stream_muting = mock_esm("../src/stream_muting");
|
||||
|
@ -44,7 +45,6 @@ const people = zrequire("people");
|
|||
const settings_config = zrequire("settings_config");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const stream_events = zrequire("stream_events");
|
||||
const compose_recipient = zrequire("compose_recipient");
|
||||
|
||||
const george = {
|
||||
email: "george@zulip.com",
|
||||
|
@ -94,9 +94,9 @@ function test(label, f) {
|
|||
});
|
||||
}
|
||||
|
||||
test("update_property", ({override, override_rewire}) => {
|
||||
override_rewire(compose_recipient, "possibly_update_stream_name_in_compose", noop);
|
||||
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
||||
test("update_property", ({override}) => {
|
||||
override(compose_recipient, "possibly_update_stream_name_in_compose", noop);
|
||||
override(compose_recipient, "on_compose_select_recipient_update", noop);
|
||||
|
||||
const sub = {...frontend};
|
||||
stream_data.add_sub(sub);
|
||||
|
|
Loading…
Reference in New Issue