2022-12-13 09:50:44 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
describe "Search", type: :system do
|
2022-12-13 09:50:44 -05:00
|
|
|
let(:search_page) { PageObjects::Pages::Search.new }
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:topic)
|
2022-12-13 09:50:44 -05:00
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is a test post in a test topic") }
|
2023-12-08 11:06:59 -05:00
|
|
|
fab!(:topic2) { Fabricate(:topic, title: "Another test topic") }
|
|
|
|
fab!(:post2) { Fabricate(:post, topic: topic2, raw: "This is another test post in a test topic") }
|
2022-12-13 09:50:44 -05:00
|
|
|
|
2024-06-06 20:41:42 -04:00
|
|
|
let(:topic_bulk_actions_modal) { PageObjects::Modals::TopicBulkActions.new }
|
|
|
|
|
2022-12-13 09:50:44 -05:00
|
|
|
describe "when using full page search on mobile" do
|
|
|
|
before do
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
2023-12-08 11:06:59 -05:00
|
|
|
SearchIndexer.index(topic2, force: true)
|
2022-12-13 09:50:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after { SearchIndexer.disable }
|
|
|
|
|
|
|
|
it "works and clears search page state", mobile: true do
|
|
|
|
visit("/search")
|
|
|
|
|
|
|
|
search_page.type_in_search("test")
|
|
|
|
search_page.click_search_button
|
|
|
|
|
|
|
|
expect(search_page).to have_search_result
|
|
|
|
expect(search_page.heading_text).not_to eq("Search")
|
|
|
|
|
2024-08-08 07:52:48 -04:00
|
|
|
click_logo
|
2023-05-04 19:45:53 -04:00
|
|
|
expect(search_page).to be_not_active
|
2022-12-13 09:50:44 -05:00
|
|
|
|
|
|
|
page.go_back
|
|
|
|
# ensure results are still there when using browser's history
|
|
|
|
expect(search_page).to have_search_result
|
|
|
|
|
2024-08-08 07:52:48 -04:00
|
|
|
click_logo
|
2022-12-13 09:50:44 -05:00
|
|
|
search_page.click_search_icon
|
|
|
|
|
2023-05-04 19:45:53 -04:00
|
|
|
expect(search_page).to have_no_search_result
|
2022-12-13 09:50:44 -05:00
|
|
|
expect(search_page.heading_text).to eq("Search")
|
|
|
|
end
|
2023-12-08 11:06:59 -05:00
|
|
|
|
|
|
|
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
|
2022-12-13 09:50:44 -05:00
|
|
|
end
|
2023-01-27 13:05:27 -05:00
|
|
|
|
|
|
|
describe "when using full page search on desktop" do
|
|
|
|
before do
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
2023-01-27 15:14:29 -05:00
|
|
|
SiteSetting.rate_limit_search_anon_user_per_minute = 4
|
2023-01-27 13:05:27 -05:00
|
|
|
RateLimiter.enable
|
|
|
|
end
|
|
|
|
|
|
|
|
after { SearchIndexer.disable }
|
|
|
|
|
2023-01-31 04:58:50 -05:00
|
|
|
xit "rate limits searches for anonymous users" do
|
2023-01-27 15:14:29 -05:00
|
|
|
queries = %w[one two three four]
|
2023-01-27 13:05:27 -05:00
|
|
|
|
|
|
|
visit("/search?expanded=true")
|
|
|
|
|
|
|
|
queries.each do |query|
|
|
|
|
search_page.clear_search_input
|
|
|
|
search_page.type_in_search(query)
|
|
|
|
search_page.click_search_button
|
|
|
|
end
|
|
|
|
|
2023-01-30 15:47:44 -05:00
|
|
|
# Rate limit error should kick in after 4 queries
|
2023-01-27 13:05:27 -05:00
|
|
|
expect(search_page).to have_warning_message
|
|
|
|
end
|
|
|
|
end
|
2024-03-05 11:10:09 -05:00
|
|
|
|
|
|
|
describe "when search menu on desktop" do
|
|
|
|
before do
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
|
|
|
SearchIndexer.index(topic2, force: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
after { SearchIndexer.disable }
|
|
|
|
|
|
|
|
it "still displays last topic search results after navigating away, then back" do
|
|
|
|
visit("/")
|
|
|
|
search_page.click_search_icon
|
|
|
|
search_page.type_in_search_menu("test")
|
|
|
|
search_page.click_search_menu_link
|
|
|
|
expect(search_page).to have_topic_title_for_first_search_result(topic.title)
|
|
|
|
search_page.click_first_topic
|
|
|
|
search_page.click_search_icon
|
|
|
|
expect(search_page).to have_topic_title_for_first_search_result(topic.title)
|
|
|
|
end
|
2024-04-04 09:52:32 -04:00
|
|
|
|
|
|
|
it "tracks search result clicks" do
|
|
|
|
expect(SearchLog.count).to eq(0)
|
|
|
|
|
|
|
|
visit("/")
|
|
|
|
search_page.click_search_icon
|
|
|
|
search_page.type_in_search_menu("test")
|
|
|
|
search_page.click_search_menu_link
|
|
|
|
|
|
|
|
expect(search_page).to have_topic_title_for_first_search_result(topic.title)
|
|
|
|
find(".search-menu-container .search-result-topic", text: topic.title).click
|
|
|
|
|
|
|
|
try_until_success { expect(SearchLog.count).to eq(1) }
|
|
|
|
try_until_success { expect(SearchLog.last.search_result_id).not_to eq(nil) }
|
|
|
|
|
|
|
|
log = SearchLog.last
|
|
|
|
expect(log.term).to eq("test")
|
|
|
|
expect(log.search_result_id).to eq(topic.first_post.id)
|
|
|
|
expect(log.search_type).to eq(SearchLog.search_types[:header])
|
|
|
|
end
|
2024-03-05 11:10:09 -05:00
|
|
|
end
|
2024-06-06 20:41:42 -04:00
|
|
|
|
|
|
|
describe "bulk actions" do
|
|
|
|
fab!(:admin)
|
|
|
|
fab!(:tag1) { Fabricate(:tag) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
|
|
|
SearchIndexer.index(topic2, force: true)
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
after { SearchIndexer.disable }
|
|
|
|
|
2024-07-22 21:39:27 -04:00
|
|
|
it "allows the user to perform bulk actions on the topic search results" do
|
|
|
|
visit("/search?q=test")
|
|
|
|
expect(page).to have_content(topic.title)
|
|
|
|
find(".search-info .bulk-select").click
|
|
|
|
find(".fps-result .fps-topic[data-topic-id=\"#{topic.id}\"] .bulk-select input").click
|
|
|
|
find(".search-info .bulk-select-topics-dropdown-trigger").click
|
|
|
|
find(".bulk-select-topics-dropdown-content .append-tags").click
|
|
|
|
expect(topic_bulk_actions_modal).to be_open
|
|
|
|
tag_selector = PageObjects::Components::SelectKit.new(".tag-chooser")
|
|
|
|
tag_selector.search(tag1.name)
|
|
|
|
tag_selector.select_row_by_value(tag1.name)
|
|
|
|
tag_selector.collapse
|
|
|
|
topic_bulk_actions_modal.click_bulk_topics_confirm
|
|
|
|
expect(
|
|
|
|
find(".fps-result .fps-topic[data-topic-id=\"#{topic.id}\"] .discourse-tags"),
|
|
|
|
).to have_content(tag1.name)
|
2024-06-06 20:41:42 -04:00
|
|
|
end
|
|
|
|
end
|
2022-12-13 09:50:44 -05:00
|
|
|
end
|