2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.search_pills_enabled = false;
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const narrow = mock_esm("../src/narrow");
|
|
|
|
const narrow_state = mock_esm("../src/narrow_state");
|
|
|
|
const search_suggestion = mock_esm("../src/search_suggestion");
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2021-02-28 00:45:40 +01:00
|
|
|
const Filter = {};
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/filter", {
|
2021-02-28 00:45:40 +01:00
|
|
|
Filter,
|
|
|
|
});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
set_global("setTimeout", (func) => func());
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const search = zrequire("search");
|
|
|
|
|
2022-03-17 15:36:55 +01:00
|
|
|
run_test("clear_search_form", () => {
|
|
|
|
$("#search_query").val("noise");
|
|
|
|
$("#search_query").trigger("focus");
|
2023-03-07 01:21:31 +01:00
|
|
|
$(".search_close_button").prop("disabled", false);
|
2022-03-17 15:36:55 +01:00
|
|
|
|
|
|
|
search.clear_search_form();
|
|
|
|
|
|
|
|
assert.equal($("#search_query").is_focused(), false);
|
|
|
|
assert.equal($("#search_query").val(), "");
|
2023-03-07 01:21:31 +01:00
|
|
|
assert.equal($(".search_close_button").prop("disabled"), true);
|
2022-03-17 15:36:55 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("update_button_visibility", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_query = $("#search_query");
|
2023-03-07 01:21:31 +01:00
|
|
|
const $search_button = $(".search_close_button");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query.is = () => false;
|
|
|
|
$search_query.val("");
|
2021-02-26 12:49:16 +01:00
|
|
|
narrow_state.active = () => false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", true);
|
2020-05-31 16:47:55 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query.is = () => true;
|
|
|
|
$search_query.val("");
|
2022-04-09 23:44:38 +02:00
|
|
|
delete narrow_state.active;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", true);
|
2018-07-14 12:46:02 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query.is = () => false;
|
|
|
|
$search_query.val("Test search term");
|
2022-04-09 23:44:38 +02:00
|
|
|
delete narrow_state.active;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", true);
|
2018-07-14 12:46:02 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query.is = () => false;
|
|
|
|
$search_query.val("");
|
2021-02-26 12:49:16 +01:00
|
|
|
narrow_state.active = () => true;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", true);
|
2018-07-14 12:46:02 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|
|
|
|
|
2021-12-06 23:44:26 +01:00
|
|
|
run_test("initialize", ({mock_template}) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_query_box = $("#search_query");
|
|
|
|
const $searchbox_form = $("#searchbox_form");
|
2023-03-07 01:21:31 +01:00
|
|
|
const $search_button = $(".search_close_button");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2021-12-06 23:44:26 +01:00
|
|
|
mock_template("search_list_item.hbs", true, (data, html) => {
|
|
|
|
assert.equal(typeof data.description_html, "string");
|
|
|
|
if (data.is_person) {
|
|
|
|
assert.equal(typeof data.user_pill_context.id, "number");
|
|
|
|
assert.equal(typeof data.user_pill_context.display_value, "string");
|
|
|
|
assert.equal(typeof data.user_pill_context.has_image, "boolean");
|
|
|
|
assert.equal(typeof data.user_pill_context.img_src, "string");
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
|
2019-12-25 16:58:11 +01:00
|
|
|
search_suggestion.max_num_of_search_results = 999;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.typeahead = (opts) => {
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.equal(opts.fixed, true);
|
2019-12-25 16:58:11 +01:00
|
|
|
assert.equal(opts.items, 999);
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.equal(opts.naturalSearch, true);
|
|
|
|
assert.equal(opts.helpOnEmptyStrings, true);
|
|
|
|
assert.equal(opts.matcher(), true);
|
|
|
|
|
|
|
|
{
|
|
|
|
const search_suggestions = {
|
2020-02-12 06:58:20 +01:00
|
|
|
lookup_table: new Map([
|
2020-07-15 00:34:28 +02:00
|
|
|
[
|
|
|
|
"stream:Verona",
|
|
|
|
{
|
2022-08-18 14:54:00 +02:00
|
|
|
description_html: "Stream <strong>Ver</strong>ona",
|
2020-07-15 00:34:28 +02:00
|
|
|
search_string: "stream:Verona",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"ver",
|
|
|
|
{
|
2022-06-19 07:17:16 +02:00
|
|
|
description_html: "Search for ver",
|
2020-07-15 00:34:28 +02:00
|
|
|
search_string: "ver",
|
|
|
|
},
|
|
|
|
],
|
2020-02-12 06:58:20 +01:00
|
|
|
]),
|
2020-07-15 01:29:15 +02:00
|
|
|
strings: ["ver", "stream:Verona"],
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Test source */
|
2020-06-01 15:00:42 +02:00
|
|
|
search_suggestion.get_suggestions = () => search_suggestions;
|
2018-07-14 12:46:02 +02:00
|
|
|
const expected_source_value = search_suggestions.strings;
|
2020-07-15 01:29:15 +02:00
|
|
|
const source = opts.source("ver");
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.equal(source, expected_source_value);
|
|
|
|
|
|
|
|
/* Test highlighter */
|
2022-08-18 14:54:00 +02:00
|
|
|
let expected_value = `<div class="search_list_item">\n <span>Search for ver</span>\n</div>\n`;
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(opts.highlighter(source[0]), expected_value);
|
|
|
|
|
2022-08-18 14:54:00 +02:00
|
|
|
expected_value = `<div class="search_list_item">\n <span>Stream <strong>Ver</strong>ona</span>\n</div>\n`;
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(opts.highlighter(source[1]), expected_value);
|
|
|
|
|
|
|
|
/* Test sorter */
|
|
|
|
assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const search_suggestions = {
|
|
|
|
lookup_table: new Map([
|
|
|
|
[
|
|
|
|
"group-pm-with:zo",
|
|
|
|
{
|
2023-01-24 19:49:56 +01:00
|
|
|
description_html: "group direct messages including",
|
2021-12-06 23:44:26 +01:00
|
|
|
is_person: true,
|
|
|
|
search_string: "group-pm-with:user7@zulipdev.com",
|
|
|
|
user_pill_context: {
|
|
|
|
display_value: "<strong>Zo</strong>e",
|
|
|
|
has_image: true,
|
|
|
|
id: 7,
|
|
|
|
img_src:
|
|
|
|
"https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"pm-with:zo",
|
|
|
|
{
|
2023-01-24 19:49:56 +01:00
|
|
|
description_html: "direct messages with",
|
2021-12-06 23:44:26 +01:00
|
|
|
is_person: true,
|
|
|
|
search_string: "pm-with:user7@zulipdev.com",
|
|
|
|
user_pill_context: {
|
|
|
|
display_value: "<strong>Zo</strong>e",
|
|
|
|
has_image: true,
|
|
|
|
id: 7,
|
|
|
|
img_src:
|
|
|
|
"https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"sender:zo",
|
|
|
|
{
|
|
|
|
description_html: "sent by",
|
|
|
|
is_person: true,
|
|
|
|
search_string: "sender:user7@zulipdev.com",
|
|
|
|
user_pill_context: {
|
|
|
|
display_value: "<strong>Zo</strong>e",
|
|
|
|
has_image: true,
|
|
|
|
id: 7,
|
|
|
|
img_src:
|
|
|
|
"https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"zo",
|
|
|
|
{
|
|
|
|
description_html: "Search for zo",
|
|
|
|
search_string: "zo",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]),
|
|
|
|
strings: ["zo", "sender:zo", "pm-with:zo", "group-pm-with:zo"],
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Test source */
|
|
|
|
search_suggestion.get_suggestions = () => search_suggestions;
|
|
|
|
const expected_source_value = search_suggestions.strings;
|
|
|
|
const source = opts.source("zo");
|
|
|
|
assert.equal(source, expected_source_value);
|
|
|
|
|
|
|
|
/* Test highlighter */
|
2022-08-18 14:54:00 +02:00
|
|
|
let expected_value = `<div class="search_list_item">\n <span>Search for zo</span>\n</div>\n`;
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.equal(opts.highlighter(source[0]), expected_value);
|
|
|
|
|
2022-08-18 14:54:00 +02:00
|
|
|
expected_value = `<div class="search_list_item">\n <span>sent by</span>\n <span class="pill-container pill-container-btn">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50" />\n <span class="pill-value"><strong>Zo</strong>e</span>\n <div class="exit">\n <span aria-hidden="true">×</span>\n </div>\n</div>\n </span>\n</div>\n`;
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.equal(opts.highlighter(source[1]), expected_value);
|
|
|
|
|
2023-01-24 19:49:56 +01:00
|
|
|
expected_value = `<div class="search_list_item">\n <span>direct messages with</span>\n <span class="pill-container pill-container-btn">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50" />\n <span class="pill-value"><strong>Zo</strong>e</span>\n <div class="exit">\n <span aria-hidden="true">×</span>\n </div>\n</div>\n </span>\n</div>\n`;
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(opts.highlighter(source[2]), expected_value);
|
|
|
|
|
2023-01-24 19:49:56 +01:00
|
|
|
expected_value = `<div class="search_list_item">\n <span>group direct messages including</span>\n <span class="pill-container pill-container-btn">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1&s=50" />\n <span class="pill-value"><strong>Zo</strong>e</span>\n <div class="exit">\n <span aria-hidden="true">×</span>\n </div>\n</div>\n </span>\n</div>\n`;
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(opts.highlighter(source[3]), expected_value);
|
|
|
|
|
2018-07-14 12:46:02 +02:00
|
|
|
/* Test sorter */
|
|
|
|
assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let operators;
|
|
|
|
let is_blurred;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.on("blur", () => {
|
2018-07-14 12:46:02 +02:00
|
|
|
is_blurred = true;
|
2020-07-21 00:23:06 +02:00
|
|
|
});
|
2018-07-14 12:46:02 +02:00
|
|
|
/* Test updater */
|
|
|
|
const _setup = (search_box_val) => {
|
|
|
|
is_blurred = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.val(search_box_val);
|
2018-07-14 12:46:02 +02:00
|
|
|
Filter.parse = (search_string) => {
|
|
|
|
assert.equal(search_string, search_box_val);
|
|
|
|
return operators;
|
|
|
|
};
|
|
|
|
narrow.activate = (raw_operators, options) => {
|
|
|
|
assert.deepEqual(raw_operators, operators);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(options, {trigger: "search"});
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
operators = [
|
|
|
|
{
|
|
|
|
negated: false,
|
|
|
|
operator: "search",
|
|
|
|
operand: "ver",
|
|
|
|
},
|
|
|
|
];
|
2020-07-15 01:29:15 +02:00
|
|
|
_setup("ver");
|
|
|
|
assert.equal(opts.updater("ver"), "ver");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(is_blurred);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
operators = [
|
|
|
|
{
|
|
|
|
negated: false,
|
|
|
|
operator: "stream",
|
|
|
|
operand: "Verona",
|
|
|
|
},
|
|
|
|
];
|
2020-07-15 01:29:15 +02:00
|
|
|
_setup("stream:Verona");
|
|
|
|
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(is_blurred);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2021-02-28 01:04:58 +01:00
|
|
|
search.__Rewire__("is_using_input_method", true);
|
2020-07-15 01:29:15 +02:00
|
|
|
_setup("stream:Verona");
|
|
|
|
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.off("blur");
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
search.initialize();
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", true);
|
|
|
|
$search_query_box.trigger("focus");
|
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.val("test string");
|
2020-07-21 00:23:06 +02:00
|
|
|
narrow_state.search_string = () => "ver";
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.trigger("blur");
|
|
|
|
assert.equal($search_query_box.val(), "test string");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2021-02-28 01:04:58 +01:00
|
|
|
search.__Rewire__("is_using_input_method", false);
|
2022-01-25 11:36:19 +01:00
|
|
|
$searchbox_form.trigger("compositionend");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(search.is_using_input_method);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const keydown = $searchbox_form.get_on_handler("keydown");
|
2020-09-24 07:50:36 +02:00
|
|
|
let default_prevented = false;
|
2020-07-21 00:23:06 +02:00
|
|
|
let ev = {
|
|
|
|
type: "keydown",
|
|
|
|
which: 15,
|
2020-09-24 07:50:36 +02:00
|
|
|
preventDefault() {
|
|
|
|
default_prevented = true;
|
|
|
|
},
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => false;
|
2020-07-21 00:23:06 +02:00
|
|
|
assert.equal(keydown(ev), undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!default_prevented);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "Enter";
|
2020-07-21 00:23:06 +02:00
|
|
|
assert.equal(keydown(ev), undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!default_prevented);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "Enter";
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => true;
|
2020-09-24 07:50:36 +02:00
|
|
|
assert.equal(keydown(ev), undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(default_prevented);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
ev = {
|
|
|
|
type: "keyup",
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
2020-07-21 00:23:06 +02:00
|
|
|
let operators;
|
|
|
|
let is_blurred;
|
2021-02-26 12:49:16 +01:00
|
|
|
narrow_state.active = () => false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.off("blur");
|
|
|
|
$search_query_box.on("blur", () => {
|
2020-07-21 00:23:06 +02:00
|
|
|
is_blurred = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
const _setup = (search_box_val) => {
|
|
|
|
is_blurred = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_button.prop("disabled", false);
|
|
|
|
$search_query_box.val(search_box_val);
|
2020-07-21 00:23:06 +02:00
|
|
|
Filter.parse = (search_string) => {
|
|
|
|
assert.equal(search_string, search_box_val);
|
|
|
|
return operators;
|
|
|
|
};
|
|
|
|
narrow.activate = (raw_operators, options) => {
|
|
|
|
assert.deepEqual(raw_operators, operators);
|
|
|
|
assert.deepEqual(options, {trigger: "search"});
|
|
|
|
};
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
operators = [
|
|
|
|
{
|
|
|
|
negated: false,
|
|
|
|
operator: "search",
|
|
|
|
operand: "",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
_setup("");
|
|
|
|
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "a";
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => false;
|
|
|
|
$searchbox_form.trigger(ev);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "Enter";
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => false;
|
|
|
|
$searchbox_form.trigger(ev);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "Enter";
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => true;
|
|
|
|
$searchbox_form.trigger(ev);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(is_blurred);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
|
|
|
_setup("ver");
|
2021-02-28 01:04:58 +01:00
|
|
|
search.__Rewire__("is_using_input_method", true);
|
2022-01-25 11:36:19 +01:00
|
|
|
$searchbox_form.trigger(ev);
|
2020-08-11 02:09:14 +02:00
|
|
|
// No change on Enter keyup event when using input tool
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2020-07-21 00:23:06 +02:00
|
|
|
|
|
|
|
_setup("ver");
|
2021-05-31 18:38:57 +02:00
|
|
|
ev.key = "Enter";
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.is = () => true;
|
|
|
|
$searchbox_form.trigger(ev);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(is_blurred);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("initiate_search", () => {
|
2020-04-12 15:21:11 +02:00
|
|
|
// open typeahead and select text when navbar is open
|
|
|
|
// this implicitly expects the code to used the chained
|
|
|
|
// function calls, which is something to keep in mind if
|
|
|
|
// this test ever fails unexpectedly.
|
2021-02-26 12:49:16 +01:00
|
|
|
narrow_state.filter = () => ({is_search: () => true});
|
2020-04-12 15:21:11 +02:00
|
|
|
let typeahead_forced_open = false;
|
|
|
|
let is_searchbox_text_selected = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#search_query").typeahead = (lookup) => {
|
2020-04-12 15:21:11 +02:00
|
|
|
if (lookup === "lookup") {
|
|
|
|
typeahead_forced_open = true;
|
|
|
|
}
|
2020-07-22 04:50:11 +02:00
|
|
|
return $("#search_query");
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
2020-07-22 04:50:11 +02:00
|
|
|
$("#search_query").on("select", () => {
|
|
|
|
is_searchbox_text_selected = true;
|
|
|
|
});
|
|
|
|
|
2021-06-04 19:27:45 +02:00
|
|
|
let searchbox_css_args;
|
|
|
|
|
|
|
|
$("#searchbox").css = (args) => {
|
|
|
|
searchbox_css_args = args;
|
|
|
|
};
|
|
|
|
|
2018-07-14 12:46:02 +02:00
|
|
|
search.initiate_search();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(typeahead_forced_open);
|
|
|
|
assert.ok(is_searchbox_text_selected);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#search_query").val(), "ver");
|
2020-06-11 00:22:22 +02:00
|
|
|
|
2021-06-04 19:27:45 +02:00
|
|
|
assert.deepEqual(searchbox_css_args, {
|
|
|
|
"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)",
|
|
|
|
});
|
|
|
|
|
2020-06-11 00:22:22 +02:00
|
|
|
// test that we append space for user convenience
|
2021-02-26 12:49:16 +01:00
|
|
|
narrow_state.filter = () => ({is_search: () => false});
|
2020-06-11 00:22:22 +02:00
|
|
|
search.initiate_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#search_query").val(), "ver ");
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|