DEV: Add base admin page page object (#30814)

This PR introduces a base page object for admin pages. Since we're standardizing using components, this makes writing tests easier by abstracting away details about selectors.
This commit is contained in:
Ted Johansson 2025-01-16 12:52:41 +08:00 committed by GitHub
parent a46d1547ab
commit 4682919744
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 53 additions and 63 deletions

View File

@ -82,6 +82,7 @@ Dir[Rails.root.join("spec/requests/examples/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/system/helpers/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/system/page_objects/**/base.rb")].each { |f| require f }
Dir[Rails.root.join("spec/system/page_objects/**/*_base.rb")].each { |f| require f }
Dir[Rails.root.join("spec/system/page_objects/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/fabricators/*.rb")].each { |f| require f }

View File

@ -66,12 +66,12 @@ RSpec.describe "Admin EmbeddableHost Management", type: :system do
admin_embedding_page.visit
expect(page).not_to have_content("#{author.username}")
admin_embedding_page.click_posts_and_topics_tab
admin_embedding_page.click_tab("posts-and-topics")
admin_embedding_posts_and_topics_page.fill_in_embed_by_username(author)
admin_embedding_posts_and_topics_page.click_save
admin_embedding_page.click_hosts_tab
admin_embedding_page.click_tab("hosts")
expect(page).to have_content("#{author.username}")
end
end

View File

@ -157,11 +157,11 @@ describe "Admin Flags Page", type: :system do
it "has settings tab" do
admin_flags_page.visit
expect(d_page_header).to have_tabs(
expect(admin_flags_page).to have_tabs(
[I18n.t("admin_js.settings"), I18n.t("admin_js.admin.config_areas.flags.flags_tab")],
)
admin_flags_page.click_settings_tab
admin_flags_page.click_tab("settings")
expect(page.all(".setting-label h3").map(&:text).map(&:downcase)).to eq(
[
"silence new user sensitivity",

View File

@ -4,7 +4,15 @@ module PageObjects
module Components
class DPageHeader < PageObjects::Pages::Base
def has_tabs?(names)
expect(page.all(".d-nav-submenu__tabs a").map(&:text)).to eq(names)
expect(page.all("#{tabs_container_selector} a").map(&:text)).to eq(names)
end
def has_active_tab?(tab_name)
find("#{tab_selector(tab_name)} .active")
end
def tab(tab_name)
find(tab_selector(tab_name))
end
def visible?
@ -14,6 +22,20 @@ module PageObjects
def hidden?
has_no_css?(".d-page-header")
end
private
def tabs_container_selector
"ul.d-nav-submenu__tabs"
end
def tab_item_selector(tab_name)
"li[class$='-tabs__#{tab_name}']"
end
def tab_selector(tab_name)
"#{tabs_container_selector} > #{tab_item_selector(tab_name)}"
end
end
end
end

View File

@ -2,23 +2,12 @@
module PageObjects
module Pages
class AdminBackups < PageObjects::Pages::Base
class AdminBackups < AdminBase
def visit_page
page.visit "/admin/backups"
self
end
def click_tab(tab_name)
case tab_name
when "settings"
find(".admin-backups-tabs__settings").click
when "files"
find(".admin-backups-tabs__files").click
when "logs"
find(".admin-backups-tabs__logs").click
end
end
def has_backup_listed?(filename)
page.has_css?(backup_row_selector(filename))
end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
module PageObjects
module Pages
class AdminBase < Base
def click_tab(tab_name)
header.tab(tab_name).click
end
delegate(:has_tabs?, :has_active_tab?, to: :header)
private
def header
@header ||= Components::DPageHeader.new
end
end
end
end

View File

@ -2,20 +2,12 @@
module PageObjects
module Pages
class AdminEmbedding < PageObjects::Pages::Base
class AdminEmbedding < AdminBase
def visit
page.visit("/admin/customize/embedding")
self
end
def click_posts_and_topics_tab
find(".admin-embedding-tabs__posts-and-topics").click
end
def click_hosts_tab
find(".admin-embedding-tabs__hosts").click
end
def click_add_host
find(".admin-embedding__header-add-host").click
self

View File

@ -2,21 +2,12 @@
module PageObjects
module Pages
class AdminEmojis < PageObjects::Pages::Base
class AdminEmojis < AdminBase
def visit_page
page.visit "/admin/config/emoji"
self
end
def click_tab(tab_name)
case tab_name
when "settings"
find(".admin-emoji-tabs__settings").click
when "index"
find(".admin-emoji-tabs__emoji").click
end
end
def has_emoji_listed?(name)
page.has_css?(emoji_table_selector, text: name)
end

View File

@ -2,7 +2,7 @@
module PageObjects
module Pages
class AdminFlags < PageObjects::Pages::Base
class AdminFlags < AdminBase
def visit
page.visit("/admin/config/flags")
self
@ -106,11 +106,6 @@ module PageObjects
expect(page).to have_no_css(".dialog-body", wait: Capybara.default_max_wait_time * 3)
self
end
def click_settings_tab
find(".admin-flags-tabs__settings a").click
self
end
end
end
end

View File

@ -2,7 +2,7 @@
module PageObjects
module Pages
class AdminPermalinks < PageObjects::Pages::Base
class AdminPermalinks < AdminBase
def visit
page.visit("/admin/config/permalinks")
self
@ -65,15 +65,6 @@ module PageObjects
def has_closed_permalink_menu?
has_no_css?(".permalink-menu-content")
end
def click_tab(tab)
has_css?(".admin-permalinks-tabs__#{tab}")
find(".admin-permalinks-tabs__#{tab}").click
end
def has_active_tab?(tab)
has_css?(".admin-permalinks-tabs__#{tab} .active")
end
end
end
end

View File

@ -2,7 +2,7 @@
module PageObjects
module Pages
class AdminUsers < PageObjects::Pages::Base
class AdminUsers < AdminBase
class UserRow
attr_reader :element
@ -77,16 +77,6 @@ module PageObjects
has_content?(I18n.t("js.search.no_results"))
end
def click_tab(tab)
has_css?(".admin-users-tabs__#{tab}")
find(".admin-users-tabs__#{tab}").click
end
def has_active_tab?(tab)
has_css?(".admin-users-tabs__#{tab} .active")
has_no_css?(".loading-container .visible")
end
def has_no_emails?
has_no_css?(".directory-table__column-header--email")
end