2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2022-04-09 23:44:38 +02:00
|
|
|
const {mock_esm, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2018-06-22 12:19:40 +02:00
|
|
|
const noop = () => {};
|
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const narrow = mock_esm("../../static/js/narrow");
|
|
|
|
const narrow_state = mock_esm("../../static/js/narrow_state", {
|
2021-03-07 13:57:14 +01:00
|
|
|
filter: () => false,
|
|
|
|
});
|
2021-03-10 06:10:32 +01:00
|
|
|
const search_suggestion = mock_esm("../../static/js/search_suggestion");
|
2021-03-07 13:57:14 +01:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/search_pill_widget", {
|
2020-06-18 17:17:11 +02:00
|
|
|
widget: {
|
2022-07-11 04:27:00 +02:00
|
|
|
getByElement: () => true,
|
2020-06-18 17:17:11 +02:00
|
|
|
},
|
|
|
|
});
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/ui_util", {
|
2021-03-06 17:37:51 +01:00
|
|
|
change_tab_to: noop,
|
|
|
|
place_caret_at_end: noop,
|
|
|
|
});
|
2021-03-07 13:57:14 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const search = zrequire("search");
|
|
|
|
const search_pill = zrequire("search_pill");
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
const {Filter} = zrequire("../js/filter");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
function test(label, f) {
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test(label, ({override}) => {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.search_pills_enabled = true;
|
2021-06-16 14:38:37 +02:00
|
|
|
f({override});
|
2021-04-03 19:07:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("clear_search_form", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#search_query").val("noise");
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#search_query").trigger("focus");
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".search_button").prop("disabled", false);
|
Simplify narrow/search interactions.
Before this change, if you hit ESC, then hotkey
code would call search.clear_search, which would
call narrow.deactivate(), which would then use
`$('#search_query')` to clear a value, but then
let search.clear_search blur the input and
disable the exit button. It was all confusing.
Things are a bit more organized now.
Now the code works like this:
hotkey.process_escape_key
Just call narrow.deactivate.
$('#search_exit').on('click', ...):
Just call narrow.deactivate.
narrow.deactivate:
Just call search.clear_search_form
search.clear_search_form:
Just do simple jquery stuff. Don't
change the entire user's narrow, not
even indirectly!
There's still a two-way interaction between
the narrow.js module and the search.js module,
but in each direction it's a one-liner.
The guiding principle here is that we only
want one top-level API, which is narrow.deactivate,
and that does the whole "kitchen sink" of
clearing searches, closing popovers, switching
in views, etc. And then all the functions it
calls out to tend to have much smaller jobs to
do.
This commit can mostly be considered a refactoring, but the
order of operations changes slightly. Basically, as
soon as you hit ESC or click on the search "X", we
clear the search widget. Most users won't notice
any difference, because we don't have to hit the
server to populate the home view. And it's arguably
an improvement to give more immediate feedback.
2018-09-10 19:36:58 +02:00
|
|
|
|
|
|
|
search.clear_search_form();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#search_query").is_focused(), false);
|
|
|
|
assert.equal($("#search_query").val(), "");
|
|
|
|
assert.equal($(".search_button").prop("disabled"), true);
|
Simplify narrow/search interactions.
Before this change, if you hit ESC, then hotkey
code would call search.clear_search, which would
call narrow.deactivate(), which would then use
`$('#search_query')` to clear a value, but then
let search.clear_search blur the input and
disable the exit button. It was all confusing.
Things are a bit more organized now.
Now the code works like this:
hotkey.process_escape_key
Just call narrow.deactivate.
$('#search_exit').on('click', ...):
Just call narrow.deactivate.
narrow.deactivate:
Just call search.clear_search_form
search.clear_search_form:
Just do simple jquery stuff. Don't
change the entire user's narrow, not
even indirectly!
There's still a two-way interaction between
the narrow.js module and the search.js module,
but in each direction it's a one-liner.
The guiding principle here is that we only
want one top-level API, which is narrow.deactivate,
and that does the whole "kitchen sink" of
clearing searches, closing popovers, switching
in views, etc. And then all the functions it
calls out to tend to have much smaller jobs to
do.
This commit can mostly be considered a refactoring, but the
order of operations changes slightly. Basically, as
soon as you hit ESC or click on the search "X", we
clear the search widget. Most users won't notice
any difference, because we don't have to hit the
server to populate the home view. And it's arguably
an improvement to give more immediate feedback.
2018-09-10 19:36:58 +02:00
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("update_button_visibility", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_query = $("#search_query");
|
|
|
|
const $search_button = $(".search_button");
|
2018-06-22 12:19:40 +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"));
|
2020-05-31 16:47:55 +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-06-22 12:19:40 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-06-22 12:19:40 +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-06-22 12:19:40 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-06-22 12:19:40 +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-06-22 12:19:40 +02:00
|
|
|
search.update_button_visibility();
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$search_button.prop("disabled"));
|
2018-06-22 12:19:40 +02:00
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("initialize", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_query_box = $("#search_query");
|
|
|
|
const $searchbox_form = $("#searchbox_form");
|
|
|
|
const $search_button = $(".search_button");
|
|
|
|
const $searchbox = $("#searchbox");
|
2018-06-22 12:19:40 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box[0] = "stub";
|
2021-02-22 17:01:29 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
search_pill.get_search_string_for_current_filter = () => "is:starred";
|
2018-07-02 22:30:18 +02:00
|
|
|
|
2019-12-25 16:58:11 +01:00
|
|
|
search_suggestion.max_num_of_search_results = 99;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.typeahead = (opts) => {
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(opts.fixed, true);
|
2019-12-25 16:58:11 +01:00
|
|
|
assert.equal(opts.items, 99);
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(opts.naturalSearch, true);
|
2018-12-04 22:55:55 +01:00
|
|
|
assert.equal(opts.helpOnEmptyStrings, true);
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(opts.matcher(), true);
|
2020-09-24 07:50:36 +02:00
|
|
|
opts.on_move();
|
2018-06-22 12:19:40 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
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",
|
|
|
|
{
|
|
|
|
description: "Stream <strong>Ver</strong>ona",
|
|
|
|
search_string: "stream:Verona",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"ver",
|
|
|
|
{
|
|
|
|
description: "Search for ver",
|
|
|
|
search_string: "ver",
|
|
|
|
},
|
|
|
|
],
|
2020-02-12 06:58:20 +01:00
|
|
|
]),
|
2020-07-15 01:29:15 +02:00
|
|
|
strings: ["ver", "stream:Verona"],
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Test source */
|
|
|
|
search_suggestion.get_suggestions = () => search_suggestions;
|
|
|
|
const expected_source_value = search_suggestions.strings;
|
2020-07-15 01:29:15 +02:00
|
|
|
const source = opts.source("ver");
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(source, expected_source_value);
|
|
|
|
|
|
|
|
/* Test highlighter */
|
2020-07-15 01:29:15 +02:00
|
|
|
let expected_value = "Search for ver";
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(opts.highlighter(source[0]), expected_value);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
expected_value = "Stream <strong>Ver</strong>ona";
|
2018-06-22 12:19:40 +02:00
|
|
|
assert.equal(opts.highlighter(source[1]), expected_value);
|
|
|
|
|
|
|
|
/* Test sorter */
|
|
|
|
assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let operators;
|
|
|
|
let is_blurred;
|
2018-07-14 16:10:00 +02:00
|
|
|
let is_append_search_string_called;
|
2022-04-09 23:44:38 +02:00
|
|
|
$search_query_box.on(
|
|
|
|
"blur",
|
|
|
|
/* istanbul ignore next */
|
|
|
|
() => {
|
|
|
|
is_blurred = true;
|
|
|
|
},
|
|
|
|
);
|
2018-07-14 16:10:00 +02:00
|
|
|
search_pill.append_search_string = () => {
|
|
|
|
is_append_search_string_called = true;
|
|
|
|
};
|
2018-06-22 12:19:40 +02:00
|
|
|
/* Test updater */
|
|
|
|
const _setup = (search_box_val) => {
|
|
|
|
is_blurred = false;
|
2018-07-14 16:10:00 +02:00
|
|
|
is_append_search_string_called = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.val(search_box_val);
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2020-05-31 16:47:55 +02:00
|
|
|
Filter.parse = (search_string) => {
|
|
|
|
assert.equal(search_string, search_box_val);
|
|
|
|
return operators;
|
|
|
|
};
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2018-06-22 12:19:40 +02:00
|
|
|
narrow.activate = (raw_operators, options) => {
|
|
|
|
assert.deepEqual(raw_operators, operators);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(options, {trigger: "search"});
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2020-07-02 01:41:40 +02:00
|
|
|
search_pill.get_search_string_for_current_filter = () => search_box_val;
|
2018-06-22 12:19:40 +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");
|
2020-05-31 16:47:55 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.updater("ver"), "ver");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
|
|
|
assert.ok(is_append_search_string_called);
|
2018-06-22 12:19:40 +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");
|
2020-05-31 16:47:55 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
|
|
|
assert.ok(is_append_search_string_called);
|
2018-06-22 12:19:40 +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");
|
2020-05-31 16:47:55 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!is_blurred);
|
|
|
|
assert.ok(is_append_search_string_called);
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$search_query_box.off("blur");
|
2018-06-22 12:19:40 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
search.initialize();
|
2018-06-22 12:19:40 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_pill_stub = $.create(".pill");
|
|
|
|
$search_pill_stub.closest = () => ({data: noop});
|
2020-07-21 00:23:06 +02:00
|
|
|
const stub_event = {
|
2022-01-25 11:36:19 +01:00
|
|
|
// FIXME: event.relatedTarget should not be a jQuery object
|
|
|
|
relatedTarget: $search_pill_stub,
|
2020-07-21 00:23:06 +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(new $.Event("blur", stub_event));
|
|
|
|
assert.equal($search_query_box.val(), "test string");
|
2020-07-21 00:23:06 +02:00
|
|
|
|
2021-06-04 19:27:45 +02:00
|
|
|
let css_args;
|
2022-01-25 11:36:19 +01:00
|
|
|
$searchbox.css = (args) => {
|
2021-06-04 19:27:45 +02:00
|
|
|
css_args = args;
|
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
$searchbox.trigger("focusout");
|
2021-06-04 19:27:45 +02:00
|
|
|
assert.deepEqual(css_args, {"box-shadow": "unset"});
|
2020-07-21 00:23:06 +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",
|
2021-05-31 18:38:57 +02:00
|
|
|
key: "a",
|
2020-09-24 07:50:36 +02:00
|
|
|
preventDefault() {
|
|
|
|
default_prevented = true;
|
|
|
|
},
|
2020-07-21 00:23:06 +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-06-22 12:19:40 +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-06-22 12:19:40 +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-06-22 12:19:40 +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;
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
2020-07-21 00:23:06 +02:00
|
|
|
narrow.activate = (raw_operators, options) => {
|
|
|
|
assert.deepEqual(raw_operators, operators);
|
|
|
|
assert.deepEqual(options, {trigger: "search"});
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
2020-07-21 00:23:06 +02:00
|
|
|
search_pill.get_search_string_for_current_filter = () => search_box_val;
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
operators = [
|
|
|
|
{
|
|
|
|
negated: false,
|
|
|
|
operator: "search",
|
|
|
|
operand: "",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
_setup("");
|
|
|
|
|
|
|
|
ev = {
|
|
|
|
type: "keyup",
|
|
|
|
which: 15,
|
2018-06-22 12:19:40 +02:00
|
|
|
};
|
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);
|
2018-06-22 12:19:40 +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-14 21:26:28 +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"));
|
2020-07-21 00:23:06 +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-06-22 12:19:40 +02:00
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("initiate_search", () => {
|
2020-05-31 15:53:39 +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.
|
|
|
|
let typeahead_forced_open = false;
|
|
|
|
let is_searchbox_text_selected = false;
|
2018-07-23 17:14:53 +02:00
|
|
|
let is_searchbox_focused = false;
|
2020-07-21 00:23:06 +02:00
|
|
|
$("#search_query").off("focus");
|
|
|
|
$("#search_query").on("focus", () => {
|
2018-07-23 17:14:53 +02:00
|
|
|
is_searchbox_focused = true;
|
2020-07-21 00:23:06 +02:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#search_query").typeahead = (lookup) => {
|
2020-05-31 15:53:39 +02:00
|
|
|
if (lookup === "lookup") {
|
|
|
|
typeahead_forced_open = true;
|
|
|
|
}
|
2020-07-22 04:50:11 +02:00
|
|
|
return $("#search_query");
|
2020-05-31 15:53:39 +02:00
|
|
|
};
|
2020-07-22 04:50:11 +02:00
|
|
|
$("#search_query").on("select", () => {
|
|
|
|
is_searchbox_text_selected = true;
|
|
|
|
});
|
2020-05-31 15:53:39 +02:00
|
|
|
|
2021-02-23 12:15:40 +01:00
|
|
|
$("#search_query")[0] = "stub";
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $searchbox = $("#searchbox");
|
2021-06-04 19:27:45 +02:00
|
|
|
let css_args;
|
2022-01-25 11:36:19 +01:00
|
|
|
$searchbox.css = (args) => {
|
2021-06-04 19:27:45 +02:00
|
|
|
css_args = args;
|
|
|
|
};
|
|
|
|
|
2018-06-22 12:19:40 +02:00
|
|
|
search.initiate_search();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(typeahead_forced_open);
|
|
|
|
assert.ok(is_searchbox_text_selected);
|
|
|
|
assert.ok(is_searchbox_focused);
|
2021-06-04 19:27:45 +02:00
|
|
|
assert.deepEqual(css_args, {"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
|
2018-06-22 12:19:40 +02:00
|
|
|
});
|