From 5c0d63fb9a92b4dec03f3521ebdc34eb3cc933f4 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 31 May 2023 15:43:46 -0700 Subject: [PATCH] stream_list: Extract initialize_stream_cursor. This does not create an event handler and thus did not belong in set_event_handlers. --- web/src/stream_list.js | 34 +++++++++++++++++++--------------- web/tests/stream_list.test.js | 7 +------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/web/src/stream_list.js b/web/src/stream_list.js index c08195042b..9447ece170 100644 --- a/web/src/stream_list.js +++ b/web/src/stream_list.js @@ -683,6 +683,24 @@ function actually_update_streams_for_search() { const update_streams_for_search = _.throttle(actually_update_streams_for_search, 50); +// Exported for tests only. +export function initialize_stream_cursor() { + stream_cursor = new ListCursor({ + list: { + scroll_container_sel: "#left_sidebar_scroll_container", + find_li(opts) { + const stream_id = opts.key; + const li = get_stream_li(stream_id); + return li; + }, + first_key: stream_list_sort.first_stream_id, + prev_key: stream_list_sort.prev_stream_id, + next_key: stream_list_sort.next_stream_id, + }, + highlight_class: "highlighted_stream", + }); +} + export function initialize() { create_initial_sidebar_rows(); @@ -690,6 +708,7 @@ export function initialize() { // when new messages come in, but it's fairly quick. build_stream_list(); update_subscribe_to_more_streams_link(); + initialize_stream_cursor(); set_event_handlers(); } @@ -745,21 +764,6 @@ export function set_event_handlers() { toggle_pm_header_icon(); }); - stream_cursor = new ListCursor({ - list: { - scroll_container_sel: "#left_sidebar_scroll_container", - find_li(opts) { - const stream_id = opts.key; - const li = get_stream_li(stream_id); - return li; - }, - first_key: stream_list_sort.first_stream_id, - prev_key: stream_list_sort.prev_stream_id, - next_key: stream_list_sort.next_stream_id, - }, - highlight_class: "highlighted_stream", - }); - const $search_input = $(".stream-list-filter").expectOne(); keydown_util.handle({ diff --git a/web/tests/stream_list.test.js b/web/tests/stream_list.test.js index 94718fbf9d..b4d38215a6 100644 --- a/web/tests/stream_list.test.js +++ b/web/tests/stream_list.test.js @@ -21,9 +21,6 @@ mock_esm("../src/narrow_state", { active: () => false, }); const topic_list = mock_esm("../src/topic_list"); -mock_esm("../src/keydown_util", { - handle: noop, -}); const scroll_util = mock_esm("../src/scroll_util", { scroll_element_into_container() {}, get_scroll_element: ($element) => $element, @@ -378,7 +375,7 @@ test_ui("zoom_in_and_zoom_out", ({mock_template}) => { $("#stream-filters-container")[0] = { dataset: {}, }; - stream_list.set_event_handlers(); + stream_list.initialize_stream_cursor(); mock_template("filter_topics", false, () => "filter-topics-stub"); let filter_topics_appended = false; @@ -430,8 +427,6 @@ test_ui("narrowing", ({mock_template}) => { assert.ok(!$("").hasClass("active-filter")); - stream_list.set_event_handlers(); - let filter; filter = new Filter([{operator: "stream", operand: "devel"}]);