Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix some test selectors and extract the subheader into a separate component

Henriette Darge61404b1a76f2
diff --git a/app/components/projects/index_sub_header_component.html.erb b/app/components/projects/index_sub_header_component.html.erb
new file mode 100644
index 00000000000..bd09217edd2
--- /dev/null
+++ b/app/components/projects/index_sub_header_component.html.erb
@@ -0,0 +1,23 @@
+<%= render(Primer::OpenProject::SubHeader.new(data: {
+ controller: "filters",
+ "application-target": "dynamic",
+ })) do |subheader|
+ subheader.with_filter_component do
+ render(Filter::FilterButtonComponent.new(query: @query, disabled: @disable_buttons))
+ end
+
+ subheader.with_action_button(tag: :a,
+ href: new_project_path,
+ scheme: :primary,
+ disabled: @disable_buttons,
+ size: :medium,
+ aria: { label: I18n.t(:label_project_new) },
+ data: { 'test-selector': 'project-new-button' }) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ Project.model_name.human
+ end if @current_user.allowed_globally?(:add_project)
+
+ subheader.with_bottom_pane_component(mt: 0) do
+ render(Projects::ProjectsFiltersComponent.new(query: @query))
+ end
+ end %>
diff --git a/app/components/projects/index_sub_header_component.rb b/app/components/projects/index_sub_header_component.rb
new file mode 100644
index 00000000000..cbd16be7fa4
--- /dev/null
+++ b/app/components/projects/index_sub_header_component.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module Projects
+ # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class IndexSubHeaderComponent < ApplicationComponent
+ # rubocop:enable OpenProject/AddPreviewForViewComponent
+ include ApplicationHelper
+
+ def initialize(query:, current_user:, disable_buttons: nil)
+ super
+ @query = query
+ @current_user = current_user
+ @disable_buttons = disable_buttons
+ end
+ end
+end
diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
index 6a85a391420..3c31b3294e7 100644
--- a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
+++ b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
@@ -11,7 +11,6 @@
icon: :search,
size: :small
},
- input_width: :xlarge,
show_clear_button: true,
clear_button_id: "project-custom-fields-mapping-filter-clear-button",
data: {
diff --git a/app/components/settings/project_custom_fields/header_component.html.erb b/app/components/settings/project_custom_fields/header_component.html.erb
index a9fe5181caf..d05b23f37dd 100644
--- a/app/components/settings/project_custom_fields/header_component.html.erb
+++ b/app/components/settings/project_custom_fields/header_component.html.erb
@@ -1,34 +1,36 @@
-<%=
- render Primer::OpenProject::PageHeader.new do |header|
- header.with_title(variant: :default) { t("settings.project_attributes.heading") }
- header.with_description { t("settings.project_attributes.heading_description") }
- header.with_breadcrumbs(breadcrumbs_items)
- end
-%>
+<%= component_wrapper do %>
+ <%=
+ render Primer::OpenProject::PageHeader.new do |header|
+ header.with_title(variant: :default) { t("settings.project_attributes.heading") }
+ header.with_description { t("settings.project_attributes.heading_description") }
+ header.with_breadcrumbs(breadcrumbs_items)
+ end
+ %>
-<%=
- render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component do
- render(Primer::Alpha::Dialog.new(id: "project-custom-field-section-dialog", title: t('settings.project_attributes.label_new_section'), size: :medium_portrait)) do |dialog|
- dialog.with_show_button('aria-label': t('settings.project_attributes.label_new_section')) do |button|
- button.with_leading_visual_icon(icon: :plus)
- t('settings.project_attributes.label_new_section')
- end
- dialog.with_body do
- render(Settings::ProjectCustomFieldSections::DialogBodyFormComponent.new)
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_component do
+ render(Primer::Alpha::Dialog.new(id: "project-custom-field-section-dialog", title: t('settings.project_attributes.label_new_section'), size: :medium_portrait)) do |dialog|
+ dialog.with_show_button('aria-label': t('settings.project_attributes.label_new_section')) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t('settings.project_attributes.label_new_section')
+ end
+ dialog.with_body do
+ render(Settings::ProjectCustomFieldSections::DialogBodyFormComponent.new)
+ end
end
end
- end
- subheader.with_action_button(tag: :a,
- href: new_admin_settings_project_custom_field_path(type: "ProjectCustomField"),
- scheme: :primary,
- data: { turbo: "false", test_selector: "new-project-custom-field-button" },
- mobile_icon: :plus,
- mobile_label: t("settings.project_attributes.label_new_attribute")) do |button|
- button.with_leading_visual_icon(icon: :plus)
- t("settings.project_attributes.label_new_attribute")
- end
+ subheader.with_action_button(tag: :a,
+ href: new_admin_settings_project_custom_field_path(type: "ProjectCustomField"),
+ scheme: :primary,
+ data: { turbo: "false", test_selector: "new-project-custom-field-button" },
+ mobile_icon: :plus,
+ mobile_label: t("settings.project_attributes.label_new_attribute")) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t("settings.project_attributes.label_new_attribute")
+ end
- end
-%>
+ end
+ %>
+<% end %>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 88c3662c188..de20141c7b9 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -38,33 +38,8 @@ See COPYRIGHT and LICENSE files for more details.
)
)
%>
- <%=
- disable_extra_controls = state == :rename
- render(Primer::OpenProject::SubHeader.new(data: {
- controller: "filters",
- "application-target": "dynamic",
- })) do |subheader|
- subheader.with_filter_component do
- render(Filter::FilterButtonComponent.new(query:))
- end
-
- subheader.with_action_button(tag: :a,
- href: new_project_path,
- scheme: :primary,
- disabled: disable_extra_controls,
- size: :medium,
- aria: { label: I18n.t(:label_project_new) },
- data: { 'test-selector': 'project-new-button' }) do |button|
- button.with_leading_visual_icon(icon: :plus)
- Project.model_name.human
- end if current_user.allowed_globally?(:add_project)
-
- subheader.with_bottom_pane_component(mt: 0) do
- render(Projects::ProjectsFiltersComponent.new(query:, disabled: disable_extra_controls))
- end
- end
- %>
+ <%= render(Projects::IndexSubHeaderComponent.new(query:, current_user:, disable_buttons: state === :rename)) %>
<%= render Projects::TableComponent.new(
query:,
diff --git a/modules/storages/app/views/storages/admin/storages/index.html.erb b/modules/storages/app/views/storages/admin/storages/index.html.erb
index 4dfc4ffa26a..db38dbc4930 100644
--- a/modules/storages/app/views/storages/admin/storages/index.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/index.html.erb
@@ -19,7 +19,8 @@ end %>
render(Primer::Alpha::ActionMenu.new(test_selector: 'storages-select-provider-action-menu',
anchor_align: :end)) do |menu|
menu.with_show_button(scheme: :primary,
- aria: { label: I18n.t("storages.label_add_new_storage") }) do |button|
+ aria: { label: I18n.t("storages.label_add_new_storage") },
+ test_selector: "storages-create-new-provider-button") do |button|
button.with_leading_visual_icon(icon: :plus)
button.with_trailing_action_icon(icon: :"triangle-down")
I18n.t("storages.label_storage")
diff --git a/modules/storages/spec/features/storages/admin/create_storage_spec.rb b/modules/storages/spec/features/storages/admin/create_storage_spec.rb
index 08434f5cd13..620e1a3eee7 100644
--- a/modules/storages/spec/features/storages/admin/create_storage_spec.rb
+++ b/modules/storages/spec/features/storages/admin/create_storage_spec.rb
@@ -50,8 +50,8 @@ RSpec.describe "Admin Create a new file storage",
expect(page).to be_axe_clean.within "#content"
- within(".PageHeader-titleBar") do
- click_on("Storage")
+ within(".SubHeader") do
+ page.find_test_selector("storages-create-new-provider-button").click
within_test_selector("storages-select-provider-action-menu") { click_on("Nextcloud") }
end
@@ -193,8 +193,8 @@ RSpec.describe "Admin Create a new file storage",
it "renders enterprise icon and redirects to upsale", :webmock do
visit admin_settings_storages_path
- within(".PageHeader-titleBar") do
- click_on("Storage")
+ within(".SubHeader") do
+ page.find_test_selector("storages-create-new-provider-button").click
within_test_selector("storages-select-provider-action-menu") do
expect(page).to have_css(".octicon-op-enterprise-addons")
@@ -213,9 +213,8 @@ RSpec.describe "Admin Create a new file storage",
expect(page).to be_axe_clean.within "#content"
- within(".PageHeader-titleBar") do
- click_on("Storage")
-
+ within(".SubHeader") do
+ page.find_test_selector("storages-create-new-provider-button").click
within_test_selector("storages-select-provider-action-menu") { click_on("OneDrive/SharePoint") }
end