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

[#53722] Specs for conditional pcf creation

Tobias Dillmann57d36225f4d0
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 66f06124012..0358afd3eed 100644
--- a/app/components/settings/project_custom_fields/header_component.html.erb
+++ b/app/components/settings/project_custom_fields/header_component.html.erb
@@ -25,11 +25,14 @@
id: "dialog-show-project-custom-field-section-dialog",
tag: :a,
href: new_link_admin_settings_project_custom_field_sections_path,
- content_arguments: { data: { controller: "async-dialog" } }
+ content_arguments: { data: { controller: "async-dialog", test_selector: "add-project-custom-field-section" } }
)
if allow_custom_field_creation?
- menu.with_sub_menu_item(label: t("settings.project_attributes.label_new_attribute")) do |sub_menu|
+ menu.with_sub_menu_item(
+ label: t("settings.project_attributes.label_new_attribute"),
+ content_arguments: { data: { test_selector: "add-project-custom-field-attribute" } }
+ ) do |sub_menu|
OpenProject::CustomFieldFormat.available_for_class_name("Project")
.sort_by(&:name)
.map do |format|
diff --git a/spec/features/admin/custom_fields/projects/index_spec.rb b/spec/features/admin/custom_fields/projects/index_spec.rb
index 556cba513f3..e472296ce48 100644
--- a/spec/features/admin/custom_fields/projects/index_spec.rb
+++ b/spec/features/admin/custom_fields/projects/index_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe "List project custom fields", :js do
let(:cf_index_page) { Pages::Admin::CustomFields::CustomFieldsProjects::Index.new }
- context "with unsufficient permissions" do
+ context "with insufficient permissions" do
it "is not accessible" do
login_as(non_admin)
cf_index_page.visit!
@@ -51,6 +51,34 @@ RSpec.describe "List project custom fields", :js do
cf_index_page.visit!
end
+ it "only allows project attribute creation when there is at least one section" do
+ # All sections are there, so we can add project attributes
+ cf_index_page.expect_add_project_attribute_submenu
+
+ section_for_input_fields.destroy
+ section_for_multi_select_fields.destroy
+ select_fields.each(&:destroy)
+
+ cf_index_page.visit!
+
+ # The (empty) select section is still there, so we can still add project attributes
+ cf_index_page.expect_add_project_attribute_submenu
+
+ within_project_custom_field_section_menu(section_for_select_fields) do
+ accept_confirm do
+ click_on("Delete")
+ end
+ end
+
+ # Now there are no sections left, so we cannot add project attributes:
+ # Turbo stream updated the component properly:
+ cf_index_page.expect_no_add_project_attribute_submenu(close_dialog: false)
+
+ # Revisiting the page again should not change anything:
+ cf_index_page.visit!
+ cf_index_page.expect_no_add_project_attribute_submenu(close_dialog: false)
+ 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")
@@ -253,7 +281,7 @@ RSpec.describe "List project custom fields", :js do
within_project_custom_field_section_menu(section) do
click_on(action)
end
- sleep 0.5 # quick fix: allow the brower to process the action
+ sleep 0.5 # quick fix: allow the browser to process the action
end
def within_project_custom_field_container(custom_field, &)
@@ -271,6 +299,6 @@ RSpec.describe "List project custom fields", :js do
within_project_custom_field_menu(custom_field) do
click_on(action)
end
- sleep 0.5 # quick fix: allow the brower to process the action
+ sleep 0.5 # quick fix: allow the browser to process the action
end
end
diff --git a/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb b/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb
index 92e9e18b48e..a4e7edd8941 100644
--- a/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb
+++ b/spec/support/pages/admin/custom_fields/custom_fields_projects/index.rb
@@ -39,6 +39,32 @@ module Pages
"/admin/settings/project_custom_fields"
end
+ def expect_add_project_attribute_submenu(close_dialog: true)
+ wait_for_network_idle
+
+ click_button "Add"
+
+ expect(page).to have_test_selector("add-project-custom-field-attribute")
+
+ if close_dialog
+ element_in_dialog = find_test_selector("add-project-custom-field-section")
+ element_in_dialog.send_keys :escape
+ end
+ end
+
+ def expect_no_add_project_attribute_submenu(close_dialog: true)
+ wait_for_network_idle
+
+ click_button "Add"
+
+ expect(page).not_to have_test_selector("add-project-custom-field-attribute")
+
+ if close_dialog
+ element_in_dialog = find_test_selector("add-project-custom-field-section")
+ element_in_dialog.send_keys :escape
+ end
+ end
+
def click_to_create_new_custom_field(type)
wait_for_network_idle