Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

node tests: Use override in topic_list_data.

Steve Howelle971cff5b866
diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js
index b022c97a94d..8ca4bb4b6df 100644
--- a/frontend_tests/node_tests/topic_list_data.js
+++ b/frontend_tests/node_tests/topic_list_data.js
@@ -7,9 +7,15 @@ const _ = require("lodash");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const narrow_state = set_global("narrow_state", {});
+const narrow_state = set_global("narrow_state", {
+ topic() {},
+});
set_global("unread", {});
-const muting = set_global("muting", {});
+const muting = set_global("muting", {
+ is_topic_muted() {
+ return false;
+ },
+});
set_global("message_list", {});
zrequire("hash_util");
@@ -25,20 +31,12 @@ const general = {
stream_data.add_sub(general);
-function clear() {
- narrow_state.topic = () => undefined;
- stream_topic_history.reset();
- muting.is_topic_muted = () => false;
-}
-
function get_list_info(zoomed) {
const stream_id = general.stream_id;
return topic_list_data.get_list_info(stream_id, zoomed);
}
-run_test("get_list_info w/real stream_topic_history", () => {
- clear();
-
+run_test("get_list_info w/real stream_topic_history", (override) => {
let list_info;
const empty_list_info = get_list_info();
@@ -57,7 +55,7 @@ run_test("get_list_info w/real stream_topic_history", () => {
});
}
- narrow_state.topic = () => "topic 6";
+ override(narrow_state, "topic", () => "topic 6");
list_info = get_list_info();
assert.equal(list_info.items.length, 5);
@@ -81,20 +79,18 @@ run_test("get_list_info w/real stream_topic_history", () => {
assert.equal(list_info.num_possible_topics, 7);
});
-run_test("get_list_info unreads", () => {
- clear();
-
+run_test("get_list_info unreads", (override) => {
let list_info;
- // Going forward, we just stub get_recent_topic_names
- // for simpler test setup.
- stream_topic_history.get_recent_topic_names = () => _.range(15).map((i) => "topic " + i);
+ override(stream_topic_history, "get_recent_topic_names", () =>
+ _.range(15).map((i) => "topic " + i),
+ );
const unread_cnt = new Map();
- unread.num_unread_for_topic = (stream_id, topic_name) => {
+ override(unread, "num_unread_for_topic", (stream_id, topic_name) => {
assert.equal(stream_id, general.stream_id);
return unread_cnt.get(topic_name) || 0;
- };
+ });
/*
We have 15 topics, but we only show up
@@ -135,10 +131,10 @@ run_test("get_list_info unreads", () => {
unread_cnt.set("topic 5", 5);
unread_cnt.set("topic 13", 13);
- muting.is_topic_muted = (stream_id, topic_name) => {
+ override(muting, "is_topic_muted", (stream_id, topic_name) => {
assert.equal(stream_id, general.stream_id);
return topic_name === "topic 4";
- };
+ });
list_info = get_list_info();
assert.equal(list_info.items.length, 8);