FIX: Navigate search results using J/K keys (#24787)

This commit is contained in:
Penar Musaraj 2023-12-08 11:06:59 -05:00 committed by GitHub
parent 6dc5fe0c83
commit 80d5acc0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -819,10 +819,10 @@ export default {
);
} else if (document.querySelector(".topic-list")) {
return document.querySelectorAll(".topic-list .topic-list-item");
} else if ((categoriesTopicsList = this.categoriesTopicsList())) {
return categoriesTopicsList;
} else if (document.querySelector(".search-results")) {
return document.querySelectorAll(".search-results .fps-result");
} else if ((categoriesTopicsList = this.categoriesTopicsList())) {
return categoriesTopicsList;
}
},

View File

@ -4,11 +4,14 @@ describe "Search", type: :system do
let(:search_page) { PageObjects::Pages::Search.new }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is a test post in a test topic") }
fab!(:topic2) { Fabricate(:topic, title: "Another test topic") }
fab!(:post2) { Fabricate(:post, topic: topic2, raw: "This is another test post in a test topic") }
describe "when using full page search on mobile" do
before do
SearchIndexer.enable
SearchIndexer.index(topic, force: true)
SearchIndexer.index(topic2, force: true)
end
after { SearchIndexer.disable }
@ -35,6 +38,26 @@ describe "Search", type: :system do
expect(search_page).to have_no_search_result
expect(search_page.heading_text).to eq("Search")
end
it "navigates search results using J/K keys" do
visit("/search")
search_page.type_in_search("test")
search_page.click_search_button
expect(search_page).to have_search_result
results = all(".fps-result")
page.send_keys("j")
expect(results.first["class"]).to include("selected")
page.send_keys("j")
expect(results.last["class"]).to include("selected")
page.send_keys("k")
expect(results.first["class"]).to include("selected")
end
end
describe "when using full page search on desktop" do