Skip to content

Commit

Permalink
Do not focus custom fields in the create child dialog
Browse files Browse the repository at this point in the history
The field to focus is the subject field.

Also test that all custom fields are displayed in the create
child dialog.
  • Loading branch information
cbliard committed Jan 16, 2025
1 parent c436989 commit a836184
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/forms/custom_fields/custom_field_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def single_value_custom_field_input(builder, custom_field)
CustomFields::Inputs::Int.new(builder, **form_args)
when "float"
CustomFields::Inputs::Float.new(builder, **form_args)
when "hierarchy"
CustomFields::Inputs::SingleSelectList.new(builder, **form_args)
when "list"
when "hierarchy", "list"
CustomFields::Inputs::SingleSelectList.new(builder, **form_args)
when "date"
CustomFields::Inputs::Date.new(builder, **form_args)
Expand All @@ -103,9 +101,7 @@ def multi_value_custom_field_input(builder, custom_field)
form_args = form_arguments(custom_field)

case custom_field.field_format
when "hierarchy"
CustomFields::Inputs::MultiSelectList.new(builder, **form_args)
when "list"
when "hierarchy", "list"
CustomFields::Inputs::MultiSelectList.new(builder, **form_args)
when "user"
CustomFields::Inputs::MultiUserSelectList.new(builder, **form_args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def autocomplete_options
{
multiple: true,
decorated: decorated?,
focusDirectly: false,
append_to:
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def autocomplete_options
{
multiple: false,
decorated: decorated?,
focusDirectly: false,
append_to:
}
end
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/custom_field_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@

trait :hierarchy do
field_format { "hierarchy" }
hierarchy_root factory: :hierarchy_item
end

trait :multi_hierarchy do
hierarchy
multi_value
end

factory :project_custom_field, class: "ProjectCustomField" do
Expand Down
44 changes: 44 additions & 0 deletions spec/features/work_packages/tabs/relations_children_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,48 @@
relations_tab.expect_no_new_relation_type("New child")
end
end

context "when all possible custom fields are there" do
let!(:user) { create(:admin) }

before do
# Introspect FactoryBot to find all traits used to create work package custom fields
traits = FactoryBot.factories[:wp_custom_field].defined_traits
traits = traits.reject { |t| t.name == "multi_value" }
traits = traits.map { |t| t.name.to_sym }

traits.each do |trait|
[true, false].each do |required| # rubocop:disable Performance/CollectionLiteralInLoop
cf = create(:wp_custom_field,
trait,
is_required: required)
project.types.first.custom_fields << cf
project.work_package_custom_fields << cf
end
end
end

it "displays a field for each required custom field" do
wp_page.visit_tab!("relations")
relations_tab.select_relation_type "New child"

project.work_package_custom_fields.each do |cf|
create_dialog.in_dialog do
if cf.required?
# `visible: :all` is needed as text custom field use a hidden textarea internally
expect(page).to have_field cf.name, visible: :all
else
expect(page).to have_no_field cf.name
end
end
end
end

it "focuses the subject input field" do
wp_page.visit_tab!("relations")
relations_tab.select_relation_type "New child"

create_dialog.expect_subject_field_focused
end
end
end
8 changes: 8 additions & 0 deletions spec/support/components/work_packages/create_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def expect_subject(value)
end
end

def expect_subject_field_focused
in_dialog do
subject_field = page.find_field("Subject")
subject_field_id_selector = "##{subject_field[:id]}"
expect(page).to have_focus_on(subject_field_id_selector)
end
end

def set_description(value)
@description.set_markdown(value)
end
Expand Down

0 comments on commit a836184

Please sign in to comment.