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 }
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is a test post in a test topic") }
|
|
|
|
|
|
|
|
describe "when using full page search on mobile" do
|
|
|
|
before do
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
|
|
|
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")
|
|
|
|
|
|
|
|
search_page.click_home_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
|
|
|
|
|
|
|
|
search_page.click_home_logo
|
|
|
|
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
|
|
|
|
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
|
2022-12-13 09:50:44 -05:00
|
|
|
end
|