mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
pill_typeahead: Refactor code for set_up_combined.
Since set_up_combined was only being called with is_stream_subscriber_input as true, there is no need to have this variable in opts as we use same sorting function for all the cases.
This commit is contained in:
@@ -63,13 +63,11 @@ export function set_up_pill_typeahead({
|
||||
user_group: boolean;
|
||||
user: boolean;
|
||||
user_group_source?: () => UserGroup[];
|
||||
is_stream_subscriber_input: boolean;
|
||||
} = {
|
||||
user_source: get_users,
|
||||
stream: true,
|
||||
user_group: true,
|
||||
user: true,
|
||||
is_stream_subscriber_input: true,
|
||||
};
|
||||
if (get_user_groups !== undefined) {
|
||||
opts.user_group_source = get_user_groups;
|
||||
|
||||
@@ -264,7 +264,6 @@ export function set_up_combined(
|
||||
user_group_source?: () => UserGroup[];
|
||||
exclude_bots?: boolean;
|
||||
update_func?: () => void;
|
||||
is_stream_subscriber_input?: boolean;
|
||||
},
|
||||
): void {
|
||||
if (!opts.user && !opts.user_group && !opts.stream) {
|
||||
@@ -383,20 +382,10 @@ export function set_up_combined(
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.is_stream_subscriber_input) {
|
||||
return typeahead_helper.sort_stream_setting_options({
|
||||
users,
|
||||
query,
|
||||
groups,
|
||||
});
|
||||
}
|
||||
return typeahead_helper.sort_recipients({
|
||||
return typeahead_helper.sort_stream_setting_options({
|
||||
users,
|
||||
query,
|
||||
current_stream_id: undefined,
|
||||
current_topic: undefined,
|
||||
groups,
|
||||
max_num_items: undefined,
|
||||
});
|
||||
},
|
||||
updater(item: TypeaheadItem, query: string): undefined {
|
||||
|
||||
@@ -42,10 +42,6 @@ function override_typeahead_helper(override_rewire) {
|
||||
override_rewire(typeahead_helper, "sort_streams", () => {
|
||||
sort_streams_called = true;
|
||||
});
|
||||
override_rewire(typeahead_helper, "sort_recipients", ({users}) => {
|
||||
sort_recipients_called = true;
|
||||
return users;
|
||||
});
|
||||
override_rewire(typeahead_helper, "sort_stream_setting_options", ({users}) => {
|
||||
sort_stream_setting_options_called = true;
|
||||
return users;
|
||||
@@ -530,26 +526,14 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {
|
||||
config.sorter([denmark_item], stream_query);
|
||||
assert.ok(sort_streams_called);
|
||||
}
|
||||
if (opts.user_group && !opts.is_stream_subscriber_input) {
|
||||
sort_recipients_called = false;
|
||||
sort_stream_setting_options_called = false;
|
||||
config.sorter([testers_item], group_query);
|
||||
assert.ok(sort_recipients_called);
|
||||
assert.ok(!sort_stream_setting_options_called);
|
||||
} else if (opts.user_group && opts.is_stream_subscriber_input) {
|
||||
if (opts.user_group) {
|
||||
sort_recipients_called = false;
|
||||
sort_stream_setting_options_called = false;
|
||||
config.sorter([testers_item], group_query);
|
||||
assert.ok(!sort_recipients_called);
|
||||
assert.ok(sort_stream_setting_options_called);
|
||||
}
|
||||
if (opts.user && !opts.is_stream_subscriber_input) {
|
||||
sort_recipients_called = false;
|
||||
sort_stream_setting_options_called = false;
|
||||
config.sorter([me_item], person_query);
|
||||
assert.ok(sort_recipients_called);
|
||||
assert.ok(!sort_stream_setting_options_called);
|
||||
} else if (opts.user && opts.is_stream_subscriber_input) {
|
||||
if (opts.user) {
|
||||
sort_recipients_called = false;
|
||||
sort_stream_setting_options_called = false;
|
||||
config.sorter([me_item], person_query);
|
||||
@@ -666,8 +650,6 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {
|
||||
for (const config of all_possible_opts) {
|
||||
opts = config;
|
||||
test_pill_typeahead(config);
|
||||
opts = {...config, is_stream_subscriber_input: true};
|
||||
test_pill_typeahead({...config, is_stream_subscriber_input: true});
|
||||
}
|
||||
|
||||
// Special case to test coverage and to test
|
||||
|
||||
Reference in New Issue
Block a user