mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
js: Convert static/js/narrow_state.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
a1e9be884d
commit
b830f53eb5
@@ -39,9 +39,12 @@ rewiremock("../../static/js/drafts").with({
|
||||
update_draft: noop,
|
||||
});
|
||||
|
||||
const narrow_state = set_global("narrow_state", {
|
||||
const narrow_state = {
|
||||
__esModule: true,
|
||||
set_compose_defaults: noop,
|
||||
});
|
||||
};
|
||||
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
|
||||
set_global("unread_ops", {
|
||||
notify_server_message_read: noop,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
@@ -15,12 +17,15 @@ const compose_fade = set_global("compose_fade", {});
|
||||
const stream_events = set_global("stream_events", {});
|
||||
const subs = set_global("subs", {});
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
const peer_data = zrequire("peer_data");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
||||
set_global("current_msg_list", {});
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
const page_params = set_global("page_params", {});
|
||||
const overlays = set_global("overlays", {});
|
||||
const settings_org = set_global("settings_org", {});
|
||||
@@ -266,3 +271,4 @@ test("stream delete (special streams)", (override) => {
|
||||
assert.equal(page_params.realm_notifications_stream_id, -1);
|
||||
assert.equal(page_params.realm_signup_notifications_stream_id, -1);
|
||||
});
|
||||
rewiremock.disable();
|
||||
|
||||
@@ -41,7 +41,8 @@ set_global("message_scroll", {
|
||||
});
|
||||
const message_util = set_global("message_util", {});
|
||||
const message_store = set_global("message_store", {});
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
const pm_list = {__esModule: true};
|
||||
rewiremock("../../static/js/pm_list").with(pm_list);
|
||||
const server_events = set_global("server_events", {});
|
||||
|
||||
@@ -26,7 +26,8 @@ set_global("document", {
|
||||
},
|
||||
});
|
||||
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
const stream_data = set_global("stream_data", {});
|
||||
set_global("recent_topics", {
|
||||
is_visible: () => false,
|
||||
|
||||
@@ -67,7 +67,7 @@ function test_with(fixture) {
|
||||
},
|
||||
};
|
||||
|
||||
narrow_state.get_first_unread_info = () => fixture.unread_info;
|
||||
narrow_state.__Rewire__("get_first_unread_info", () => fixture.unread_info);
|
||||
|
||||
narrow.maybe_add_local_messages({
|
||||
id_info,
|
||||
|
||||
@@ -204,7 +204,7 @@ run_test("defensive code", () => {
|
||||
// _possible_unread_message_ids for any case where we
|
||||
// couldn't compute the unread message ids, but that
|
||||
// invariant is hard to future-proof.
|
||||
narrow_state._possible_unread_message_ids = () => undefined;
|
||||
narrow_state.__Rewire__("_possible_unread_message_ids", () => undefined);
|
||||
const terms = [{operator: "some-unhandled-case", operand: "whatever"}];
|
||||
set_filter(terms);
|
||||
assert_unread_info({
|
||||
|
||||
@@ -8,7 +8,8 @@ const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
set_global("ui", {
|
||||
get_content_element: (element) => element,
|
||||
});
|
||||
|
||||
@@ -46,7 +46,6 @@ rewiremock.enable();
|
||||
|
||||
zrequire("hash_util");
|
||||
zrequire("narrow");
|
||||
zrequire("narrow_state");
|
||||
const people = zrequire("people");
|
||||
zrequire("presence");
|
||||
zrequire("buddy_data");
|
||||
|
||||
@@ -168,7 +168,6 @@ set_global("stream_data", {
|
||||
rewiremock.enable();
|
||||
|
||||
zrequire("message_util");
|
||||
zrequire("narrow_state");
|
||||
const people = zrequire("people");
|
||||
let rt = zrequire("recent_topics");
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
@@ -12,7 +14,11 @@ set_global("page_params", {
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
const narrow_state = set_global("narrow_state", {filter: () => false});
|
||||
const narrow_state = {
|
||||
__esModule: true,
|
||||
filter: () => false,
|
||||
};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
const search_suggestion = set_global("search_suggestion", {});
|
||||
set_global("ui_util", {
|
||||
change_tab_to: noop,
|
||||
@@ -27,6 +33,8 @@ set_global("search_pill_widget", {
|
||||
|
||||
set_global("setTimeout", (func) => func());
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
const search = zrequire("search");
|
||||
const search_pill = zrequire("search_pill");
|
||||
const {Filter} = zrequire("Filter", "js/filter");
|
||||
@@ -341,3 +349,4 @@ run_test("initiate_search", () => {
|
||||
assert(is_searchbox_text_selected);
|
||||
assert(is_searchbox_focused);
|
||||
});
|
||||
rewiremock.disable();
|
||||
|
||||
@@ -14,7 +14,8 @@ set_global("page_params", {
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
const search_suggestion = set_global("search_suggestion", {});
|
||||
set_global("ui_util", {
|
||||
change_tab_to: noop,
|
||||
|
||||
@@ -88,7 +88,7 @@ run_test("basic_get_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => "office";
|
||||
narrow_state.__Rewire__("stream", () => "office");
|
||||
|
||||
const suggestions = get_suggestions("", query);
|
||||
|
||||
@@ -102,7 +102,7 @@ run_test("subset_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
const suggestions = get_suggestions(base_query, query);
|
||||
|
||||
@@ -114,7 +114,7 @@ run_test("subset_suggestions", () => {
|
||||
run_test("private_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let query = "is:private";
|
||||
let suggestions = get_suggestions("", query);
|
||||
@@ -231,7 +231,7 @@ run_test("private_suggestions", () => {
|
||||
run_test("group_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
// Entering a comma in a pm-with query should immediately generate
|
||||
// suggestions for the next person.
|
||||
@@ -372,7 +372,7 @@ run_test("empty_query_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
const suggestions = get_suggestions("", query);
|
||||
|
||||
@@ -413,7 +413,7 @@ run_test("has_suggestions", () => {
|
||||
// default suggestion when suggesting `has` operator.
|
||||
let query = "h";
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let suggestions = get_suggestions("", query);
|
||||
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
||||
@@ -467,7 +467,7 @@ run_test("has_suggestions", () => {
|
||||
run_test("check_is_suggestions", () => {
|
||||
let query = "i";
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let suggestions = get_suggestions("", query);
|
||||
let expected = [
|
||||
@@ -571,7 +571,7 @@ run_test("check_is_suggestions", () => {
|
||||
run_test("sent_by_me_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let query = "";
|
||||
let suggestions = get_suggestions("", query);
|
||||
@@ -650,7 +650,7 @@ run_test("topic_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["office"];
|
||||
|
||||
narrow_state.stream = () => "office";
|
||||
narrow_state.__Rewire__("stream", () => "office");
|
||||
|
||||
const devel_id = 44;
|
||||
const office_id = 77;
|
||||
@@ -739,7 +739,7 @@ run_test("whitespace_glitch", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["office"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
@@ -753,7 +753,7 @@ run_test("whitespace_glitch", () => {
|
||||
run_test("stream_completion", () => {
|
||||
stream_data.subscribed_streams = () => ["office", "dev help"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
@@ -775,7 +775,7 @@ run_test("stream_completion", () => {
|
||||
|
||||
function people_suggestion_setup() {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
narrow_state.stream = noop;
|
||||
narrow_state.__Rewire__("stream", noop);
|
||||
|
||||
const ted = {
|
||||
email: "ted@zulip.com",
|
||||
@@ -923,7 +923,7 @@ run_test("operator_suggestions", () => {
|
||||
run_test("queries_with_spaces", () => {
|
||||
stream_data.subscribed_streams = () => ["office", "dev help"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ run_test("basic_get_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => "office";
|
||||
narrow_state.__Rewire__("stream", () => "office");
|
||||
|
||||
const suggestions = get_suggestions("", query);
|
||||
|
||||
@@ -97,7 +97,7 @@ run_test("subset_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
const suggestions = get_suggestions("", query);
|
||||
|
||||
@@ -113,7 +113,7 @@ run_test("subset_suggestions", () => {
|
||||
run_test("private_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let query = "is:private";
|
||||
let suggestions = get_suggestions("", query);
|
||||
@@ -226,7 +226,7 @@ run_test("private_suggestions", () => {
|
||||
run_test("group_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
// Entering a comma in a pm-with query should immediately generate
|
||||
// suggestions for the next person.
|
||||
@@ -374,7 +374,7 @@ run_test("empty_query_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
const suggestions = get_suggestions("", query);
|
||||
|
||||
@@ -415,7 +415,7 @@ run_test("has_suggestions", () => {
|
||||
// default suggestion when suggesting `has` operator.
|
||||
let query = "h";
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let suggestions = get_suggestions("", query);
|
||||
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
||||
@@ -471,7 +471,7 @@ run_test("has_suggestions", () => {
|
||||
|
||||
run_test("check_is_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => ["devel", "office"];
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let query = "i";
|
||||
let suggestions = get_suggestions("", query);
|
||||
@@ -541,7 +541,7 @@ run_test("check_is_suggestions", () => {
|
||||
run_test("sent_by_me_suggestions", () => {
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
let query = "";
|
||||
let suggestions = get_suggestions("", query);
|
||||
@@ -615,7 +615,7 @@ run_test("topic_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["office"];
|
||||
|
||||
narrow_state.stream = () => "office";
|
||||
narrow_state.__Rewire__("stream", () => "office");
|
||||
|
||||
const devel_id = 44;
|
||||
const office_id = 77;
|
||||
@@ -710,7 +710,7 @@ run_test("whitespace_glitch", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => ["office"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
@@ -724,7 +724,7 @@ run_test("whitespace_glitch", () => {
|
||||
run_test("stream_completion", () => {
|
||||
stream_data.subscribed_streams = () => ["office", "dev help"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
@@ -749,7 +749,7 @@ run_test("people_suggestions", () => {
|
||||
|
||||
stream_data.subscribed_streams = () => [];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
const ted = {
|
||||
email: "ted@zulip.com",
|
||||
@@ -863,7 +863,7 @@ run_test("operator_suggestions", () => {
|
||||
run_test("queries_with_spaces", () => {
|
||||
stream_data.subscribed_streams = () => ["office", "dev help"];
|
||||
|
||||
narrow_state.stream = () => {};
|
||||
narrow_state.__Rewire__("stream", () => {});
|
||||
|
||||
stream_topic_history.reset();
|
||||
|
||||
|
||||
@@ -383,12 +383,12 @@ let narrow_state;
|
||||
test_ui("narrowing", () => {
|
||||
initialize_stream_data();
|
||||
|
||||
narrow_state = set_global("narrow_state", {
|
||||
narrow_state = rewiremock("../../static/js/narrow_state").with({
|
||||
stream() {
|
||||
return "devel";
|
||||
},
|
||||
topic: noop,
|
||||
});
|
||||
}).mock.value;
|
||||
|
||||
topic_list.close = noop;
|
||||
topic_list.rebuild = noop;
|
||||
|
||||
@@ -8,9 +8,11 @@ const rewiremock = require("rewiremock/node");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
const narrow_state = set_global("narrow_state", {
|
||||
const narrow_state = {
|
||||
__esModule: true,
|
||||
topic() {},
|
||||
});
|
||||
};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
set_global("unread", {});
|
||||
const muting = {
|
||||
__esModule: true,
|
||||
|
||||
@@ -116,7 +116,6 @@ zrequire("condense");
|
||||
zrequire("lightbox");
|
||||
zrequire("overlays");
|
||||
zrequire("message_view_header");
|
||||
zrequire("narrow_state");
|
||||
zrequire("presence");
|
||||
zrequire("search_pill_widget");
|
||||
zrequire("unread");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const _ = require("lodash");
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
@@ -11,11 +12,13 @@ let page_params = set_global("page_params", {
|
||||
realm_push_notifications_enabled: false,
|
||||
});
|
||||
|
||||
set_global("narrow_state", {});
|
||||
rewiremock("../../static/js/narrow_state").with({});
|
||||
set_global("current_msg_list", {});
|
||||
set_global("home_msg_list", {});
|
||||
const message_store = set_global("message_store", {});
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
const muting = zrequire("muting");
|
||||
const people = zrequire("people");
|
||||
const stream_data = zrequire("stream_data");
|
||||
@@ -693,3 +696,4 @@ run_test("errors", () => {
|
||||
assert.equal(counts.private_message_count, 0);
|
||||
test_notifiable_count(counts.home_unread_messages, 0);
|
||||
});
|
||||
rewiremock.disable();
|
||||
|
||||
@@ -38,7 +38,7 @@ rewiremock("../../static/js/pm_list").with({
|
||||
update_private_messages() {},
|
||||
});
|
||||
|
||||
set_global("narrow_state", {
|
||||
rewiremock("../../static/js/narrow_state").with({
|
||||
update_email() {},
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ const poll_widget = {__esModule: true};
|
||||
rewiremock("../../static/js/poll_widget").with(poll_widget);
|
||||
set_global("document", "document-stub");
|
||||
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const narrow_state = {__esModule: true};
|
||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||
set_global("current_msg_list", {});
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
Reference in New Issue
Block a user