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 the test-selectors disappearing from the forms.

Marcello Rochac60feee93958
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
index 680363dffee..7b60fdf7659 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- primer_form_with(**item_options, test_selector: "op-custom-fields--new-item-form") do |f|
+ primer_form_with(**item_options) do |f|
render(CustomFields::Hierarchy::ItemForm.new(f, target_item: model))
end
%>
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.rb b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
index 49db3f4deb5..ac05baac0d6 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
@@ -35,8 +35,8 @@ module Admin
include OpTurbo::Streamable
def item_options
- options = { url:, method: http_verb }
- options[:data] = { turbo_frame: ItemsComponent.wrapper_key } if model.new_record?
+ options = { url:, method: http_verb, data: { test_selector: "op-custom-fields--new-item-form" } }
+ options[:data][:turbo_frame] = ItemsComponent.wrapper_key if model.new_record?
options
end
diff --git a/app/components/admin/custom_fields/hierarchy/items_component.rb b/app/components/admin/custom_fields/hierarchy/items_component.rb
index 1b519236754..9c83089684a 100644
--- a/app/components/admin/custom_fields/hierarchy/items_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/items_component.rb
@@ -45,7 +45,7 @@ module Admin
end
def new_item_path
- position = model.children.any? ? children.last.sort_order + 1 : 0
+ position = model.children.any? ? model.children.last.sort_order + 1 : 0
new_child_custom_field_item_path(root.custom_field_id, model, position:)
end
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index b5b5a70d30f..78e9b51ed4b 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -67,7 +67,8 @@ module Admin
.either(
lambda do |item|
redirect_to(
- new_child_custom_field_item_path(@custom_field, @active_item, position: item.sort_order + 1)
+ new_child_custom_field_item_path(@custom_field, @active_item, position: item.sort_order + 1),
+ status: :see_other
)
end,
lambda do |validation_result|
@@ -82,7 +83,7 @@ module Admin
.update_item(item: @active_item, label: item_input[:label], short: item_input[:short])
.either(
lambda do |_|
- redirect_to(custom_field_item_path(@custom_field, @active_item.parent))
+ redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other)
end,
lambda do |validation_result|
add_errors_to_edit_form(validation_result)
diff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
index 92dcb83106b..09fccae93c8 100644
--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb
@@ -44,7 +44,7 @@ module CustomFields
.bind { |validation| create_root_item(validation[:custom_field]) }
end
- # Insert a new node on the hierarchy tree.
+ # Insert a new node on the hierarchy tree at a desired position or at the end if no sort_order is passed.
# @param parent [CustomField::Hierarchy::Item] the parent of the node
# @param label [String] the node label/name that must be unique at the same tree level
# @param short [String] an alias for the node
diff --git a/spec/features/custom_fields/hierarchy_custom_field_spec.rb b/spec/features/custom_fields/hierarchy_custom_field_spec.rb
index fe961ae75a2..d7632338978 100644
--- a/spec/features/custom_fields/hierarchy_custom_field_spec.rb
+++ b/spec/features/custom_fields/hierarchy_custom_field_spec.rb
@@ -85,7 +85,7 @@ RSpec.describe "custom fields of type hierarchy", :js, :with_cuprite do
hierarchy_page.expect_current_path
expect(page).to have_test_selector("op-custom-fields--hierarchy-items-blankslate")
- click_on "Item"
+ within("sub-header") { click_on "Item" }
expect(page).not_to have_test_selector("op-custom-fields--hierarchy-items-blankslate")
fill_in "Label", with: "Stormtroopers"
fill_in "Short", with: "ST"