0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/spec/system/page_objects/components/welcome_banner.rb
Régis Hanol 3709d8f3e3
FIX: Hand off search cleanly between welcome banner and header search (#42018)
Previously, the header search field appeared as soon as the welcome
banner was no longer fully visible, leaving both search bars on screen
and interactive at once; since they share one search service, a single
search could show its results in both panels, the banner's open results
panel could overlay and swallow clicks aimed at the header field, and
typing into the superseded banner input ran searches with no visible
results.

This change bases the switch on the banner's search bar itself: the
banner remains the only search UI while any part of its input is below
the header, and the header search replaces it exactly when the input is
fully tucked away — with focus and the open results panel following the
handoff in both directions, stray focus on the superseded input
redirected to the active one, and hidden menus closed so a dismissed
panel stays dismissed.

Note the intentional behavior change: the header search field now
appears slightly later when scrolling (once the banner search bar is
fully under the header, rather than on the first pixel of scroll).

Internal topic: t/188511
2026-07-28 15:56:20 +02:00

100 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Components
class WelcomeBanner < PageObjects::Components::Base
def visible?
has_css?(".welcome-banner")
end
def hidden?
has_no_css?(".welcome-banner")
end
def invisible?
has_css?(".welcome-banner", visible: false)
end
def open_search_menu
find(".welcome-banner #welcome-banner-search-input").click
self
end
def has_search_menu?
has_css?(".welcome-banner .search-menu-panel", visible: false)
end
def has_no_search_menu?
has_no_css?(".welcome-banner .search-menu-panel", visible: false)
end
def has_anonymous_title?
has_css?(
".welcome-banner .welcome-banner__title",
text: I18n.t("js.welcome_banner.header.anonymous_members", site_name: SiteSetting.title),
)
end
def has_logged_in_title?(username)
has_css?(
".welcome-banner .welcome-banner__title",
text:
I18n.t("js.welcome_banner.header.logged_in_members", preferred_display_name: username),
)
end
def has_new_user_title?(username)
has_css?(
".welcome-banner .welcome-banner__title",
text: I18n.t("js.welcome_banner.header.new_members", preferred_display_name: username),
)
end
def has_no_subheader?
has_no_css?(".welcome-banner .welcome-banner__subheader")
end
def has_anonymous_subheader?
has_css?(
".welcome-banner .welcome-banner__subheader",
text: I18n.t("js.welcome_banner.subheader.anonymous_members"),
)
end
def has_logged_in_subheader?
has_css?(
".welcome-banner .welcome-banner__subheader",
text: I18n.t("js.welcome_banner.subheader.logged_in_members"),
)
end
def has_no_bg_img?
has_no_css?(".welcome-banner.--with-bg-img")
end
def has_bg_img?(url)
has_css?(
".welcome-banner.--with-bg-img .custom-search-banner-wrap.welcome-banner__wrap",
style: "background-image:url(#{url});",
visible: true,
)
end
def has_custom_text_color?(color)
has_css?(".welcome-banner .welcome-banner__title", style: "color:#{color};", visible: true)
end
def has_no_custom_text_color?(color)
has_no_css?(".welcome-banner .welcome-banner__title", style: "color:#{color};")
end
def above_topic_content?
has_css?("#main-outlet > .--location-above-topic-content", visible: true)
end
def below_site_header?
has_css?(".discourse-root > .--location-below-site-header", visible: true)
end
end
end
end