search: Stop disabling and enabling the search close button.

This is logic from 10 years ago (dbc4798594)
that is no longer relevant. It seems like we used to show the
search bar open all the time and only showed the buttons when
there was focus in the search bar. Now we close the search bar
when it's not being used, and no longer need to update button
visibility or disable the search close button.
This commit is contained in:
evykassirer
2023-06-20 18:42:08 -07:00
committed by Tim Abbott
parent c4d8f501d6
commit 367030ebfe
7 changed files with 3 additions and 114 deletions

View File

@@ -11,9 +11,6 @@ const {user_settings} = require("./lib/zpage_params");
let $window_stub;
set_global("to_$", () => $window_stub);
mock_esm("../src/search", {
update_button_visibility() {},
});
set_global("document", "document-stub");
const history = set_global("history", {});

View File

@@ -28,7 +28,6 @@ const message_feed_top_notices = mock_esm("../src/message_feed_top_notices");
const message_feed_loading = mock_esm("../src/message_feed_loading");
const message_view_header = mock_esm("../src/message_view_header");
const notifications = mock_esm("../src/notifications");
const search = mock_esm("../src/search");
const stream_list = mock_esm("../src/stream_list");
const top_left_corner = mock_esm("../src/top_left_corner");
const typing_events = mock_esm("../src/typing_events");
@@ -88,7 +87,6 @@ function test_helper() {
stub(message_feed_loading, "show_loading_older");
stub(message_feed_top_notices, "hide_top_of_narrow_notices");
stub(notifications, "redraw_title");
stub(search, "update_button_visibility");
stub(stream_list, "handle_narrow_activated");
stub(message_view_header, "render_title_area");
stub(top_left_corner, "handle_narrow_activated");
@@ -193,7 +191,6 @@ run_test("basics", () => {
[hashchange, "save_narrow"],
[compose_closed_ui, "update_buttons_for_stream"],
[compose_closed_ui, "update_reply_recipient_label"],
[search, "update_button_visibility"],
[compose_actions, "on_narrow"],
[top_left_corner, "handle_narrow_activated"],
[stream_list, "handle_narrow_activated"],

View File

@@ -2,7 +2,7 @@
const {strict: assert} = require("assert");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const $ = require("./lib/zjquery");
@@ -16,59 +16,21 @@ mock_esm("../src/filter", {
Filter,
});
set_global("setTimeout", (func) => func());
const search = zrequire("search");
run_test("clear_search_form", () => {
$("#search_query").val("noise");
$("#search_query").trigger("focus");
$(".search_close_button").prop("disabled", false);
search.clear_search_form();
assert.equal($("#search_query").is_focused(), false);
assert.equal($("#search_query").val(), "");
assert.equal($(".search_close_button").prop("disabled"), true);
});
run_test("update_button_visibility", () => {
const $search_query = $("#search_query");
const $search_button = $(".search_close_button");
$search_query.is = () => false;
$search_query.val("");
narrow_state.active = () => false;
$search_button.prop("disabled", true);
search.update_button_visibility();
assert.ok($search_button.prop("disabled"));
$search_query.is = () => true;
$search_query.val("");
delete narrow_state.active;
$search_button.prop("disabled", true);
search.update_button_visibility();
assert.ok(!$search_button.prop("disabled"));
$search_query.is = () => false;
$search_query.val("Test search term");
delete narrow_state.active;
$search_button.prop("disabled", true);
search.update_button_visibility();
assert.ok(!$search_button.prop("disabled"));
$search_query.is = () => false;
$search_query.val("");
narrow_state.active = () => true;
$search_button.prop("disabled", true);
search.update_button_visibility();
assert.ok(!$search_button.prop("disabled"));
});
run_test("initialize", ({mock_template}) => {
const $search_query_box = $("#search_query");
const $searchbox_form = $("#searchbox_form");
const $search_button = $(".search_close_button");
mock_template("search_list_item.hbs", true, (data, html) => {
assert.equal(typeof data.description_html, "string");
@@ -261,10 +223,6 @@ run_test("initialize", ({mock_template}) => {
search.initialize();
$search_button.prop("disabled", true);
$search_query_box.trigger("focus");
assert.ok(!$search_button.prop("disabled"));
$search_query_box.val("test string");
narrow_state.search_string = () => "ver";
$search_query_box.trigger("blur");
@@ -301,7 +259,6 @@ run_test("initialize", ({mock_template}) => {
};
let operators;
let is_blurred;
narrow_state.active = () => false;
$search_query_box.off("blur");
$search_query_box.on("blur", () => {
is_blurred = true;
@@ -309,7 +266,6 @@ run_test("initialize", ({mock_template}) => {
const _setup = (search_box_val) => {
is_blurred = false;
$search_button.prop("disabled", false);
$search_query_box.val(search_box_val);
Filter.parse = (search_string) => {
assert.equal(search_string, search_box_val);
@@ -336,14 +292,12 @@ run_test("initialize", ({mock_template}) => {
$searchbox_form.trigger(ev);
assert.ok(!is_blurred);
assert.ok(!$search_button.prop("disabled"));
ev.key = "Enter";
$search_query_box.is = () => false;
$searchbox_form.trigger(ev);
assert.ok(!is_blurred);
assert.ok(!$search_button.prop("disabled"));
ev.key = "Enter";
$search_query_box.is = () => true;
@@ -355,14 +309,12 @@ run_test("initialize", ({mock_template}) => {
$searchbox_form.trigger(ev);
// No change on Enter keyup event when using input tool
assert.ok(!is_blurred);
assert.ok(!$search_button.prop("disabled"));
_setup("ver");
ev.key = "Enter";
$search_query_box.is = () => true;
$searchbox_form.trigger(ev);
assert.ok(is_blurred);
assert.ok(!$search_button.prop("disabled"));
});
run_test("initiate_search", () => {