node-tests: Remove mock of `topic_list` in `topic_list_data.test`.

With commit f0d1332ba2, we no longer need to mock `topic_list.js`
in the `topic_list_data` node test. Instead, we can pass a string
directly to that function. The default is an empty string unless
there is a search input. Also, updates the default of the zoom to
be false instead of undefined in the tests.
This commit is contained in:
Lauryn Menard 2023-04-12 13:22:52 +02:00 committed by Tim Abbott
parent 9ed1c79f1b
commit b9023db04e
1 changed files with 11 additions and 12 deletions

View File

@ -24,10 +24,6 @@ const narrow_state = mock_esm("../src/narrow_state", {
topic() {}, topic() {},
}); });
const topic_list = mock_esm("../src/topic_list", {
get_topic_search_term() {},
});
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history"); const stream_topic_history = zrequire("stream_topic_history");
const topic_list_data = zrequire("topic_list_data"); const topic_list_data = zrequire("topic_list_data");
@ -40,9 +36,11 @@ const general = {
stream_data.add_sub(general); stream_data.add_sub(general);
function get_list_info(zoomed) { function get_list_info(zoom, search) {
const stream_id = general.stream_id; const stream_id = general.stream_id;
return topic_list_data.get_list_info(stream_id, zoomed, topic_list.get_topic_search_term()); const zoomed = zoom === undefined ? false : zoom;
const search_term = search === undefined ? "" : search;
return topic_list_data.get_list_info(stream_id, zoomed, search_term);
} }
function test(label, f) { function test(label, f) {
@ -112,11 +110,10 @@ test("get_list_info w/real stream_topic_history", ({override}) => {
unread: 0, unread: 0,
url: "#narrow/stream/556-general/topic/topic.208", url: "#narrow/stream/556-general/topic/topic.208",
}); });
// If we zoom in, our results based on topic filter.
// If topic search input is empty, we show all 10 topics.
// If we zoom in, our results are based on topic filter.
// If topic search input is empty, we show all 10 topics.
const zoomed = true; const zoomed = true;
override(topic_list, "get_topic_search_term", () => "");
list_info = get_list_info(zoomed); list_info = get_list_info(zoomed);
assert.equal(list_info.items.length, 10); assert.equal(list_info.items.length, 10);
assert.equal(list_info.more_topics_unreads, 0); assert.equal(list_info.more_topics_unreads, 0);
@ -125,9 +122,11 @@ test("get_list_info w/real stream_topic_history", ({override}) => {
add_topic_message("After Brooklyn", 1008); add_topic_message("After Brooklyn", 1008);
add_topic_message("Catering", 1009); add_topic_message("Catering", 1009);
// when topic search is open then we list topics based on search term.
override(topic_list, "get_topic_search_term", () => "b,c"); // When topic search input is not empty, we show topics
list_info = get_list_info(zoomed); // based on the search term.
const search_term = "b,c";
list_info = get_list_info(zoomed, search_term);
assert.equal(list_info.items.length, 2); assert.equal(list_info.items.length, 2);
assert.equal(list_info.more_topics_unreads, 0); assert.equal(list_info.more_topics_unreads, 0);
assert.equal(list_info.more_topics_have_unread_mention_messages, false); assert.equal(list_info.more_topics_have_unread_mention_messages, false);