discourse/spec/system/welcome_banner_spec.rb
Martin Brennan 0971556058
FIX: Do not show header search icon if welcome banner search shown (#33098)
This brings the search_icon header search mode to parity with the
search_field mode. We don't want to show either of these if the welcome
banner is showing, since it has a search field, this is redundant.

If you scroll the page and the welcome banner is hidden, then we
show the header search icon.

This commit also cleans up some code related to the page-search
shortcut, which we no longer use, including limiting showing search
on topic only if there are > 20 posts.
2025-06-09 09:17:13 +10:00

96 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Welcome banner", type: :system do
fab!(:current_user) { Fabricate(:user) }
let(:banner) { PageObjects::Components::WelcomeBanner.new }
let(:search_page) { PageObjects::Pages::Search.new }
context "when welcome banner is enabled" do
before { SiteSetting.enable_welcome_banner = true }
it "shows for logged in and anonymous users" do
visit "/"
expect(banner).to be_visible
expect(banner).to have_anonymous_title
sign_in(current_user)
visit "/"
expect(banner).to have_logged_in_title(current_user.username)
end
it "only displays on top_menu routes" do
sign_in(current_user)
SiteSetting.remove_override!(:top_menu)
topic = Fabricate(:topic)
visit "/"
expect(banner).to be_visible
visit "/latest"
expect(banner).to be_visible
visit "/new"
expect(banner).to be_visible
visit "/unread"
expect(banner).to be_visible
visit "/hot"
expect(banner).to be_visible
visit "/tags"
expect(banner).to be_hidden
visit topic.relative_url
expect(banner).to be_hidden
end
context "when using search_field search_experience" do
before { SiteSetting.search_experience = "search_field" }
it "hides welcome banner and shows header search on scroll, and vice-versa" do
Fabricate(:topic)
sign_in(current_user)
visit "/"
expect(banner).to be_visible
expect(search_page).to have_no_search_field
fake_scroll_down_long
expect(banner).to be_invisible
expect(search_page).to have_search_field
page.scroll_to(0, 0)
expect(banner).to be_visible
expect(search_page).to have_no_search_field
end
end
context "when using search_icon search_experience" do
before { SiteSetting.search_experience = "search_icon" }
it "hides welcome banner and shows header search on scroll, and vice-versa" do
Fabricate(:topic)
sign_in(current_user)
visit "/"
expect(banner).to be_visible
expect(search_page).to have_no_search_icon
fake_scroll_down_long
expect(banner).to be_invisible
expect(search_page).to have_search_icon
page.scroll_to(0, 0)
expect(banner).to be_visible
expect(search_page).to have_no_search_icon
end
end
end
context "when welcome banner is not enabled" do
before { SiteSetting.enable_welcome_banner = false }
it "does not show the welcome banner for logged in and anonymous users" do
visit "/"
expect(banner).to be_hidden
sign_in(current_user)
visit "/"
expect(banner).to be_hidden
end
end
end