mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Steve Howell
					
				
			
			
				
	
			
			
			
						parent
						
							9c4d7b3bd4
						
					
				
				
					commit
					bc8647539c
				
			@@ -8,11 +8,6 @@ const {run_test} = require("../zjsunit/test");
 | 
				
			|||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
const stream_sort = zrequire("stream_sort");
 | 
					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 = {
 | 
					const scalene = {
 | 
				
			||||||
    subscribed: true,
 | 
					    subscribed: true,
 | 
				
			||||||
    name: "scalene",
 | 
					    name: "scalene",
 | 
				
			||||||
@@ -44,18 +39,36 @@ const weaving = {
 | 
				
			|||||||
    pin_to_top: false,
 | 
					    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) {
 | 
					function sort_groups(query) {
 | 
				
			||||||
    const streams = stream_data.subscribed_stream_ids();
 | 
					    const streams = stream_data.subscribed_stream_ids();
 | 
				
			||||||
    return stream_sort.sort_groups(streams, query);
 | 
					    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");
 | 
					    override(stream_data, "is_active", (sub) => sub.name !== "pneumonia");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test sorting into categories/alphabetized
 | 
					    // Test sorting into categories/alphabetized
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,6 @@ let previous_dormant;
 | 
				
			|||||||
let all_streams = [];
 | 
					let all_streams = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function get_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) =>
 | 
					    const sorted_streams = all_streams.map((stream_id) =>
 | 
				
			||||||
        stream_data.maybe_get_stream_name(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) {
 | 
					export function sort_groups(streams, search_term) {
 | 
				
			||||||
    if (streams.length === 0) {
 | 
					 | 
				
			||||||
        return undefined;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    streams = filter_streams_by_search(streams, search_term);
 | 
					    streams = filter_streams_by_search(streams, search_term);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function is_normal(sub) {
 | 
					    function is_normal(sub) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user