DEV: Introduce <DPageHeader /> and <DPageSubheader /> components (#30146)

This converts the `<AdminPageHeader />` component and the
`<AdminPageSubheader />` components into new components
that can be used outside of admin, and updates the CSS classes.
Also introduces a `<DPageActionButton />` component and child
components for the header action buttons.

I have to keep the old admin-only components around for
now until plugins are updated, then we can remove it,
and remove the re-exports that are done within
admin-page-action-button.gjs
This commit is contained in:
Martin Brennan
2024-12-18 08:13:39 +10:00
committed by GitHub
parent ef754cdd9a
commit a879bcdc35
41 changed files with 789 additions and 489 deletions

View File

@ -8,7 +8,7 @@ describe "Admin Flags Page", type: :system do
let(:admin_flags_page) { PageObjects::Pages::AdminFlags.new }
let(:admin_flag_form_page) { PageObjects::Pages::AdminFlagForm.new }
let(:flag_modal) { PageObjects::Modals::Flag.new }
let(:admin_header) { PageObjects::Components::AdminHeader.new }
let(:d_page_header) { PageObjects::Components::DPageHeader.new }
before do
sign_in(admin)
@ -27,7 +27,7 @@ describe "Admin Flags Page", type: :system do
)
admin_flags_page.visit
expect(admin_header).to be_visible
expect(d_page_header).to be_visible
admin_flags_page.toggle("spam")
topic_page.visit_topic(post.topic).open_flag_topic_modal
@ -81,8 +81,7 @@ describe "Admin Flags Page", type: :system do
expect(admin_flags_page).to have_add_flag_button_enabled
admin_flags_page.click_add_flag
expect(admin_header).to be_hidden
expect(d_page_header).to be_hidden
admin_flag_form_page
.fill_in_name("Vulgar")
@ -115,7 +114,7 @@ describe "Admin Flags Page", type: :system do
# update
admin_flags_page.visit.click_edit_flag("custom_vulgar")
expect(admin_header).to be_hidden
expect(d_page_header).to be_hidden
admin_flag_form_page.fill_in_name("Tasteless").click_save
expect(admin_flags_page).to have_flags(
@ -158,7 +157,7 @@ describe "Admin Flags Page", type: :system do
it "has settings tab" do
admin_flags_page.visit
expect(admin_header).to have_tabs(
expect(d_page_header).to have_tabs(
[I18n.t("admin_js.settings"), I18n.t("admin_js.admin.config_areas.flags.flags_tab")],
)

View File

@ -6,11 +6,11 @@ describe "Admin User Fields", type: :system do
before { sign_in(current_user) }
let(:user_fields_page) { PageObjects::Pages::AdminUserFields.new }
let(:admin_header) { PageObjects::Components::AdminHeader.new }
let(:page_header) { PageObjects::Components::DPageHeader.new }
it "correctly saves user fields" do
user_fields_page.visit
expect(admin_header).to be_visible
expect(page_header).to be_visible
user_fields_page.add_field(name: "Occupation", description: "What you do for work")
expect(user_fields_page).to have_user_field("Occupation")
@ -32,7 +32,7 @@ describe "Admin User Fields", type: :system do
user_fields_page.visit
user_fields_page.click_add_field
expect(admin_header).to be_hidden
expect(page_header).to be_hidden
form = page.find(".user-field")
editable_label = I18n.t("admin_js.admin.user_fields.editable.title")
@ -73,7 +73,7 @@ describe "Admin User Fields", type: :system do
form.find(".user-field-name").fill_in(with: "Favourite Transformer")
expect(admin_header).to be_hidden
expect(page_header).to be_hidden
form.find(".btn-primary").click

View File

@ -2,17 +2,18 @@
module PageObjects
module Components
# TODO (martin) Delete this after plugins have been updated to use DPageHeader
class AdminHeader < PageObjects::Pages::Base
def has_tabs?(names)
expect(page.all(".admin-nav-submenu__tabs a").map(&:text)).to eq(names)
expect(page.all(".d-nav-submenu__tabs a").map(&:text)).to eq(names)
end
def visible?
has_css?(".admin-page-header")
has_css?(".d-page-header")
end
def hidden?
has_no_css?(".admin-page-header")
has_no_css?(".d-page-header")
end
end
end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
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)
end
def visible?
has_css?(".d-page-header")
end
def hidden?
has_no_css?(".d-page-header")
end
end
end
end

View File

@ -21,7 +21,7 @@ module PageObjects
end
def plugin_nav_tab_selector(plugin)
".admin-nav-submenu__tabs .admin-plugin-tab-nav-item[data-plugin-nav-tab-id=\"#{plugin}\"]"
".d-nav-submenu__tabs .admin-plugin-tab-nav-item[data-plugin-nav-tab-id=\"#{plugin}\"]"
end
end
end

View File

@ -19,7 +19,7 @@ module PageObjects
end
def click_add_field
page.find(".admin-page-header__actions .btn-primary").click
page.find(".d-page-header__actions .btn-primary").click
end
def click_edit