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

added specs for project custom field administration, fixed minor bugs

Jonas Jabarida2c3a922585
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
index d376d4ebcb3..86ad4a07226 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
@@ -1,5 +1,5 @@
<%=
- component_wrapper do
+ component_wrapper(class: "op-project-custom-field-container", data: { qa_selector: "project-custom-field-container-#{@project_custom_field.id}" }) do
flex_layout(justify_content: :space_between, align_items: :center) do |main_container|
main_container.with_column(flex_layout: true, align_items: :center) do |content_container|
content_container.with_column(mr: 2) do
@@ -28,7 +28,7 @@
end
end
main_container.with_column do
- render(Primer::Alpha::ActionMenu.new) do |menu|
+ render(Primer::Alpha::ActionMenu.new(data: { qa_selector: "project-custom-field-action-menu" })) do |menu|
menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_project_custom_field_actions"), scheme: :invisible)
edit_action_item(menu)
move_actions(menu)
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
index 1edf7fb943c..4a5ad54384d 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -44,7 +44,7 @@ module Settings
def edit_action_item(menu)
menu.with_item(label: t("label_edit"),
href: edit_admin_settings_project_custom_field_path(@project_custom_field),
- data: { turbo: "false" }) do |item|
+ data: { turbo: "false", qa_selector: "project-custom-field-edit" }) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
end
@@ -72,7 +72,7 @@ module Settings
menu.with_item(label: label_text,
href: move_admin_settings_project_custom_field_path(@project_custom_field, move_to:),
form_arguments: {
- method: :put, data: { 'turbo-stream': true }
+ method: :put, data: { 'turbo-stream': true, qa_selector: "project-custom-field-move-#{move_to}" }
}) do |item|
item.with_leading_visual_icon(icon:)
end
@@ -83,7 +83,8 @@ module Settings
scheme: :danger,
href: admin_settings_project_custom_field_path(@project_custom_field),
form_arguments: {
- method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true }
+ method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true,
+ qa_selector: "project-custom-field-delete" }
}) do |item|
item.with_leading_visual_icon(icon: :trash)
end
diff --git a/app/components/settings/project_custom_field_sections/show_component.html.erb b/app/components/settings/project_custom_field_sections/show_component.html.erb
index bde18fd9458..a7878c81493 100644
--- a/app/components/settings/project_custom_field_sections/show_component.html.erb
+++ b/app/components/settings/project_custom_field_sections/show_component.html.erb
@@ -1,5 +1,5 @@
<%=
- component_wrapper do
+ component_wrapper(class: "op-project-custom-field-section-container", data: { qa_selector: "project-custom-field-section-container-#{@project_custom_field_section.id}" }) do
render(Primer::Beta::BorderBox.new(mt: 3, data: drag_and_drop_target_config)) do |component|
component.with_header(font_weight: :bold) do
flex_layout(justify_content: :space_between, align_items: :center) do |section_header_container|
@@ -15,7 +15,7 @@
end
section_header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|
actions_container.with_column do
- render(Primer::Alpha::ActionMenu.new) do |menu|
+ render(Primer::Alpha::ActionMenu.new(data: { qa_selector: "project-custom-field-section-action-menu" })) do |menu|
menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_section_actions"), scheme: :invisible)
edit_action_item(menu)
move_actions(menu)
@@ -50,7 +50,7 @@
type: "ProjectCustomField", custom_field_section_id: @project_custom_field_section.id
),
scheme: :secondary,
- data: { turbo: "false"}
+ data: { turbo: "false", qa_selector: "new-project-custom-field-button" }
)) do |button|
button.with_leading_visual_icon(icon: :plus)
t('settings.project_attributes.label_new_attribute')
diff --git a/app/components/settings/project_custom_field_sections/show_component.rb b/app/components/settings/project_custom_field_sections/show_component.rb
index 573cf1d4c87..e9fc4eab56b 100644
--- a/app/components/settings/project_custom_field_sections/show_component.rb
+++ b/app/components/settings/project_custom_field_sections/show_component.rb
@@ -86,7 +86,7 @@ module Settings
menu.with_item(label: label_text,
href: move_admin_settings_project_custom_field_section_path(@project_custom_field_section, move_to:),
form_arguments: {
- method: :put, data: { 'turbo-stream': true }
+ method: :put, data: { 'turbo-stream': true, qa_selector: "project-custom-field-section-move-#{move_to}" }
}) do |item|
item.with_leading_visual_icon(icon:)
end
@@ -102,7 +102,10 @@ module Settings
def edit_action_item(menu)
menu.with_item(label: t("settings.project_attributes.label_edit_section"),
tag: :button,
- content_arguments: { 'data-show-dialog-id': "project-custom-field-section-dialog#{@project_custom_field_section.id}" },
+ content_arguments: {
+ 'data-show-dialog-id': "project-custom-field-section-dialog#{@project_custom_field_section.id}",
+ 'data-qa-selector': "project-custom-field-section-edit"
+ },
value: "") do |item|
item.with_leading_visual_icon(icon: :pencil)
end
@@ -113,7 +116,8 @@ module Settings
scheme: :danger,
href: admin_settings_project_custom_field_section_path(@project_custom_field_section),
form_arguments: {
- method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true }
+ method: :delete, data: { confirm: t("text_are_you_sure"), 'turbo-stream': true,
+ qa_selector: "project-custom-field-section-delete" }
}) do |item|
item.with_leading_visual_icon(icon: :trash)
end
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 e3727c36279..0b1d0169aa7 100644
--- a/app/components/settings/project_custom_fields/header_component.html.erb
+++ b/app/components/settings/project_custom_fields/header_component.html.erb
@@ -11,7 +11,7 @@
tag: :a,
href: new_admin_settings_project_custom_field_path(type: "ProjectCustomField"),
scheme: :primary,
- data: { turbo: "false"}
+ data: { turbo: "false", qa_selector: "new-project-custom-field-button" }
)) do |button|
button.with_leading_visual_icon(icon: :plus)
t('settings.project_attributes.label_new_attribute')
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index eff4a190e16..e5b12f7f5d7 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -74,7 +74,7 @@ module Admin::Settings
# needs refactoring via update service
@custom_field.move_to = params[:move_to]&.to_sym
- update_sections_via_turbo_stream(project_custom_field_sections: @custom_field_sections)
+ update_sections_via_turbo_stream(project_custom_field_sections: @project_custom_field_sections)
respond_with_turbo_streams
end
diff --git a/app/views/admin/settings/project_custom_fields/new.html.erb b/app/views/admin/settings/project_custom_fields/new.html.erb
index 781470cc8a9..143135f47ec 100644
--- a/app/views/admin/settings/project_custom_fields/new.html.erb
+++ b/app/views/admin/settings/project_custom_fields/new.html.erb
@@ -31,6 +31,8 @@ See COPYRIGHT and LICENSE files for more details.
'admin--custom-fields-format-value': @custom_field.field_format
%>
+<% local_assigns[:additional_breadcrumb] = t('settings.project_attributes.new.heading') %>
+
<%= render(Settings::ProjectCustomFields::NewFormHeaderComponent.new) %>
<%= error_messages_for 'custom_field' %>
diff --git a/spec/features/admin/project_custom_fields/create_spec.rb b/spec/features/admin/project_custom_fields/create_spec.rb
new file mode 100644
index 00000000000..c5c03bc3ee9
--- /dev/null
+++ b/spec/features/admin/project_custom_fields/create_spec.rb
@@ -0,0 +1,106 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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.
+#++
+
+require 'spec_helper'
+require_relative 'shared_context'
+
+RSpec.describe 'Create project custom fields', :js do
+ include_context 'with seeded project custom fields'
+
+ context 'with unsufficient permissions' do
+ it 'is not accessible' do
+ login_as(non_admin)
+ visit new_admin_settings_project_custom_field_path
+
+ expect(page).to have_text('You are not authorized to access this page.')
+ end
+ end
+
+ context 'with sufficient permissions' do
+ before do
+ login_as(admin)
+ visit new_admin_settings_project_custom_field_path
+ end
+
+ it 'shows a correct breadcrumb menu' do
+ within '#breadcrumb' do
+ expect(page).to have_link("Administration")
+ expect(page).to have_link('Project attributes')
+ expect(page).to have_text('New attribute')
+ end
+ end
+
+ it 'allows to create a new project custom field with an associated section' do
+ # TODO: reuse specs for classic custom field form in order to test for other attribute settings
+ expect(page).to have_css('.PageHeader-title', text: 'New attribute')
+
+ fill_in('custom_field_name', with: 'New custom field')
+ select(section_for_select_fields.name, from: 'custom_field_custom_field_section_id')
+
+ click_on('Save')
+
+ # redirects to the overview page
+ # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect
+ expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: 'ProjectCustomField'))
+
+ expect(page).to have_text('New custom field')
+
+ latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last
+
+ expect(latest_custom_field.name).to eq('New custom field')
+ expect(latest_custom_field.project_custom_field_section).to eq(section_for_select_fields)
+ end
+
+ it 'allows to create a new project custom field with a prefilled section via url param' do
+ visit new_admin_settings_project_custom_field_path(custom_field_section_id: section_for_multi_select_fields.id)
+
+ fill_in('custom_field_name', with: 'New custom field')
+
+ click_on('Save')
+
+ # redirects to the overview page
+ # the tab parameter is set as the redirect originates from the former custom field controller but does not have an effect
+ expect(page).to have_current_path(admin_settings_project_custom_fields_path(tab: 'ProjectCustomField'))
+
+ latest_custom_field = ProjectCustomField.reorder(created_at: :asc).last
+
+ expect(latest_custom_field.name).to eq('New custom field')
+ expect(latest_custom_field.project_custom_field_section).to eq(section_for_multi_select_fields)
+ end
+
+ it 'prevents creating a new project custom field with an empty name' do
+ click_on('Save')
+
+ # no server side validation shown, html5 validation is used
+
+ # expect no redirect
+ expect(page).to have_no_current_path(admin_settings_project_custom_fields_path(tab: 'ProjectCustomField'))
+ expect(page).to have_current_path(new_admin_settings_project_custom_field_path)
+ end
+ end
+end
diff --git a/spec/features/admin/project_custom_fields/edit_spec.rb b/spec/features/admin/project_custom_fields/edit_spec.rb
new file mode 100644
index 00000000000..b197fbdcef4
--- /dev/null
+++ b/spec/features/admin/project_custom_fields/edit_spec.rb
@@ -0,0 +1,95 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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.
+#++
+
+require 'spec_helper'
+require_relative 'shared_context'
+
+RSpec.describe 'Edit project custom fields', :js do
+ include_context 'with seeded project custom fields'
+
+ context 'with unsufficient permissions' do
+ it 'is not accessible' do
+ login_as(non_admin)
+ visit edit_admin_settings_project_custom_field_path(boolean_project_custom_field)
+
+ expect(page).to have_text('You are not authorized to access this page.')
+ end
+ end
+
+ context 'with sufficient permissions' do
+ before do
+ login_as(admin)
+ visit edit_admin_settings_project_custom_field_path(boolean_project_custom_field)
+ end
+
+ it 'shows a correct breadcrumb menu' do
+ within '#breadcrumb' do
+ expect(page).to have_link("Administration")
+ expect(page).to have_link('Project attributes')
+ expect(page).to have_text(boolean_project_custom_field.name)
+ end
+ end
+
+ it 'allows to change basic attributes and the section of the project custom field' do
+ # TODO: reuse specs for classic custom field form in order to test for other attribute manipulations
+ expect(page).to have_css('.PageHeader-title', text: boolean_project_custom_field.name)
+
+ fill_in('custom_field_name', with: 'Updated name')
+ select(section_for_select_fields.name, from: 'custom_field_custom_field_section_id')
+
+ click_on('Save')
+
+ expect(page).to have_text('Successful update')
+
+ expect(page).to have_css('.PageHeader-title', text: 'Updated name')
+
+ expect(boolean_project_custom_field.reload.name).to eq("Updated name")
+ expect(boolean_project_custom_field.reload.project_custom_field_section).to eq(section_for_select_fields)
+
+ within '#breadcrumb' do
+ expect(page).to have_link("Administration")
+ expect(page).to have_link('Project attributes')
+ expect(page).to have_text('Updated name')
+ end
+ end
+
+ it 'prevents saving a project custom field with an empty name' do
+ original_name = boolean_project_custom_field.name
+
+ fill_in('custom_field_name', with: '')
+ click_on('Save')
+
+ # no server side validation shown, html5 validation is used
+
+ expect(page).to have_no_text('Successful update')
+
+ expect(page).to have_css('.PageHeader-title', text: original_name)
+ expect(boolean_project_custom_field.reload.name).to eq(original_name)
+ end
+ end
+end
diff --git a/spec/features/admin/project_custom_fields/list_spec.rb b/spec/features/admin/project_custom_fields/list_spec.rb
new file mode 100644
index 00000000000..b01692b6606
--- /dev/null
+++ b/spec/features/admin/project_custom_fields/list_spec.rb
@@ -0,0 +1,276 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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.
+#++
+
+require 'spec_helper'
+require_relative 'shared_context'
+
+RSpec.describe 'List project custom fields', :js do
+ include_context 'with seeded project custom fields'
+
+ context 'with unsufficient permissions' do
+ it 'is not accessible' do
+ login_as(non_admin)
+ visit admin_settings_project_custom_fields_path
+
+ expect(page).to have_text('You are not authorized to access this page.')
+ end
+ end
+
+ context 'with sufficient permissions' do
+ before do
+ login_as(admin)
+ visit admin_settings_project_custom_fields_path
+ end
+
+ it 'shows all sections in the correct order and allows reordering via menu or drag and drop' do
+ containers = page.all('.op-project-custom-field-section-container')
+
+ expect(containers[0].text).to include(section_for_input_fields.name)
+ expect(containers[1].text).to include(section_for_select_fields.name)
+ expect(containers[2].text).to include(section_for_multi_select_fields.name)
+
+ perform_action_for_project_custom_field_section(section_for_multi_select_fields, "Move up")
+
+ visit admin_settings_project_custom_fields_path
+
+ containers = page.all('.op-project-custom-field-section-container')
+
+ expect(containers[0].text).to include(section_for_input_fields.name)
+ expect(containers[1].text).to include(section_for_multi_select_fields.name)
+ expect(containers[2].text).to include(section_for_select_fields.name)
+
+ # TODO: Add drag and drop test
+ end
+
+ it 'allows to delete a section only if no project custom fields are assigned to it' do
+ within_project_custom_field_section_menu(section_for_multi_select_fields) do
+ expect(page).to have_css("button[aria-disabled='true']", text: 'Delete')
+ end
+
+ multi_list_project_custom_field.destroy
+ multi_user_project_custom_field.destroy
+ multi_version_project_custom_field.destroy
+
+ visit admin_settings_project_custom_fields_path
+
+ within_project_custom_field_section_menu(section_for_multi_select_fields) do
+ expect(page).to have_no_css("button[aria-disabled='true']", text: 'Delete')
+ expect(page).to have_button('Delete')
+
+ accept_confirm do
+ click_on('Delete')
+ end
+ end
+
+ expect(page).to have_no_css("[data-qa-selector='project-custom-field-section-container-#{section_for_multi_select_fields.id}']")
+ end
+
+ it 'allows to edit a section' do
+ within_project_custom_field_section_menu(section_for_input_fields) do
+ click_on('Edit title')
+ end
+
+ fill_in('project_custom_field_section_name', with: 'Updated section name')
+
+ click_on('Save')
+
+ expect(page).to have_no_text(section_for_input_fields.name)
+ expect(page).to have_text('Updated section name')
+ end
+
+ it 'allows to create a new section' do
+ within '#settings-project-custom-fields-header-component' do
+ click_on('dialog-show-project-custom-field-section-dialog')
+ end
+
+ fill_in('project_custom_field_section_name', with: 'New section name')
+
+ click_on('Save')
+
+ expect(page).to have_text('New section name')
+
+ containers = page.all('.op-project-custom-field-section-container')
+
+ expect(containers[0].text).to include('New section name')
+ expect(containers[1].text).to include(section_for_input_fields.name)
+ expect(containers[2].text).to include(section_for_select_fields.name)
+ expect(containers[3].text).to include(section_for_multi_select_fields.name)
+ end
+
+ describe 'managing project custom fields' do
+ it 'shows all custom fields in the correct order within their section and allows reordering via menu or drag and drop' do
+ within_project_custom_field_section_container(section_for_input_fields) do
+ containers = page.all('.op-project-custom-field-container')
+
+ expect(containers[0].text).to include(boolean_project_custom_field.name)
+ expect(containers[1].text).to include(string_project_custom_field.name)
+ expect(containers[2].text).to include(integer_project_custom_field.name)
+ expect(containers[3].text).to include(float_project_custom_field.name)
+ expect(containers[4].text).to include(date_project_custom_field.name)
+ expect(containers[5].text).to include(text_project_custom_field.name)
+ end
+
+ within_project_custom_field_section_container(section_for_select_fields) do
+ containers = page.all('.op-project-custom-field-container')
+
+ expect(containers[0].text).to include(list_project_custom_field.name)
+ expect(containers[1].text).to include(version_project_custom_field.name)
+ expect(containers[2].text).to include(user_project_custom_field.name)
+ end
+
+ within_project_custom_field_section_container(section_for_multi_select_fields) do
+ containers = page.all('.op-project-custom-field-container')
+
+ expect(containers[0].text).to include(multi_list_project_custom_field.name)
+ expect(containers[1].text).to include(multi_version_project_custom_field.name)
+ expect(containers[2].text).to include(multi_user_project_custom_field.name)
+ end
+
+ perform_action_for_project_custom_field(multi_user_project_custom_field, "Move up")
+
+ visit admin_settings_project_custom_fields_path
+
+ within_project_custom_field_section_container(section_for_multi_select_fields) do
+ containers = page.all('.op-project-custom-field-container')
+
+ expect(containers[0].text).to include(multi_list_project_custom_field.name)
+ expect(containers[1].text).to include(multi_user_project_custom_field.name)
+ expect(containers[2].text).to include(multi_version_project_custom_field.name)
+ end
+
+ # TODO: Add drag and drop test
+ end
+
+ it 'shows the number of projects using a custom field' do
+ within_project_custom_field_container(boolean_project_custom_field) do
+ expect(page).to have_text('0 Projects')
+ end
+
+ project = create(:project)
+ project.project_custom_fields << boolean_project_custom_field
+
+ visit admin_settings_project_custom_fields_path
+
+ within_project_custom_field_container(boolean_project_custom_field) do
+ expect(page).to have_text('1 Project')
+ end
+ end
+
+ it 'allows to delete a custom field' do
+ within_project_custom_field_menu(boolean_project_custom_field) do
+ accept_confirm do
+ click_on('Delete')
+ end
+ end
+
+ expect(page).to have_no_css("[data-qa-selector='project-custom-field-container-#{boolean_project_custom_field.id}']")
+ end
+
+ it 'redirects to the custom field edit page via menu item' do
+ within_project_custom_field_menu(boolean_project_custom_field) do
+ click_on('Edit')
+ end
+
+ expect(page).to have_current_path(edit_admin_settings_project_custom_field_path(boolean_project_custom_field))
+ end
+
+ it 'redirects to the custom field edit page via click on the name of the custom field' do
+ within_project_custom_field_container(boolean_project_custom_field) do
+ click_on(boolean_project_custom_field.name)
+ end
+
+ expect(page).to have_current_path(edit_admin_settings_project_custom_field_path(boolean_project_custom_field))
+ end
+
+ it 'redirects to the custom field new page via header menu button' do
+ page.find("[data-qa-selector='new-project-custom-field-button']").click
+
+ expect(page).to have_current_path(new_admin_settings_project_custom_field_path(type: 'ProjectCustomField'))
+ end
+
+ it 'redirects to the custom field new page via button in empty sections' do
+ within_project_custom_field_section_container(section_for_multi_select_fields) do
+ expect(page).to have_no_css("[data-qa-selector='new-project-custom-field-button']")
+ end
+
+ multi_list_project_custom_field.destroy
+ multi_user_project_custom_field.destroy
+ multi_version_project_custom_field.destroy
+
+ visit admin_settings_project_custom_fields_path
+
+ within_project_custom_field_section_container(section_for_multi_select_fields) do
+ page.find("[data-qa-selector='new-project-custom-field-button']").click
+ end
+
+ expect(page).to have_current_path(new_admin_settings_project_custom_field_path(
+ type: 'ProjectCustomField',
+ custom_field_section_id: section_for_multi_select_fields.id
+ ))
+ end
+ end
+ end
+
+ # helper methods:
+
+ def within_project_custom_field_section_container(section, &block)
+ within("[data-qa-selector='project-custom-field-section-container-#{section.id}']", &block)
+ end
+
+ def within_project_custom_field_section_menu(section, &block)
+ within_project_custom_field_section_container(section) do
+ page.find("[data-qa-selector='project-custom-field-section-action-menu']").click
+ within('anchored-position', &block)
+ end
+ end
+
+ def perform_action_for_project_custom_field_section(section, action)
+ within_project_custom_field_section_menu(section) do
+ click_on(action)
+ end
+ sleep 0.5 # quick fix: allow the brower to process the action
+ end
+
+ def within_project_custom_field_container(custom_field, &block)
+ within("[data-qa-selector='project-custom-field-container-#{custom_field.id}']", &block)
+ end
+
+ def within_project_custom_field_menu(section, &block)
+ within_project_custom_field_container(section) do
+ page.find("[data-qa-selector='project-custom-field-action-menu']").click
+ within('anchored-position', &block)
+ end
+ end
+
+ def perform_action_for_project_custom_field(custom_field, action)
+ within_project_custom_field_menu(custom_field) do
+ click_on(action)
+ end
+ sleep 0.5 # quick fix: allow the brower to process the action
+ end
+end
diff --git a/spec/features/admin/project_custom_fields/shared_context.rb b/spec/features/admin/project_custom_fields/shared_context.rb
new file mode 100644
index 00000000000..ee6b3faf084
--- /dev/null
+++ b/spec/features/admin/project_custom_fields/shared_context.rb
@@ -0,0 +1,128 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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.
+#++
+
+RSpec.shared_context 'with seeded project custom fields' do
+ shared_let(:admin) { create(:admin) }
+ shared_let(:non_admin) { create(:user) }
+
+ shared_let(:section_for_input_fields) { create(:project_custom_field_section, name: 'Input fields') }
+ shared_let(:section_for_select_fields) { create(:project_custom_field_section, name: 'Select fields') }
+ shared_let(:section_for_multi_select_fields) { create(:project_custom_field_section, name: 'Multi select fields') }
+
+ let!(:boolean_project_custom_field) do
+ create(:boolean_project_custom_field, name: 'Boolean field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:string_project_custom_field) do
+ create(:string_project_custom_field, name: 'String field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:integer_project_custom_field) do
+ create(:integer_project_custom_field, name: 'Integer field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:float_project_custom_field) do
+ create(:float_project_custom_field, name: 'Float field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:date_project_custom_field) do
+ create(:date_project_custom_field, name: 'Date field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:text_project_custom_field) do
+ create(:text_project_custom_field, name: 'Text field',
+ project_custom_field_section: section_for_input_fields)
+ end
+
+ let!(:list_project_custom_field) do
+ create(:list_project_custom_field, name: 'List field',
+ project_custom_field_section: section_for_select_fields,
+ possible_values: ['Option 1', 'Option 2', 'Option 3'])
+ end
+
+ let!(:version_project_custom_field) do
+ create(:version_project_custom_field, name: 'Version field',
+ project_custom_field_section: section_for_select_fields)
+ end
+
+ let!(:user_project_custom_field) do
+ create(:user_project_custom_field, name: 'User field',
+ project_custom_field_section: section_for_select_fields)
+ end
+
+ let!(:multi_list_project_custom_field) do
+ create(:list_project_custom_field, name: 'Multi list field',
+ project_custom_field_section: section_for_multi_select_fields,
+ possible_values: ['Option 1', 'Option 2', 'Option 3'],
+ multi_value: true)
+ end
+
+ let!(:multi_version_project_custom_field) do
+ create(:version_project_custom_field, name: 'Multi version field',
+ project_custom_field_section: section_for_multi_select_fields,
+ multi_value: true)
+ end
+
+ let!(:multi_user_project_custom_field) do
+ create(:user_project_custom_field, name: 'Multi user field',
+ project_custom_field_section: section_for_multi_select_fields,
+ multi_value: true)
+ end
+
+ let!(:input_fields) do
+ [
+ boolean_project_custom_field,
+ string_project_custom_field,
+ integer_project_custom_field,
+ float_project_custom_field,
+ date_project_custom_field,
+ text_project_custom_field
+ ]
+ end
+
+ let!(:select_fields) do
+ [
+ list_project_custom_field,
+ version_project_custom_field,
+ user_project_custom_field
+ ]
+ end
+
+ let!(:multi_select_fields) do
+ [
+ multi_list_project_custom_field,
+ multi_version_project_custom_field,
+ multi_user_project_custom_field
+ ]
+ end
+end