mirror of
https://github.com/zulip/zulip.git
synced 2026-07-06 21:18:58 +08:00
search: Use zrequire instead of mockesm for search_suggestion in tests.
Soon search_suggestion will be used more in unit tests.
This commit is contained in:
parent
20722cea89
commit
a35f166fac
@ -43,7 +43,10 @@ export type Suggestion = {
|
||||
}
|
||||
);
|
||||
|
||||
export const max_num_of_search_results = MAX_ITEMS;
|
||||
export let max_num_of_search_results = MAX_ITEMS;
|
||||
export function rewire_max_num_of_search_results(value: typeof max_num_of_search_results): void {
|
||||
max_num_of_search_results = value;
|
||||
}
|
||||
|
||||
function channel_matches_query(channel_name: string, q: string): boolean {
|
||||
return common.phrase_match(q, channel_name);
|
||||
@ -1153,7 +1156,7 @@ export function get_search_result(
|
||||
return attacher.get_result().slice(0, max_items);
|
||||
}
|
||||
|
||||
export function get_suggestions(
|
||||
export let get_suggestions = function (
|
||||
pill_search_terms: NarrowTerm[],
|
||||
text_search_terms: NarrowTerm[],
|
||||
add_current_filter = false,
|
||||
@ -1163,6 +1166,10 @@ export function get_suggestions(
|
||||
} {
|
||||
const result = get_search_result(pill_search_terms, text_search_terms, add_current_filter);
|
||||
return finalize_search_result(result);
|
||||
};
|
||||
|
||||
export function rewire_get_suggestions(value: typeof get_suggestions): void {
|
||||
get_suggestions = value;
|
||||
}
|
||||
|
||||
export function finalize_search_result(result: Suggestion[]): {
|
||||
|
||||
@ -7,10 +7,10 @@ const {run_test, noop} = require("./lib/test.cjs");
|
||||
const $ = require("./lib/zjquery.cjs");
|
||||
|
||||
const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");
|
||||
const search_suggestion = mock_esm("../src/search_suggestion");
|
||||
|
||||
const search = zrequire("search");
|
||||
const search_pill = zrequire("search_pill");
|
||||
const search_suggestion = zrequire("search_suggestion");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
||||
function stub_pills() {
|
||||
@ -60,7 +60,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
|
||||
return html;
|
||||
});
|
||||
|
||||
search_suggestion.max_num_of_search_results = 999;
|
||||
override_rewire(search_suggestion, "max_num_of_search_results", 999);
|
||||
let terms;
|
||||
|
||||
function mock_pill_removes(widget) {
|
||||
@ -112,7 +112,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
|
||||
};
|
||||
|
||||
/* Test source */
|
||||
search_suggestion.get_suggestions = () => search_suggestions;
|
||||
override_rewire(search_suggestion, "get_suggestions", () => search_suggestions);
|
||||
const expected_source_value = search_suggestions.strings;
|
||||
const source = opts.source("ver");
|
||||
assert.deepStrictEqual(source, expected_source_value);
|
||||
@ -200,7 +200,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
|
||||
};
|
||||
|
||||
/* Test source */
|
||||
search_suggestion.get_suggestions = () => search_suggestions;
|
||||
override_rewire(search_suggestion, "get_suggestions", () => search_suggestions);
|
||||
const expected_source_value = search_suggestions.strings;
|
||||
const source = opts.source("zo");
|
||||
assert.deepStrictEqual(source, expected_source_value);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user