From aeb4419d527d194a5f59d7f5346c60fc5122aec8 Mon Sep 17 00:00:00 2001 From: Ryan Rehman Date: Sun, 31 May 2020 19:23:39 +0530 Subject: [PATCH] search: Open typeahead on initiating search. This fixes a bug where the hotkeys used to search messages doesn't work for pills enabled case. --- frontend_tests/node_tests/search.js | 22 +++++++++++++++++++++- static/js/search.js | 7 +++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index f9f0d3d8c4..cdba07c67d 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -282,10 +282,30 @@ run_test('initizalize', () => { }); run_test('initiate_search', () => { + // 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; let is_searchbox_focused = false; - $('#search_arrows').focus = () => { + $('#search_query').focus = () => { is_searchbox_focused = true; }; + $('#search_query').select = noop; + $('#search_query').typeahead = (lookup) => { + if (lookup === "lookup") { + typeahead_forced_open = true; + return { + select: () => { + is_searchbox_text_selected = true; + }, + }; + } + }; + search.initiate_search(); + assert(typeahead_forced_open); + assert(is_searchbox_text_selected); assert(is_searchbox_focused); }); diff --git a/static/js/search.js b/static/js/search.js index e9dcd1759b..721c1235e0 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -193,11 +193,10 @@ exports.focus_search = function () { }; exports.initiate_search = function () { + tab_bar.open_search_bar_and_close_narrow_description(); + $('#search_query').typeahead('lookup').select(); if (page_params.search_pills_enabled) { - $('#search_arrows').focus(); - } else { - tab_bar.open_search_bar_and_close_narrow_description(); - $('#search_query').typeahead('lookup').select(); + $('#search_query').focus(); } };