From e79a50d7a9a5baf5c3ea812d0e1bfd6f7018f443 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 8 Aug 2024 13:52:48 +0200 Subject: [PATCH] DEV: adds logo page component (#28276) Usage: ``` click_logo # globally accessible PageObjects::Components::Logo.click PageObjects::Components::Logo.hover ``` --- .../system/admin_sidebar_navigation_spec.rb | 4 ++-- plugins/chat/spec/system/chat_channel_spec.rb | 2 +- plugins/chat/spec/system/navigation_spec.rb | 6 +++--- .../page_objects/chat_drawer/chat_drawer.rb | 2 +- .../spec/system/separate_sidebar_mode_spec.rb | 8 ++++---- spec/support/system_helpers.rb | 4 ++++ spec/system/homepage_spec.rb | 6 +++--- spec/system/page_objects/components/logo.rb | 17 +++++++++++++++++ spec/system/page_objects/pages/search.rb | 4 ---- spec/system/request_tracker_spec.rb | 4 ++-- spec/system/scroll_manager_service_spec.rb | 2 +- spec/system/search_spec.rb | 5 ++--- .../user_page/user_preferences_profile_spec.rb | 4 ++-- 13 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 spec/system/page_objects/components/logo.rb diff --git a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb index 00fa0b90a80..b15bca51d2a 100644 --- a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb +++ b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb @@ -43,7 +43,7 @@ describe "Admin Revamp | Sidebar Navigation | Plugin Links", type: :system do expect(sidebar).to have_switch_button("chat") sidebar.click_link_in_section("community", "admin") expect(sidebar).to have_no_switch_button("chat") - find("#site-logo").click + click_logo expect(sidebar).to have_switch_button("chat") end @@ -56,7 +56,7 @@ describe "Admin Revamp | Sidebar Navigation | Plugin Links", type: :system do expect(sidebar).to have_no_switch_button("chat") sidebar.click_link_in_section("community", "admin") expect(sidebar).to have_no_section("chat-channels") - find("#site-logo").click + click_logo expect(sidebar).to have_section("chat-channels") end diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rb index 1c97ad6b4ef..3326335d408 100644 --- a/plugins/chat/spec/system/chat_channel_spec.rb +++ b/plugins/chat/spec/system/chat_channel_spec.rb @@ -372,7 +372,7 @@ RSpec.describe "Chat channel", type: :system do ".chat-message-actions-container .secondary-actions .select-kit-body", ) - find("#site-logo").hover + PageObjects::Components::Logo.hover expect(page).to have_css( ".chat-message-actions-container .secondary-actions .select-kit-body", ) diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb index 312c7c2f029..2e7fb0734f9 100644 --- a/plugins/chat/spec/system/navigation_spec.rb +++ b/plugins/chat/spec/system/navigation_spec.rb @@ -351,7 +351,7 @@ RSpec.describe "Navigation", type: :system do chat_page.open_from_header chat_drawer_page.maximize sidebar_page.open_channel(category_channel_2) - find("#site-logo").click + click_logo expect(chat_page).to have_header_href(chat_channel_path) @@ -395,7 +395,7 @@ RSpec.describe "Navigation", type: :system do context "when clicking logo from a channel in full page" do it "deactivates the channel in the sidebar" do visit("/chat/c/#{category_channel.slug}/#{category_channel.id}") - find("#site-logo").click + click_logo expect(sidebar_component).to have_no_section_link(category_channel.name, active: true) end @@ -440,7 +440,7 @@ RSpec.describe "Navigation", type: :system do expect(side_panel_page).to have_open_thread(thread) - find("#site-logo").click + click_logo sidebar_component.switch_to_chat expect(side_panel_page).to have_open_thread(thread) diff --git a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb index 384094a3a66..5f9f2273f98 100644 --- a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb +++ b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb @@ -152,7 +152,7 @@ module PageObjects # and that the message actions menu is closed. # This check is essential because the message actions menu might partially # overlap with the header, making certain buttons inaccessible. - find("#site-logo").hover + PageObjects::Components::Logo.hover end end end diff --git a/plugins/chat/spec/system/separate_sidebar_mode_spec.rb b/plugins/chat/spec/system/separate_sidebar_mode_spec.rb index 21fde310ee3..09444505a45 100644 --- a/plugins/chat/spec/system/separate_sidebar_mode_spec.rb +++ b/plugins/chat/spec/system/separate_sidebar_mode_spec.rb @@ -40,7 +40,7 @@ RSpec.describe "Separate sidebar mode", type: :system do expect(sidebar_component).to have_section("chat-channels") expect(sidebar_component).to have_no_section("Categories") - find("#site-logo").click + click_logo expect(sidebar_component).to have_switch_button("chat") expect(header_component).to have_open_chat_button @@ -101,7 +101,7 @@ RSpec.describe "Separate sidebar mode", type: :system do expect(sidebar_component).to have_section("Categories") expect(sidebar_component).to have_section("chat-channels") - find("#site-logo").click + click_logo expect(sidebar_component).to have_no_switch_button expect(header_component).to have_open_chat_button @@ -177,7 +177,7 @@ RSpec.describe "Separate sidebar mode", type: :system do expect(sidebar_component).to have_section("chat-channels") expect(sidebar_component).to have_no_section("Categories") - find("#site-logo").click + click_logo expect(sidebar_component).to have_switch_button("chat") expect(header_component).to have_open_chat_button @@ -292,7 +292,7 @@ RSpec.describe "Separate sidebar mode", type: :system do expect(sidebar_component).to have_section("chat-channels") expect(sidebar_component).to have_no_section("Categories") - find("#site-logo").click + click_logo expect(sidebar_component).to have_switch_button("chat") expect(header_component).to have_open_chat_button diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb index 850862b7f71..b7d5030e226 100644 --- a/spec/support/system_helpers.rb +++ b/spec/support/system_helpers.rb @@ -161,4 +161,8 @@ module SystemHelpers def skip_on_ci!(message = "Flaky on CI") skip(message) if ENV["CI"] end + + def click_logo + PageObjects::Components::Logo.click + end end diff --git a/spec/system/homepage_spec.rb b/spec/system/homepage_spec.rb index 29546fdda78..e140dfeb62e 100644 --- a/spec/system/homepage_spec.rb +++ b/spec/system/homepage_spec.rb @@ -63,7 +63,7 @@ describe "Homepage", type: :system do find("#sidebar-section-content-community li:first-child").click expect(page).to have_css(".list-container") - find("#site-logo").click + click_logo expect(page).to have_no_css(".list-container") # ensure clicking on logo brings user back to the custom homepage @@ -93,7 +93,7 @@ describe "Homepage", type: :system do find(".btn-primary.save-changes:not([disabled])", wait: 5) expect(user.user_option.homepage_id).to eq(UserOption::HOMEPAGES.key("top")) - find("#site-logo").click + click_logo expect(page).to have_css(".navigation-container .top.active", text: "Top") expect(page).to have_css(".top-lists") @@ -109,7 +109,7 @@ describe "Homepage", type: :system do find(".btn-primary.save-changes:not([disabled])", wait: 5) expect(user.reload.user_option.homepage_id).to_not eq(UserOption::HOMEPAGES.key("top")) - find("#site-logo").click + click_logo expect(page).to have_current_path("/") expect(page).to have_css(".new-home", text: "Hi friends!") diff --git a/spec/system/page_objects/components/logo.rb b/spec/system/page_objects/components/logo.rb new file mode 100644 index 00000000000..4a74382cc56 --- /dev/null +++ b/spec/system/page_objects/components/logo.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module PageObjects + module Components + class Logo < PageObjects::Pages::Base + SELECTOR = "#site-logo" + + def self.click + new.find(SELECTOR).click + end + + def self.hover + new.find(SELECTOR).hover + end + end + end +end diff --git a/spec/system/page_objects/pages/search.rb b/spec/system/page_objects/pages/search.rb index 6978eb0a935..50804c9e01b 100644 --- a/spec/system/page_objects/pages/search.rb +++ b/spec/system/page_objects/pages/search.rb @@ -30,10 +30,6 @@ module PageObjects find(".search-cta").click end - def click_home_logo - find(".d-header .logo-mobile").click - end - def click_search_icon find(".d-header #search-button").click end diff --git a/spec/system/request_tracker_spec.rb b/spec/system/request_tracker_spec.rb index b334d7c0003..3fa625913ce 100644 --- a/spec/system/request_tracker_spec.rb +++ b/spec/system/request_tracker_spec.rb @@ -105,7 +105,7 @@ describe "Request tracking", type: :system do ) end - find("#site-logo").click + click_logo try_until_success do CachedCounting.flush @@ -153,7 +153,7 @@ describe "Request tracking", type: :system do ) end - find("#site-logo").click + click_logo try_until_success do CachedCounting.flush diff --git a/spec/system/scroll_manager_service_spec.rb b/spec/system/scroll_manager_service_spec.rb index d89d81d35d3..76442b69cce 100644 --- a/spec/system/scroll_manager_service_spec.rb +++ b/spec/system/scroll_manager_service_spec.rb @@ -38,7 +38,7 @@ describe "Ember route-scroll-manager service", type: :system do try_until_success { expect(current_scroll_y).to eq(topic_list_scroll_y) } # Clicking site logo triggers refresh and scrolls to top - find("#site-logo").click + click_logo try_until_success { expect(current_scroll_y).to eq(0) } end end diff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rb index 8c6becc2a82..305514d3e27 100644 --- a/spec/system/search_spec.rb +++ b/spec/system/search_spec.rb @@ -27,14 +27,14 @@ describe "Search", type: :system do expect(search_page).to have_search_result expect(search_page.heading_text).not_to eq("Search") - search_page.click_home_logo + click_logo expect(search_page).to be_not_active 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 + click_logo search_page.click_search_icon expect(search_page).to have_no_search_result @@ -103,7 +103,6 @@ describe "Search", type: :system do 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) diff --git a/spec/system/user_page/user_preferences_profile_spec.rb b/spec/system/user_page/user_preferences_profile_spec.rb index f31ee17ced4..2b29bd3335d 100644 --- a/spec/system/user_page/user_preferences_profile_spec.rb +++ b/spec/system/user_page/user_preferences_profile_spec.rb @@ -47,7 +47,7 @@ describe "User preferences | Profile", type: :system do expect(page).to have_current_path("/faq") - find("#site-logo").click + click_logo expect(page).to have_current_path("/u/#{user.username}/preferences/profile") @@ -60,7 +60,7 @@ describe "User preferences | Profile", type: :system do it "disables client-side routing while missing required fields" do user_preferences_profile_page.visit(user) - find("#site-logo").click + click_logo expect(page).to have_current_path("/u/#{user.username}/preferences/profile") end