code cleanup: Remove obsolete stream_sort code.

I remove an obsolete comment--we use get_streams()
for the `n` key now.

I also remove a guard statement from sort_groups()
that returned `undefined` for empty lists.

That guard statement would break this code:

    const stream_groups = stream_sort.sort_groups(streams, get_search_term());

    if (stream_groups.same_as_before && ...

The calling code prevents the situation anyway:

    const streams = stream_data.subscribed_stream_ids();
    if (streams.length === 0) {
        return;
    }

I modify the "no_subscribed_streams" test to test
the new behavior.  (Even though stream_list currently
short-circuits the call here, that may change in the future.)

I also introduce the test() wrapper to explicitly clear
our data.
This commit is contained in:
Steve Howell
2021-03-13 13:51:32 +00:00
committed by Steve Howell
parent 9c4d7b3bd4
commit bc8647539c
2 changed files with 25 additions and 18 deletions

View File

@@ -8,11 +8,6 @@ const {run_test} = require("../zjsunit/test");
const stream_data = zrequire("stream_data");
const stream_sort = zrequire("stream_sort");
run_test("no_subscribed_streams", () => {
assert.equal(stream_sort.sort_groups([]), undefined);
assert.equal(stream_sort.first_stream_id(), undefined);
});
const scalene = {
subscribed: true,
name: "scalene",
@@ -44,18 +39,36 @@ const weaving = {
pin_to_top: false,
};
stream_data.add_sub(scalene);
stream_data.add_sub(fast_tortoise);
stream_data.add_sub(pneumonia);
stream_data.add_sub(clarinet);
stream_data.add_sub(weaving);
function sort_groups(query) {
const streams = stream_data.subscribed_stream_ids();
return stream_sort.sort_groups(streams, query);
}
run_test("basics", (override) => {
function test(label, f) {
run_test(label, (override) => {
stream_data.clear_subscriptions();
f(override);
});
}
test("no_subscribed_streams", () => {
const sorted = sort_groups("");
assert.deepEqual(sorted, {
dormant_streams: [],
normal_streams: [],
pinned_streams: [],
same_as_before: sorted.same_as_before,
});
assert.equal(stream_sort.first_stream_id(), undefined);
});
test("basics", (override) => {
stream_data.add_sub(scalene);
stream_data.add_sub(fast_tortoise);
stream_data.add_sub(pneumonia);
stream_data.add_sub(clarinet);
stream_data.add_sub(weaving);
override(stream_data, "is_active", (sub) => sub.name !== "pneumonia");
// Test sorting into categories/alphabetized

View File

@@ -7,8 +7,6 @@ let previous_dormant;
let all_streams = [];
export function get_streams() {
// Right now this is only used for testing, but we should
// use it for things like hotkeys that cycle through streams.
const sorted_streams = all_streams.map((stream_id) =>
stream_data.maybe_get_stream_name(stream_id),
);
@@ -46,10 +44,6 @@ function filter_streams_by_search(streams, search_term) {
}
export function sort_groups(streams, search_term) {
if (streams.length === 0) {
return undefined;
}
streams = filter_streams_by_search(streams, search_term);
function is_normal(sub) {