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 edit dialog, refactored form input implementation, fixed minor bugs

Jonas Jabaricca82ec32d20
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 2aa2e7109ae..ef07583c930 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -236,6 +236,7 @@ class CustomField < ApplicationRecord
def attribute_name(format = nil)
return "customField#{id}" if format == :camel_case
+ return "custom-field-#{id}" if format == :kebab_case
"custom_field_#{id}"
end
diff --git a/lib/primer/open_project/forms/autocompleter.html.erb b/lib/primer/open_project/forms/autocompleter.html.erb
index bcd50431ed4..3464bd8a99f 100644
--- a/lib/primer/open_project/forms/autocompleter.html.erb
+++ b/lib/primer/open_project/forms/autocompleter.html.erb
@@ -1,4 +1,4 @@
-<%= render(FormControl.new(input: @input)) do %>
+<%= render(FormControl.new(input: @input, data: @wrapper_data_attributes)) do %>
<% if decorated_select? %>
<%= render partial: '/augmented/autocomplete_select_decoration',
locals: {
diff --git a/lib/primer/open_project/forms/autocompleter.rb b/lib/primer/open_project/forms/autocompleter.rb
index 51aedf8b157..3767fd2b071 100644
--- a/lib/primer/open_project/forms/autocompleter.rb
+++ b/lib/primer/open_project/forms/autocompleter.rb
@@ -9,10 +9,11 @@ module Primer
delegate :builder, :form, :select_options, to: :@input
- def initialize(input:, autocomplete_options:)
+ def initialize(input:, autocomplete_options:, wrapper_data_attributes: {})
super()
@input = input
@autocomplete_options = autocomplete_options
+ @wrapper_data_attributes = wrapper_data_attributes
end
def decorated_select?
diff --git a/lib/primer/open_project/forms/dsl/autocompleter_input.rb b/lib/primer/open_project/forms/dsl/autocompleter_input.rb
index 706037c1942..ea435554780 100644
--- a/lib/primer/open_project/forms/dsl/autocompleter_input.rb
+++ b/lib/primer/open_project/forms/dsl/autocompleter_input.rb
@@ -5,7 +5,7 @@ module Primer
module Forms
module Dsl
class AutocompleterInput < Primer::Forms::Dsl::Input
- attr_reader :name, :label, :autocomplete_options, :select_options
+ attr_reader :name, :label, :autocomplete_options, :select_options, :wrapper_data_attributes
class Option
attr_reader :label, :value, :selected
@@ -25,10 +25,11 @@ module Primer
end
end
- def initialize(name:, label:, autocomplete_options:, **system_arguments)
+ def initialize(name:, label:, autocomplete_options:, wrapper_data_attributes: {}, **system_arguments)
@name = name
@label = label
@autocomplete_options = autocomplete_options
+ @wrapper_data_attributes = wrapper_data_attributes
@select_options = []
super(**system_arguments)
@@ -41,7 +42,7 @@ module Primer
end
def to_component
- Autocompleter.new(input: self, autocomplete_options:)
+ Autocompleter.new(input: self, autocomplete_options:, wrapper_data_attributes:)
end
def type
diff --git a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb
index a2e06e95b84..14ba839a647 100644
--- a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb
+++ b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb
@@ -1,7 +1,7 @@
<%=
content_tag("turbo-frame", id: "edit-project-attributes-dialog-#{@project_custom_field_section.id}-frame") do
- component_wrapper do
+ component_wrapper(data: { qa_selector: 'async-dialog-content' }) do
primer_form_with(
model: @project,
method: :put,
diff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb
index 44012a99acb..92fa94b6168 100644
--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb
+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb
@@ -14,7 +14,7 @@
id: "edit-project-attributes-dialog-#{@project_custom_field_section.id}",
src: project_attribute_section_dialog_path(project_id: @project.id, section_id: @project_custom_field_section.id),
size: :medium_portrait,
- title: "#{t('label_edit')} #{ @project_custom_field_section.name }",
+ title: @project_custom_field_section.name,
button_icon: :pencil,
button_attributes: { scheme: :invisible, data: {
qa_selector: "project-custom-field-section-edit-button"
diff --git a/spec/features/projects/project_custom_fields/overview_page/overview_page.rb b/modules/overviews/app/forms/project/custom_value_form/base/autocomplete/multi_value_input.rb
similarity index 51%
rename from spec/features/projects/project_custom_fields/overview_page/overview_page.rb
rename to modules/overviews/app/forms/project/custom_value_form/base/autocomplete/multi_value_input.rb
index 85b3aa23f8c..05caa715f6d 100644
--- a/spec/features/projects/project_custom_fields/overview_page/overview_page.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/base/autocomplete/multi_value_input.rb
@@ -25,50 +25,53 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
-class OverviewPage
- include Rails.application.routes.url_helpers
- include Capybara::DSL
- include Capybara::RSpecMatchers
- include RSpec::Matchers
- def initialize(project)
+class Project::CustomValueForm::Base::Autocomplete::MultiValueInput < Project::CustomValueForm::Base::Input
+ def initialize(custom_field:, custom_field_values:, project:)
+ @custom_field = custom_field
+ @custom_field_values = custom_field_values
@project = project
end
- def visit_page
- visit project_path(@project.id)
+ def base_config
+ super.merge(
+ {
+ autocomplete_options:
+ },
+ invalid: invalid?,
+ validation_message:,
+ wrapper_data_attributes: {
+ 'qa-field-name': qa_field_name
+ }
+ )
end
- def within_async_loaded_sidebar
- within '#project-attributes-sidebar' do
- expect(page).to have_css("[data-qa-selector='project-attributes-sidebar-async-content']")
- yield
- end
+ def autocomplete_options
+ {
+ multiple: true,
+ decorated:,
+ inputId: id,
+ inputName: name
+ }
end
- def within_custom_field_section_container(section, &)
- within("[data-qa-selector='project-custom-field-section-#{section.id}']", &)
+ def decorated
+ raise NotImplementedError
end
- def within_custom_field_container(custom_field, &)
- within("[data-qa-selector='project-custom-field-#{custom_field.id}']", &)
+ def name
+ "project[multi_custom_field_values_attributes][#{@custom_field.id}][values]"
end
- def open_edit_dialog_for_section(section)
- within_async_loaded_sidebar do
- within_custom_field_section_container(section) do
- page.find("[data-qa-selector='project-custom-field-section-edit-button']").click
- end
- end
+ def value
+ nil
end
- def close_edit_dialog_for_section(section)
- within("modal-dialog#edit-project-attributes-dialog-#{section.id}") do
- page.find(".close-button").click
- end
+ def invalid?
+ @custom_field_values.any? { |custom_field_value| custom_field_value.errors.any? }
end
- def within_edit_dialog_for_section(section, &)
- within("modal-dialog#edit-project-attributes-dialog-#{section.id}", &)
+ def validation_message
+ @custom_field_values.map { |custom_field_value| custom_field_value.errors.full_messages }.join(', ') if invalid?
end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/base/autocomplete/single_value_input.rb b/modules/overviews/app/forms/project/custom_value_form/base/autocomplete/single_value_input.rb
new file mode 100644
index 00000000000..2e1d1ed887f
--- /dev/null
+++ b/modules/overviews/app/forms/project/custom_value_form/base/autocomplete/single_value_input.rb
@@ -0,0 +1,67 @@
+#-- 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.
+#++
+
+class Project::CustomValueForm::Base::Autocomplete::SingleValueInput < Project::CustomValueForm::Base::Input
+ def base_config
+ super.merge(
+ {
+ autocomplete_options:
+ },
+ invalid: invalid?,
+ validation_message:,
+ wrapper_data_attributes: {
+ 'qa-field-name': qa_field_name
+ }
+ )
+ end
+
+ def autocomplete_options
+ {
+ multiple: false,
+ decorated:,
+ inputId: id,
+ inputName: name
+ }
+ end
+
+ def decorated
+ raise NotImplementedError
+ end
+
+ def value
+ nil
+ end
+
+ def invalid?
+ @custom_field_value.errors.any?
+ end
+
+ def validation_message
+ @custom_field_value.errors.full_messages.join(', ') if invalid?
+ end
+end
diff --git a/modules/overviews/app/forms/project/custom_value_form/base.rb b/modules/overviews/app/forms/project/custom_value_form/base/input.rb
similarity index 86%
rename from modules/overviews/app/forms/project/custom_value_form/base.rb
rename to modules/overviews/app/forms/project/custom_value_form/base/input.rb
index f01ba20e571..eb6cf8e4646 100644
--- a/modules/overviews/app/forms/project/custom_value_form/base.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/base/input.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Base < ApplicationForm
+class Project::CustomValueForm::Base::Input < ApplicationForm
def initialize(custom_field:, custom_field_value:, project:)
@custom_field = custom_field
@custom_field_value = custom_field_value
@@ -41,10 +41,11 @@ class Project::CustomValueForm::Base < ApplicationForm
scope_id_to_model: false,
placeholder: @custom_field.name,
label: @custom_field.name,
- value: @custom_field_value.value,
+ value:,
required: @custom_field.is_required?,
- invalid: @custom_field_value.errors.any?,
- validation_message: @custom_field_value.errors.any? ? @custom_field_value.errors.full_messages&.join(" ") : nil
+ data: {
+ 'qa-field-name': qa_field_name
+ }
}
end
@@ -59,4 +60,12 @@ class Project::CustomValueForm::Base < ApplicationForm
def id
name.gsub(/[\[\]]/, "_")
end
+
+ def value
+ @custom_field_value.value || @custom_field.default_value
+ end
+
+ def qa_field_name
+ @custom_field.attribute_name(:kebab_case)
+ end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/bool.rb b/modules/overviews/app/forms/project/custom_value_form/bool.rb
index 7be79995201..9b7087fd893 100644
--- a/modules/overviews/app/forms/project/custom_value_form/bool.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/bool.rb
@@ -26,16 +26,16 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Bool < Project::CustomValueForm::Base
+class Project::CustomValueForm::Bool < Project::CustomValueForm::Base::Input
form do |custom_value_form|
custom_value_form.check_box(**base_config)
end
def base_config
super.merge({
- value: "1",
- unchecked_value: "0",
- checked: @custom_field_value&.typed_value == true
- })
+ value: "1",
+ unchecked_value: "0",
+ checked: @custom_field_value&.typed_value == true || @custom_field.default_value == true
+ })
end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/date.rb b/modules/overviews/app/forms/project/custom_value_form/date.rb
index 15f40f2fa59..c0a925aa70c 100644
--- a/modules/overviews/app/forms/project/custom_value_form/date.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/date.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Date < Project::CustomValueForm::Base
+class Project::CustomValueForm::Date < Project::CustomValueForm::Base::Input
form do |custom_value_form|
custom_value_form.text_field(**base_config)
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/float.rb b/modules/overviews/app/forms/project/custom_value_form/float.rb
index f68e6e550b9..a4ddbf6a7f0 100644
--- a/modules/overviews/app/forms/project/custom_value_form/float.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/float.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Float < Project::CustomValueForm::Base
+class Project::CustomValueForm::Float < Project::CustomValueForm::Base::Input
form do |custom_value_form|
custom_value_form.text_field(**base_config)
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/int.rb b/modules/overviews/app/forms/project/custom_value_form/int.rb
index 903937c2981..0e336eb44df 100644
--- a/modules/overviews/app/forms/project/custom_value_form/int.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/int.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Int < Project::CustomValueForm::Base
+class Project::CustomValueForm::Int < Project::CustomValueForm::Base::Input
form do |custom_value_form|
custom_value_form.text_field(**base_config)
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/multi_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/multi_select_list.rb
index 70b75b19352..90efc15d259 100644
--- a/modules/overviews/app/forms/project/custom_value_form/multi_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/multi_select_list.rb
@@ -26,19 +26,13 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::MultiSelectList < Project::CustomValueForm::Base
- def initialize(custom_field:, custom_field_values:, project:)
- @custom_field = custom_field
- @custom_field_values = custom_field_values
- @project = project
- end
-
+class Project::CustomValueForm::MultiSelectList < Project::CustomValueForm::Base::Autocomplete::MultiValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config) do |list|
@custom_field.custom_options.each do |custom_option|
list.option(
label: custom_option.value, value: custom_option.id,
- selected: @custom_field_values.pluck(:value).map { |value| value&.to_i }.include?(custom_option.id)
+ selected: selected?(custom_option)
)
end
end
@@ -46,35 +40,17 @@ class Project::CustomValueForm::MultiSelectList < Project::CustomValueForm::Base
private
- def base_config
- {
- name:,
- scope_name_to_model: false,
- scope_id_to_model: false, # autocompleter does not respect scope_id_to_model = false
- placeholder: @custom_field.name,
- label: @custom_field.name,
- required: @custom_field.is_required?,
- include_blank: @custom_field.is_required? ? false : '_blank', # autocompleter does not send '_blank' as value when no option is selected
- autocomplete_options: {
- multiple: true,
- decorated: true,
- inputId: id,
- inputName: name
- },
- invalid: invalid?,
- validation_message:
- }
- end
-
- def name
- "project[multi_custom_field_values_attributes][#{@custom_field.id}][values]"
+ def decorated
+ true
end
- def invalid?
- @custom_field_values.any? { |custom_field_value| custom_field_value.errors.any? }
- end
+ def selected?(custom_option)
+ cf_values = @custom_field_values.reject { |custom_field_value| custom_field_value.id.nil? }
- def validation_message
- @custom_field_values.map { |custom_field_value| custom_field_value.errors.full_messages }.join(', ') if invalid?
+ if cf_values.any?
+ cf_values.pluck(:value).map { |value| value&.to_i }.include?(custom_option.id)
+ else
+ custom_option.default_value?
+ end
end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/multi_user_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/multi_user_select_list.rb
index 42c8433f31c..579f2fed1d2 100644
--- a/modules/overviews/app/forms/project/custom_value_form/multi_user_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/multi_user_select_list.rb
@@ -26,48 +26,39 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::MultiUserSelectList < Project::CustomValueForm::Base
- def initialize(custom_field:, custom_field_values:, project:)
- @custom_field = custom_field
- @custom_field_values = custom_field_values
- @project = project
- end
-
+class Project::CustomValueForm::MultiUserSelectList < Project::CustomValueForm::Base::Autocomplete::MultiValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config)
end
private
- def base_config
- {
- name:,
- scope_name_to_model: false,
- scope_id_to_model: false, # autocompleter does not respect scope_id_to_model = false
- placeholder: @custom_field.name,
- label: @custom_field.name,
- required: @custom_field.is_required?,
- autocomplete_options: {
- multiple: true,
- # decorated: true,
- inputId: id,
- placeholder: "Search for users",
- resource: 'principals',
- filters: [{ name: 'type', operator: '=', values: ['User'] },
- { name: 'member', operator: '=', values: ['1'] }],
- searchKey: 'any_name_attribute',
- inputName: name,
- inputValue: input_value
- },
- invalid: invalid?,
- validation_message:
- }
+ def decorated
+ false
+ end
+
+ def autocomplete_options
+ super.merge({
+ placeholder: "Search for users",
+ resource: 'principals',
+ filters:,
+ searchKey: 'any_name_attribute',
+ inputValue: input_value
+ })
end
def name
"project[multi_user_custom_field_values_attributes][#{@custom_field.id}][comma_seperated_values][]"
end
+ def filters
+ [
+ { name: 'type', operator: '=', values: ['User', 'Group', 'PlaceholderUser'] },
+ { name: 'member', operator: '=', values: [@project.id.to_s] },
+ { name: 'status', operator: '!', values: [User.statuses["locked"].to_s] }
+ ]
+ end
+
def input_value
"?#{input_values_filter}"
end
@@ -79,12 +70,4 @@ class Project::CustomValueForm::MultiUserSelectList < Project::CustomValueForm::
filters = [user_filter, id_filter]
URI.encode_www_form("filters" => filters.to_json)
end
-
- def invalid?
- @custom_field_values.any? { |custom_field_value| custom_field_value.errors.any? }
- end
-
- def validation_message
- @custom_field_values.map { |custom_field_value| custom_field_value.errors.full_messages }.join(', ') if invalid?
- end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/multi_version_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/multi_version_select_list.rb
index 62b05cbc0fb..ec773aecbc1 100644
--- a/modules/overviews/app/forms/project/custom_value_form/multi_version_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/multi_version_select_list.rb
@@ -26,19 +26,13 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::MultiVersionSelectList < Project::CustomValueForm::Base
- def initialize(custom_field:, custom_field_values:, project:)
- @custom_field = custom_field
- @custom_field_values = custom_field_values
- @project = project
- end
-
+class Project::CustomValueForm::MultiVersionSelectList < Project::CustomValueForm::Base::Autocomplete::MultiValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config) do |list|
@project.versions.each do |version|
list.option(
label: version.name, value: version.id,
- selected: @custom_field_values.pluck(:value).map { |value| value&.to_i }.include?(version.id)
+ selected: selected?(version)
)
end
end
@@ -46,35 +40,11 @@ class Project::CustomValueForm::MultiVersionSelectList < Project::CustomValueFor
private
- def base_config
- {
- name:,
- scope_name_to_model: false,
- scope_id_to_model: false, # autocompleter does not respect scope_id_to_model = false
- placeholder: @custom_field.name,
- label: @custom_field.name,
- required: @custom_field.is_required?,
- include_blank: @custom_field.is_required? ? false : '_blank', # autocompleter does not send '_blank' as value when no option is selected
- autocomplete_options: {
- multiple: true,
- decorated: true,
- inputId: id,
- inputName: name
- },
- invalid: invalid?,
- validation_message:
- }
- end
-
- def name
- "project[multi_custom_field_values_attributes][#{@custom_field.id}][values]"
- end
-
- def invalid?
- @custom_field_values.any? { |custom_field_value| custom_field_value.errors.any? }
+ def decorated
+ true
end
- def validation_message
- @custom_field_values.map { |custom_field_value| custom_field_value.errors.full_messages }.join(', ') if invalid?
+ def selected?(version)
+ @custom_field_values.pluck(:value).map { |value| value&.to_i }.include?(version.id)
end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/single_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/single_select_list.rb
index e05ff913db0..d8d70d73182 100644
--- a/modules/overviews/app/forms/project/custom_value_form/single_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/single_select_list.rb
@@ -26,29 +26,25 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::SingleSelectList < Project::CustomValueForm::Base
+class Project::CustomValueForm::SingleSelectList < Project::CustomValueForm::Base::Autocomplete::SingleValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config) do |list|
@custom_field_value.custom_field.custom_options.each do |custom_option|
list.option(
label: custom_option.value, value: custom_option.id,
- selected: custom_option.id == @custom_field_value.value&.to_i
+ selected: selected?(custom_option)
)
end
end
end
- def base_config
- super.merge(
- {
- include_blank: @custom_field.is_required? ? false : '_blank', # autocompleter does not send '_blank' as value when no option is selected
- autocomplete_options: {
- multiple: false,
- decorated: true,
- inputId: id,
- inputName: name
- }
- }
- )
+ private
+
+ def decorated
+ true
+ end
+
+ def selected?(custom_option)
+ custom_option.id == @custom_field_value.value&.to_i || custom_option.id == @custom_field.default_value&.to_i
end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/single_user_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/single_user_select_list.rb
index f410dae1e5f..ba293ba04bc 100644
--- a/modules/overviews/app/forms/project/custom_value_form/single_user_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/single_user_select_list.rb
@@ -26,48 +26,44 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::SingleUserSelectList < Project::CustomValueForm::Base
+class Project::CustomValueForm::SingleUserSelectList < Project::CustomValueForm::Base::Autocomplete::SingleValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config)
end
- def base_config
+ private
+
+ def decorated
+ false
+ end
+
+ def autocomplete_options
super.merge({
- autocomplete_options: {
- inputId: id,
- placeholder: "Search for a user",
- resource: 'principals',
- filters: [{ name: 'type', operator: '=', values: ['User'] },
- { name: 'member', operator: '=', values: ['1'] }],
- searchKey: 'any_name_attribute',
- inputName: name,
- inputValue: input_value
- # focusDirectly: true,
- # appendTo: 'body',
- # disabled: @disabled
- },
- invalid: invalid?,
- validation_message:
+ placeholder: "Search for a user",
+ resource: 'principals',
+ filters:,
+ searchKey: 'any_name_attribute',
+ inputValue: input_value
})
end
+ def filters
+ [
+ { name: 'type', operator: '=', values: ['User', 'Group', 'PlaceholderUser'] },
+ { name: 'member', operator: '=', values: [@project.id.to_s] },
+ { name: 'status', operator: '!', values: [User.statuses["locked"].to_s] }
+ ]
+ end
+
def input_value
"?#{input_values_filter}"
end
def input_values_filter
- user_filter = { "type" => { "operator" => "=", "values" => ["User"] } }
+ user_filter = { "type" => { "operator" => "=", "values" => ['User', 'Group', 'PlaceholderUser'] } }
id_filter = { "id" => { "operator" => "=", "values" => @custom_field_value.value } }
filters = [user_filter, id_filter]
URI.encode_www_form("filters" => filters.to_json)
end
-
- def invalid?
- @custom_field_value.errors.any?
- end
-
- def validation_message
- @custom_field_value.errors.full_messages.join(', ') if invalid?
- end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/single_version_select_list.rb b/modules/overviews/app/forms/project/custom_value_form/single_version_select_list.rb
index 5437fa2f82f..72f1d1a1b4a 100644
--- a/modules/overviews/app/forms/project/custom_value_form/single_version_select_list.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/single_version_select_list.rb
@@ -26,30 +26,25 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::SingleVersionSelectList < Project::CustomValueForm::Base
+class Project::CustomValueForm::SingleVersionSelectList < Project::CustomValueForm::Base::Autocomplete::SingleValueInput
form do |custom_value_form|
custom_value_form.autocompleter(**base_config) do |list|
@project.versions.each do |version|
list.option(
label: version.name, value: version.id,
- selected: version.id == @custom_field_value.value&.to_i
+ selected: selected?(version)
)
end
end
end
- def base_config
- super.merge(
- {
- include_blank: @custom_field.is_required? ? false : '_blank', # autocompleter does not send '_blank' as value when no option is selected
- autocomplete_options: {
- multiple: false,
- decorated: true,
- inputId: id,
- inputName: name,
- }
- }
- )
+ private
+
+ def decorated
+ true
end
+ def selected?(version)
+ version.id == @custom_field_value.value&.to_i
+ end
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/string.rb b/modules/overviews/app/forms/project/custom_value_form/string.rb
index e301c10da3c..5b535eb950a 100644
--- a/modules/overviews/app/forms/project/custom_value_form/string.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/string.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::String < Project::CustomValueForm::Base
+class Project::CustomValueForm::String < Project::CustomValueForm::Base::Input
form do |custom_value_form|
custom_value_form.text_field(**base_config)
end
diff --git a/modules/overviews/app/forms/project/custom_value_form/text.rb b/modules/overviews/app/forms/project/custom_value_form/text.rb
index 6c66afda1ac..5c4758b3f74 100644
--- a/modules/overviews/app/forms/project/custom_value_form/text.rb
+++ b/modules/overviews/app/forms/project/custom_value_form/text.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Project::CustomValueForm::Text < Project::CustomValueForm::Base
+class Project::CustomValueForm::Text < Project::CustomValueForm::Base::Input
form do |custom_value_form|
# TODO: rich_text_area not working yet
# Uncaught DOMException: Failed to execute 'querySelector' on 'Element': '#project_project[new_custom_field_values_attributes][xyz][value]' is not a valid selector.
diff --git a/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb
new file mode 100644
index 00000000000..685dff43762
--- /dev/null
+++ b/spec/features/projects/project_custom_fields/overview_page/dialog_spec.rb
@@ -0,0 +1,694 @@
+#-- 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.
+#++
+
+require 'spec_helper'
+require_relative 'shared_context'
+
+RSpec.describe 'Edit project custom fields on project overview page', :js do
+ include_context 'with seeded projects, members and project custom fields'
+
+ let(:overview_page) { Pages::Projects::Show.new(project) }
+
+ before do
+ login_as admin
+ end
+
+ describe 'with enabled project attributes feature', with_flag: { project_attributes: true } do
+ before do
+ overview_page.visit_page
+ end
+
+ describe 'with sufficient permissions' do
+ describe 'enables editing of project custom field values via dialog' do
+ let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section_for_input_fields) }
+
+ it 'opens a dialog showing inputs for project custom fields of a specific section' do
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.expect_open
+ end
+
+ it 'renders the dialog body asynchronically' do
+ expect(page).to have_no_css(dialog.async_content_container_css_selector, visible: :all)
+
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ expect(page).to have_css(dialog.async_content_container_css_selector, visible: :visible)
+ end
+
+ it 'can be closed via close icon or cancel button' do
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.close_via_icon
+
+ dialog.expect_closed
+
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.close_via_button
+
+ dialog.expect_closed
+ end
+
+ it 'shows only the project custom fields of the specific section within the dialog' do
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.within_async_content(close_after_yield: true) do
+ (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
+ if input_fields.include?(project_custom_field)
+ expect(page).to have_content(project_custom_field.name)
+ else
+ expect(page).to have_no_content(project_custom_field.name)
+ end
+ end
+ end
+
+ dialog = Components::Projects::ProjectCustomFields::EditDialog.new(project, section_for_select_fields)
+
+ overview_page.open_edit_dialog_for_section(section_for_select_fields)
+
+ dialog.within_async_content(close_after_yield: true) do
+ (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
+ if select_fields.include?(project_custom_field)
+ expect(page).to have_content(project_custom_field.name)
+ else
+ expect(page).to have_no_content(project_custom_field.name)
+ end
+ end
+ end
+
+ dialog = Components::Projects::ProjectCustomFields::EditDialog.new(project, section_for_multi_select_fields)
+
+ overview_page.open_edit_dialog_for_section(section_for_multi_select_fields)
+
+ dialog.within_async_content(close_after_yield: true) do
+ (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
+ if multi_select_fields.include?(project_custom_field)
+ expect(page).to have_content(project_custom_field.name)
+ else
+ expect(page).to have_no_content(project_custom_field.name)
+ end
+ end
+ end
+ end
+
+ it 'shows the inputs in the correct order defined by the position of project custom field in a section' do
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.within_async_content(close_after_yield: true) do
+ containers = dialog.input_containers
+
+ expect(containers[0].text).to include('Boolean field')
+ expect(containers[1].text).to include('String field')
+ expect(containers[2].text).to include('Integer field')
+ expect(containers[3].text).to include('Float field')
+ expect(containers[4].text).to include('Date field')
+ expect(containers[5].text).to include('Text field')
+ end
+
+ boolean_project_custom_field.move_to_bottom
+
+ overview_page.open_edit_dialog_for_section(section_for_input_fields)
+
+ dialog.within_async_content(close_after_yield: true) do
+ containers = dialog.input_containers
+
+ expect(containers[0].text).to include('String field')
+ expect(containers[1].text).to include('Integer field')
+ expect(containers[2].text).to include('Float field')
+ expect(containers[3].text).to include('Date field')
+ expect(containers[4].text).to include('Text field')
+ expect(containers[5].text).to include('Boolean field')
+ end
+ end
+
+ describe 'with correct inital values' do
+ describe 'with input fields' do
+ let(:section) { section_for_input_fields }
+ let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section) }
+
+ shared_examples 'a custom field checkbox' do
+ it 'shows the correct value if given' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ if expected_initial_value
+ expect(page).to have_checked_field(custom_field.name)
+ else
+ expect(page).to have_no_checked_field(custom_field.name)
+ end
+ end
+ end
+
+ it 'is unchecked if no value and no default value is given' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_no_checked_field(custom_field.name)
+ end
+ end
+
+ it 'shows default value if no value is given' do
+ custom_field.custom_values.destroy_all
+
+ custom_field.update!(default_value: true)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_checked_field(custom_field.name)
+ end
+
+ custom_field.update!(default_value: false)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_no_checked_field(custom_field.name)
+ end
+ end
+ end
+
+ shared_examples 'a custom field input' do
+ it 'shows the correct value if given' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_field(custom_field.name, with: expected_initial_value)
+ end
+ end
+
+ it 'shows a blank input if no value or default value is given' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_field(custom_field.name, with: expected_blank_value)
+ end
+ end
+
+ it 'shows the default value if no value is given' do
+ custom_field.custom_values.destroy_all
+ custom_field.update!(default_value:)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ dialog.within_async_content(close_after_yield: true) do
+ expect(page).to have_field(custom_field.name, with: default_value)
+ end
+ end
+ end
+
+ describe 'with boolean CF' do
+ let(:custom_field) { boolean_project_custom_field }
+ let(:default_value) { false }
+ let(:expected_blank_value) { false }
+ let(:expected_initial_value) { true }
+
+ it_behaves_like 'a custom field checkbox'
+ end
+
+ describe 'with string CF' do
+ let(:custom_field) { string_project_custom_field }
+ let(:default_value) { 'Default value' }
+ let(:expected_blank_value) { '' }
+ let(:expected_initial_value) { 'Foo' }
+
+ it_behaves_like 'a custom field input'
+ end
+
+ describe 'with integer CF' do
+ let(:custom_field) { integer_project_custom_field }
+ let(:default_value) { 789 }
+ let(:expected_blank_value) { '' }
+ let(:expected_initial_value) { 123 }
+
+ it_behaves_like 'a custom field input'
+ end
+
+ describe 'with float CF' do
+ let(:custom_field) { float_project_custom_field }
+ let(:default_value) { 789.123 }
+ let(:expected_blank_value) { '' }
+ let(:expected_initial_value) { 123.456 }
+
+ it_behaves_like 'a custom field input'
+ end
+
+ describe 'with date CF' do
+ let(:custom_field) { date_project_custom_field }
+ let(:default_value) { Date.new(2026, 1, 1) }
+ let(:expected_blank_value) { '' }
+ let(:expected_initial_value) { Date.new(2024, 1, 1) }
+
+ it_behaves_like 'a custom field input'
+ end
+
+ describe 'with text CF' do
+ let(:custom_field) { text_project_custom_field }
+ let(:default_value) { 'Default value' }
+ let(:expected_blank_value) { '' }
+ let(:expected_initial_value) { "Lorem\nipsum" }
+
+ it_behaves_like 'a custom field input'
+ end
+ end
+
+ describe 'with single select fields' do
+ let(:section) { section_for_select_fields }
+ let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section) }
+
+ shared_examples 'a autocomplete single select field' do
+ it 'shows the correct value if given' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_selected(expected_initial_value)
+ end
+
+ it 'shows a blank input if no value or default value is given' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_blank
+ end
+
+ it 'filters the list based on the input' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search(second_option)
+
+ field.expect_option(second_option)
+ field.expect_no_option(first_option)
+ field.expect_no_option(third_option)
+ end
+
+ it 'enables the user to select a single value from a list' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search(second_option)
+ field.select_option(second_option)
+
+ field.expect_selected(second_option)
+
+ field.search(third_option)
+ field.select_option(third_option)
+
+ field.expect_selected(third_option)
+ field.expect_not_selected(second_option)
+ end
+
+ it 'clears the input if clicked on the clear button' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.clear
+
+ field.expect_blank
+ end
+ end
+
+ describe 'with single select list CF' do
+ let(:custom_field) { list_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { custom_field.custom_options.first.value }
+
+ let(:first_option) { custom_field.custom_options.first.value }
+ let(:second_option) { custom_field.custom_options.second.value }
+ let(:third_option) { custom_field.custom_options.third.value }
+
+ it_behaves_like 'a autocomplete single select field'
+
+ it 'shows the default value if no value is given' do
+ custom_field.custom_values.destroy_all
+
+ custom_field.custom_options.first.update!(default_value: true)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_selected(custom_field.custom_options.first.value)
+ end
+ end
+
+ describe 'with single version select list CF' do
+ let(:custom_field) { version_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { first_version.name }
+
+ let(:first_option) { first_version.name }
+ let(:second_option) { second_version.name }
+ let(:third_option) { third_version.name }
+
+ it_behaves_like 'a autocomplete single select field'
+
+ describe 'with correct version scoping' do
+ let!(:version_in_other_project) do
+ create(:version, name: 'Version 1 in other project', project: other_project)
+ end
+
+ it 'shows only versions that are associated with this project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Version 1')
+
+ field.expect_option(first_version.name)
+ field.expect_no_option(version_in_other_project.name)
+ end
+ end
+ end
+
+ describe 'with single user select list CF' do
+ let(:custom_field) { user_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { member_in_project.name }
+
+ let(:first_option) { member_in_project.name }
+ let(:second_option) { another_member_in_project.name }
+ let(:third_option) { one_more_member_in_project.name }
+
+ it_behaves_like 'a autocomplete single select field'
+
+ describe 'with correct user scoping' do
+ let!(:member_in_other_project) do
+ create(:user,
+ firstname: 'Member 1',
+ lastname: 'In other Project',
+ member_with_roles: { other_project => reader_role })
+ end
+
+ it 'shows only users that are members of the project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Member 1')
+
+ field.expect_option(member_in_project.name)
+ field.expect_no_option(member_in_other_project.name)
+ end
+ end
+
+ describe 'with support for user groups' do
+ let!(:member_in_other_project) do
+ create(:user,
+ firstname: 'Member 1',
+ lastname: 'In other Project',
+ member_with_roles: { other_project => reader_role })
+ end
+ let!(:group) do
+ create(:group, name: 'Group 1 in project',
+ member_with_roles: { project => reader_role })
+ end
+ let!(:group_in_other_project) do
+ create(:group, name: 'Group 1 in other project', members: [member_in_other_project],
+ member_with_roles: { other_project => reader_role })
+ end
+
+ it 'shows only groups that are associated with this project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Group 1')
+
+ field.expect_option(group.name)
+ field.expect_no_option(group_in_other_project.name)
+ end
+ end
+
+ describe 'with support for placeholder users' do
+ let!(:placeholder_user) do
+ create(:placeholder_user, name: 'Placeholder User',
+ member_with_roles: { project => reader_role })
+ end
+
+ it 'shows the placeholder user' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Placeholder User')
+
+ field.expect_option(placeholder_user.name)
+ end
+ end
+ end
+ end
+
+ describe 'with multi select fields' do
+ let(:section) { section_for_multi_select_fields }
+ let(:dialog) { Components::Projects::ProjectCustomFields::EditDialog.new(project, section) }
+
+ shared_examples 'a autocomplete multi select field' do
+ it 'shows the correct value if given' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_selected(*expected_initial_value)
+ end
+
+ it 'shows a blank input if no value or default value is given' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_blank
+ end
+
+ it 'filters the list based on the input' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search(second_option)
+
+ field.expect_option(second_option)
+ field.expect_no_option(first_option)
+ field.expect_no_option(third_option)
+ end
+
+ it 'allows to select multiple values' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.select_option(second_option)
+ field.select_option(third_option)
+
+ field.expect_selected(second_option)
+ field.expect_selected(third_option)
+ end
+
+ it 'allows to remove selected values' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.select_option(second_option)
+ field.select_option(third_option)
+
+ field.deselect_option(third_option)
+
+ field.expect_selected(second_option)
+ field.expect_not_selected(third_option)
+ end
+
+ it 'allows to remove all selected values at once' do
+ custom_field.custom_values.destroy_all
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.select_option(second_option)
+ field.select_option(third_option)
+
+ field.clear
+
+ field.expect_not_selected(second_option)
+ field.expect_not_selected(third_option)
+ end
+ end
+
+ describe 'with multi select list CF' do
+ let(:custom_field) { multi_list_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { [custom_field.custom_options.first.value, custom_field.custom_options.second.value] }
+
+ let(:first_option) { custom_field.custom_options.first.value }
+ let(:second_option) { custom_field.custom_options.second.value }
+ let(:third_option) { custom_field.custom_options.third.value }
+
+ it_behaves_like 'a autocomplete multi select field'
+
+ it 'shows the default value if no value is given' do
+ multi_list_project_custom_field.custom_values.destroy_all
+
+ multi_list_project_custom_field.custom_options.first.update!(default_value: true)
+ multi_list_project_custom_field.custom_options.second.update!(default_value: true)
+
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.expect_selected(multi_list_project_custom_field.custom_options.first.value)
+ field.expect_selected(multi_list_project_custom_field.custom_options.second.value)
+ end
+ end
+
+ describe 'with multi version select list CF' do
+ let(:custom_field) { multi_version_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { [first_version.name, second_version.name] }
+
+ let(:first_option) { first_version.name }
+ let(:second_option) { second_version.name }
+ let(:third_option) { third_version.name }
+
+ it_behaves_like 'a autocomplete multi select field'
+
+ describe 'with correct version scoping' do
+ let!(:version_in_other_project) do
+ create(:version, name: 'Version 1 in other project', project: other_project)
+ end
+
+ it 'shows only versions that are associated with this project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Version 1')
+
+ field.expect_option(first_version.name)
+ field.expect_no_option(version_in_other_project.name)
+ end
+ end
+ end
+
+ describe 'with multi user select list CF' do
+ let(:custom_field) { multi_user_project_custom_field }
+ let(:field) { FormFields::Primerized::AutocompleteField.new(custom_field) }
+
+ let(:expected_initial_value) { [member_in_project.name, another_member_in_project.name] }
+
+ let(:first_option) { member_in_project.name }
+ let(:second_option) { another_member_in_project.name }
+ let(:third_option) { one_more_member_in_project.name }
+
+ it_behaves_like 'a autocomplete multi select field'
+
+ describe 'with correct user scoping' do
+ let!(:member_in_other_project) do
+ create(:user,
+ firstname: 'Member 1',
+ lastname: 'In other Project',
+ member_with_roles: { other_project => reader_role })
+ end
+
+ it 'shows only users that are members of the project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Member 1')
+
+ field.expect_option(member_in_project.name)
+ field.expect_no_option(member_in_other_project.name)
+ end
+ end
+
+ describe 'with support for user groups' do
+ let!(:member_in_other_project) do
+ create(:user,
+ firstname: 'Member 1',
+ lastname: 'In other Project',
+ member_with_roles: { other_project => reader_role })
+ end
+ let!(:group) do
+ create(:group, name: 'Group 1 in project',
+ member_with_roles: { project => reader_role })
+ end
+ let!(:another_group) do
+ create(:group, name: 'Group 2 in project',
+ member_with_roles: { project => reader_role })
+ end
+ let!(:group_in_other_project) do
+ create(:group, name: 'Group 1 in other project', members: [member_in_other_project],
+ member_with_roles: { other_project => reader_role })
+ end
+
+ it 'shows only groups that are associated with this project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Group 1')
+ field.expect_option(group.name)
+ field.expect_no_option(group_in_other_project.name)
+ end
+
+ it 'enables to select multiple user groups' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.select_option('Group 1 in project')
+ field.select_option('Group 2 in project')
+
+ field.expect_selected('Group 1 in project')
+ field.expect_selected('Group 2 in project')
+ end
+ end
+
+ describe 'with support for placeholder users' do
+ let!(:placeholder_user) do
+ create(:placeholder_user, name: 'Placeholder user',
+ member_with_roles: { project => reader_role })
+ end
+ let!(:another_placeholder_user) do
+ create(:placeholder_user, name: 'Another placeholder User',
+ member_with_roles: { project => reader_role })
+ end
+ let!(:placeholder_user_in_other_project) do
+ create(:placeholder_user, name: 'Placeholder user in other project',
+ member_with_roles: { other_project => reader_role })
+ end
+
+ it 'shows only placeholder users from this project' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.search('Placeholder User')
+
+ field.expect_option(placeholder_user.name)
+ field.expect_option(another_placeholder_user.name)
+ field.expect_no_option(placeholder_user_in_other_project.name)
+ end
+
+ it 'enables to select multiple placeholder users' do
+ overview_page.open_edit_dialog_for_section(section)
+
+ field.select_option(placeholder_user.name)
+ field.select_option(another_placeholder_user.name)
+
+ field.expect_selected(placeholder_user.name)
+ field.expect_selected(another_placeholder_user.name)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/features/projects/project_custom_fields/overview_page/edit_spec.rb b/spec/features/projects/project_custom_fields/overview_page/edit_spec.rb
deleted file mode 100644
index 414424a812d..00000000000
--- a/spec/features/projects/project_custom_fields/overview_page/edit_spec.rb
+++ /dev/null
@@ -1,163 +0,0 @@
-#-- 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.
-#++
-
-require 'spec_helper'
-require_relative 'shared_context'
-require_relative 'overview_page'
-
-RSpec.describe 'Edit project custom fields on project overview page', :js, :with_cuprite do
- include_context 'with seeded projects, members and project custom fields'
-
- let(:overview_page) { OverviewPage.new(project) }
-
- before do
- login_as admin
- end
-
- describe 'with enabled project attributes feature', with_flag: { project_attributes: true } do
- describe 'with sufficient permissions' do
- describe 'enables editing of project custom field values via dialog' do
- it 'opens a dialog showing inputs for project custom fields of a specific section' do
- overview_page.visit_page
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- expect(page).to have_css("modal-dialog#edit-project-attributes-dialog-#{section_for_input_fields.id}")
- end
-
- it 'renders the dialog body asynchronically' do
- overview_page.visit_page
-
- expect(page).to have_no_css('#project-custom-fields-sections-edit-dialog-component', visible: :all)
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- expect(page).to have_css('#project-custom-fields-sections-edit-dialog-component', visible: :visible)
- end
-
- it 'can be closed via close icon or cancel button' do
- overview_page.visit_page
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- within("modal-dialog#edit-project-attributes-dialog-#{section_for_input_fields.id}") do
- page.find(".close-button").click
- end
-
- expect(page).to have_no_css("modal-dialog#edit-project-attributes-dialog-#{section_for_input_fields.id}")
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- within("modal-dialog#edit-project-attributes-dialog-#{section_for_input_fields.id}") do
- click_link_or_button 'Cancel'
- end
-
- expect(page).to have_no_css("modal-dialog#edit-project-attributes-dialog-#{section_for_input_fields.id}")
- end
-
- it 'shows only the project custom fields of the specific section within the dialog' do
- overview_page.visit_page
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- overview_page.within_edit_dialog_for_section(section_for_input_fields) do
- (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
- if input_fields.include?(project_custom_field)
- expect(page).to have_content(project_custom_field.name)
- else
- expect(page).to have_no_content(project_custom_field.name)
- end
- end
- end
-
- overview_page.close_edit_dialog_for_section(section_for_input_fields)
-
- overview_page.open_edit_dialog_for_section(section_for_select_fields)
-
- overview_page.within_edit_dialog_for_section(section_for_select_fields) do
- (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
- if select_fields.include?(project_custom_field)
- expect(page).to have_content(project_custom_field.name)
- else
- expect(page).to have_no_content(project_custom_field.name)
- end
- end
- end
-
- overview_page.close_edit_dialog_for_section(section_for_select_fields)
-
- overview_page.open_edit_dialog_for_section(section_for_multi_select_fields)
-
- overview_page.within_edit_dialog_for_section(section_for_multi_select_fields) do
- (input_fields + select_fields + multi_select_fields).each do |project_custom_field|
- if multi_select_fields.include?(project_custom_field)
- expect(page).to have_content(project_custom_field.name)
- else
- expect(page).to have_no_content(project_custom_field.name)
- end
- end
- end
- end
-
- it 'shows the inputs in the correct order defined by the position of project custom field in a section' do
- overview_page.visit_page
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- overview_page.within_edit_dialog_for_section(section_for_input_fields) do
- fields = page.all('.op-project-custom-field-input-container')
-
- expect(fields[0].text).to include('Boolean field')
- expect(fields[1].text).to include('String field')
- expect(fields[2].text).to include('Integer field')
- expect(fields[3].text).to include('Float field')
- expect(fields[4].text).to include('Date field')
- expect(fields[5].text).to include('Text field')
- end
-
- overview_page.close_edit_dialog_for_section(section_for_input_fields)
-
- boolean_project_custom_field.move_to_bottom
-
- overview_page.open_edit_dialog_for_section(section_for_input_fields)
-
- overview_page.within_edit_dialog_for_section(section_for_input_fields) do
- fields = page.all('.op-project-custom-field-input-container')
-
- expect(fields[0].text).to include('String field')
- expect(fields[1].text).to include('Integer field')
- expect(fields[2].text).to include('Float field')
- expect(fields[3].text).to include('Date field')
- expect(fields[4].text).to include('Text field')
- expect(fields[5].text).to include('Boolean field')
- end
- end
- end
- end
- end
-end
diff --git a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
index 0033eefa9cb..f38bcfa26b1 100644
--- a/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
+++ b/spec/features/projects/project_custom_fields/overview_page/shared_context.rb
@@ -30,8 +30,13 @@ RSpec.shared_context 'with seeded projects, members and project custom fields' d
let(:project) { create(:project, name: 'Foo project', identifier: 'foo-project') }
let(:other_project) { create(:project, name: 'Bar project', identifier: 'bar-project') }
- let(:first_version) { create(:version, name: 'Version 1', project:) }
- let(:second_version) { create(:version, name: 'Version 2', project:) }
+ let!(:first_version) { create(:version, name: 'Version 1', project:) }
+ let!(:second_version) { create(:version, name: 'Version 2', project:) }
+ let!(:third_version) { create(:version, name: 'Version 3', project:) }
+
+ shared_let(:reader_role) do
+ create(:project_role, permissions: %i[view_work_packages])
+ end
let!(:admin) do
create(:admin)
@@ -41,18 +46,21 @@ RSpec.shared_context 'with seeded projects, members and project custom fields' d
create(:user,
firstname: 'Member 1',
lastname: 'In Project',
- member_with_permissions: { project => %w[
- view_work_packages
- ] })
+ member_with_roles: { project => reader_role })
end
let!(:another_member_in_project) do
create(:user,
firstname: 'Member 2',
lastname: 'In Project',
- member_with_permissions: { project => %w[
- view_work_packages
- ] })
+ member_with_roles: { project => reader_role })
+ end
+
+ let!(:one_more_member_in_project) do
+ create(:user,
+ firstname: 'Member 3',
+ lastname: 'In Project',
+ member_with_roles: { project => reader_role })
end
let!(:section_for_input_fields) { create(:project_custom_field_section, name: 'Input fields') }
diff --git a/spec/features/projects/project_custom_fields/overview_page/show_spec.rb b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb
similarity index 98%
rename from spec/features/projects/project_custom_fields/overview_page/show_spec.rb
rename to spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb
index 3895e3048f7..03c0b5667e0 100644
--- a/spec/features/projects/project_custom_fields/overview_page/show_spec.rb
+++ b/spec/features/projects/project_custom_fields/overview_page/sidebar_spec.rb
@@ -720,6 +720,14 @@ RSpec.describe 'Show project custom fields on project overview page', :js, :with
end
end
end
+
+ describe 'with support for user groups' do
+ # TODO
+ end
+
+ describe 'with support for user placeholders' do
+ # TODO
+ end
end
describe 'with multi list CF' do
@@ -833,18 +841,4 @@ RSpec.describe 'Show project custom fields on project overview page', :js, :with
end
end
end
-
- # TODO: share examples in order to reduce code duplication
- # shared_examples 'a project custom field' do
- # it 'shows the correct value for the project custom field if given' do
- # overview_page.visit_page
-
- # overview_page.within_async_loaded_sidebar do
- # overview_page.within_custom_field_container(custom_field) do
- # expect(page).to have_text custom_field.name
- # expect(page).to have_text custom_field.formatted_value
- # end
- # end
- # end
- # end
end
diff --git a/spec/support/components/projects/project_custom_fields/edit_dialog.rb b/spec/support/components/projects/project_custom_fields/edit_dialog.rb
new file mode 100644
index 00000000000..1bb07c2c3fd
--- /dev/null
+++ b/spec/support/components/projects/project_custom_fields/edit_dialog.rb
@@ -0,0 +1,479 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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.
+# ++
+
+require 'support/components/common/modal'
+require 'support/components/autocompleter/ng_select_autocomplete_helpers'
+
+module Components
+ module Projects
+ module ProjectCustomFields
+ class EditDialog < Components::Common::Modal
+ include Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ attr_reader :project, :project_custom_field_section, :title
+
+ def initialize(project, project_custom_field_section)
+ super()
+
+ @project = project
+ @project_custom_field_section = project_custom_field_section
+ @title = @project_custom_field_section.name
+ end
+
+ def dialog_css_selector
+ "modal-dialog#edit-project-attributes-dialog-#{@project_custom_field_section.id}"
+ end
+
+ def async_content_container_css_selector
+ "#{dialog_css_selector} [data-qa-selector='async-dialog-content']"
+ end
+
+ def within_dialog(&)
+ within(dialog_css_selector, &)
+ end
+
+ def within_async_content(close_after_yield: false, &)
+ within(async_content_container_css_selector, &)
+ close if close_after_yield
+ end
+
+ def close
+ within_dialog do
+ page.find(".close-button").click
+ end
+ end
+ alias_method :close_via_icon, :close
+
+ def close_via_button
+ within(dialog_css_selector) do
+ click_link_or_button 'Cancel'
+ end
+ end
+
+ def expect_open
+ expect(page).to have_css(dialog_css_selector)
+ end
+
+ def expect_closed
+ expect(page).to have_no_css(dialog_css_selector)
+ end
+
+ def expect_async_content_loaded
+ expect(page).to have_css(async_content_container_css_selector)
+ end
+
+ ###
+
+ def input_containers
+ page.all('.op-project-custom-field-input-container')
+ end
+
+ def within_custom_field_input_container(custom_field, &)
+ # wrapping in `within_async_content` to make sure the container is properly loaded
+ within_async_content do
+ within("[data-qa-selector='project-custom-field-input-container-#{custom_field.id}']", &)
+ end
+ end
+ end
+ end
+ end
+end
+
+# def select_shares(*principals)
+# within shares_list do
+# principals.each do |principal|
+# check principal.name
+# end
+# end
+# end
+
+# def deselect_shares(*principals)
+# within shares_list do
+# principals.each do |principal|
+# uncheck principal.name
+# end
+# end
+# end
+
+# def expect_not_selectable(*principals)
+# principals.each do |principal|
+# within user_row(principal) do
+# expect(page).to have_no_field(principal.name)
+# end
+# end
+# end
+
+# def toggle_select_all
+# within shares_header do
+# if page.find_field('toggle_all').checked?
+# uncheck 'toggle_all'
+# else
+# check 'toggle_all'
+# end
+# end
+# end
+
+# def expect_selected(*principals)
+# within shares_list do
+# principals.each do |principal|
+# expect(page).to have_checked_field(principal.name)
+# end
+# end
+# end
+
+# def expect_deselected(*principals)
+# within shares_list do
+# principals.each do |principal|
+# expect(page).to have_unchecked_field(principal.name)
+# end
+# end
+# end
+
+# def expect_selected_count_of(count)
+# expect(shares_header)
+# .to have_text("#{count} selected")
+# end
+
+# def expect_select_all_available
+# expect(shares_header)
+# .to have_field('toggle_all')
+# end
+
+# def expect_select_all_not_available
+# expect(shares_header)
+# .to have_no_field('toggle_all', wait: 0)
+# end
+
+# def expect_select_all_toggled
+# within shares_header do
+# expect(page).to have_checked_field('toggle_all')
+# end
+# end
+
+# def expect_select_all_untoggled
+# within shares_header do
+# expect(page).to have_unchecked_field('toggle_all')
+# end
+# end
+
+# def expect_bulk_actions_available
+# within shares_header do
+# expect(page).to have_button 'Remove'
+# expect(page).to have_test_selector('op-share-wp-bulk-update-role')
+# end
+# end
+
+# def expect_bulk_actions_not_available
+# within shares_header do
+# expect(page).to have_no_button('Remove', wait: 0)
+# expect(page).not_to have_test_selector('op-share-wp-bulk-update-role', wait: 0)
+# end
+# end
+
+# def bulk_remove
+# within shares_header do
+# click_button 'Remove'
+# end
+# end
+
+# def bulk_update(role_name)
+# within shares_header do
+# find('[data-test-selector="op-share-wp-bulk-update-role"]').click
+
+# find('.ActionListContent', text: role_name).click
+# end
+# end
+
+# def expect_bulk_update_label(label_text)
+# within shares_header do
+# expect(page)
+# .to have_css('[data-test-selector="op-share-wp-bulk-update-role"] .Button-label',
+# text: label_text)
+# if label_text == 'Mixed'
+# %w[View Comment Edit].each do |permission_name|
+# within bulk_update_form(permission_name) do
+# expect(page)
+# .to have_css(unchecked_permission, visible: :all)
+# end
+# end
+# else
+# within bulk_update_form(label_text) do
+# expect(page)
+# .to have_css(checked_permission, visible: :all)
+# end
+# end
+# end
+# end
+
+# def bulk_update_form(permission_name)
+# find("[data-test-selector='op-share-wp-bulk-update-role-permission-#{permission_name}']", visible: :all)
+# end
+
+# def checked_permission
+# 'button[type=submit][aria-checked=true]'
+# end
+
+# def unchecked_permission
+# 'button[type=submit][aria-checked="false"]'
+# end
+
+# def expect_blankslate
+# within_modal do
+# expect(page).to have_text(I18n.t('work_package.sharing.text_empty_state_description'))
+# end
+# end
+
+# def expect_empty_search_blankslate
+# within_modal do
+# expect(page).to have_text(I18n.t('work_package.sharing.text_empty_search_description'))
+# end
+# end
+
+# def invite_user(users, role_name)
+# Array(users).each do |user|
+# case user
+# when String
+# select_not_existing_user_option(user)
+# when Principal
+# select_existing_user(user)
+# end
+# end
+
+# select_invite_role(role_name)
+
+# within_modal do
+# click_button 'Share'
+# end
+# end
+
+# alias_method :invite_users, :invite_user
+# alias_method :invite_group, :invite_user
+
+# # Augments +invite_user+ by asserting that the modifications to the
+# # share have reflected in the modal's UI and we're able to continue
+# # with our spec without any waits or network related assertions.
+# #
+# # As a side benefit, it just keeps the spec file cleaner.
+# def invite_user!(user, role_name)
+# invite_user(user, role_name)
+# expect_shared_with(user, role_name)
+# end
+
+# def search_user(search_string)
+# search_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),
+# query: search_string,
+# results_selector: 'body'
+# end
+
+# def remove_user(user)
+# within user_row(user) do
+# click_button 'Remove'
+# end
+# end
+
+# def select_invite_role(role_name)
+# within modal_element.find('[data-test-selector="op-share-wp-invite-role"]') do
+# # Open the ActionMenu
+# click_button 'View'
+
+# find('.ActionListContent', text: role_name).click
+# end
+# end
+
+# def change_role(user, role_name)
+# within user_row(user) do
+# find('[data-test-selector="op-share-wp-update-role"]').click
+
+# within '.ActionListWrap' do
+# click_button role_name
+# end
+# end
+# end
+
+# def filter(filter_name, value)
+# within(shares_header) do
+# retry_block do
+# # The button's text changes dynamically based on the currently selected option
+# # Hence the spec's readability is hindered by using something like
+# # `click_button filter_name.capitalize`
+# find("[data-test-selector='op-share-wp-filter-#{filter_name}-button']").click
+
+# # Open the ActionMenu
+# find('.ActionListContent', text: value).click
+# end
+# end
+
+# wait_for_network_idle # Ensures filtering is done
+# end
+
+# def close
+# within_modal do
+# page.find("[data-test-selector='op-share-wp-modal--close-icon']").click
+# end
+# end
+
+# def click_share
+# within_modal do
+# click_button 'Share'
+# end
+# end
+
+# def expect_shared_with(user, role_name = nil, position: nil, editable: true)
+# within_modal do
+# within shares_list do
+# expect(page).to have_list_item(text: user.name, position:)
+# within(:list_item, text: user.name, position:) do
+# if role_name
+# expect(page).to have_button(role_name),
+# "Expected share with #{user.name.inspect} to have button #{role_name}."
+# end
+# unless editable
+# expect(page).not_to have_button,
+# "Expected share with #{user.name.inspect} not to be editable (expected no buttons)."
+# end
+# end
+# end
+# end
+# end
+
+# def expect_not_shared_with(*principals)
+# within shares_list do
+# principals.each do |principal|
+# expect(page)
+# .to have_no_text(principal.name)
+# end
+# end
+# end
+
+# def expect_shared_count_of(count)
+# expect(shares_header)
+# .to have_text(I18n.t('work_package.sharing.count', count:))
+# end
+
+# def expect_no_invite_option
+# within_modal do
+# expect(page)
+# .to have_text(I18n.t('work_package.sharing.permissions.denied'))
+# end
+# end
+
+# def resend_invite(user)
+# within user_row(user) do
+# click_button I18n.t("work_package.sharing.user_details.resend_invite")
+# end
+# end
+
+# def expect_invite_resent(user)
+# within user_row(user) do
+# expect(page)
+# .to have_text(I18n.t("work_package.sharing.user_details.invite_resent"))
+# end
+# end
+
+# def user_row(user)
+# within_modal do
+# find(:list_item, text: user.name)
+# end
+# end
+
+# def active_list
+# modal_element
+# .find('[data-test-selector="op-share-wp-active-list"]')
+# end
+
+# def shares_header
+# active_list.find('[data-test-selector="op-share-wp-header"]')
+# end
+
+# def shares_counter
+# shares_header.find('[data-test-selector="op-share-wp-active-count"]')
+# end
+
+# def shares_list
+# find_by_id('op-share-wp-active-shares')
+# end
+
+# def select_existing_user(user)
+# select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),
+# query: user.firstname,
+# select_text: user.name,
+# results_selector: 'body'
+# end
+
+# def select_not_existing_user_option(email)
+# select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),
+# query: email,
+# select_text: "Send invite to\"#{email}\"",
+# results_selector: 'body'
+# end
+
+# def expect_upsale_banner
+# within_modal do
+# expect(page)
+# .to have_text(I18n.t(:label_enterprise_addon))
+# end
+# end
+
+# def expect_no_user_limit_warning
+# within modal_element do
+# expect(page)
+# .to have_no_text(I18n.t('work_package.sharing.warning_user_limit_reached'), wait: 0)
+# end
+# end
+
+# def expect_user_limit_warning
+# within modal_element do
+# expect(page)
+# .to have_text(I18n.t('work_package.sharing.warning_user_limit_reached'))
+# end
+# end
+
+# def expect_error_message(text)
+# within modal_element do
+# expect(page)
+# .to have_css('[data-test-selector="op-share-wp-error-message"]',
+# text:)
+# end
+# end
+
+# def expect_select_a_user_hint
+# within modal_element do
+# expect(page)
+# .to have_text(I18n.t("work_package.sharing.warning_no_selected_user"))
+# end
+# end
+
+# def expect_no_select_a_user_hint
+# within modal_element do
+# expect(page)
+# .to have_no_text(I18n.t("work_package.sharing.warning_no_selected_user"), wait: 0)
+# end
+# end
+# end
+# end
+# end
diff --git a/spec/support/form_fields/primerized/autocomplete_field.rb b/spec/support/form_fields/primerized/autocomplete_field.rb
new file mode 100644
index 00000000000..ff62c7fcc86
--- /dev/null
+++ b/spec/support/form_fields/primerized/autocomplete_field.rb
@@ -0,0 +1,66 @@
+require_relative 'form_field'
+
+module FormFields
+ module Primerized
+ class AutocompleteField < FormField
+ ### actions
+
+ def select_option(*values)
+ values.each do |val|
+ field_container.find('.ng-select-container').click
+ expect(page).to have_css('.ng-option', text: val, visible: :all)
+ page.find('.ng-option', text: val, visible: :all).click
+ sleep 0.25 # still required?
+ end
+ end
+
+ def deselect_option(*values)
+ values.each do |val|
+ field_container.find('.ng-select-container').click
+ page.find('.ng-value', text: val, visible: :all).find('.ng-value-icon').click
+ sleep 0.25 # still required?
+ end
+ end
+
+ def search(text)
+ field_container.find('.ng-select-container input').set text
+ end
+
+ def clear
+ field_container.find('.ng-clear-wrapper', visible: :all).click
+ end
+
+ ### expectations
+
+ def expect_selected(*values)
+ values.each do |val|
+ expect(field_container).to have_css('.ng-value', text: val)
+ end
+ end
+
+ def expect_not_selected(*values)
+ values.each do |val|
+ expect(field_container).to have_no_css('.ng-value', text: val)
+ end
+ end
+
+ def expect_blank
+ expect(field_container).to have_css('.ng-value', count: 0)
+ end
+
+ def expect_no_option(option)
+ expect(page)
+ .to have_no_css('.ng-option', text: option, visible: :all)
+ end
+
+ def expect_option(option)
+ expect(page)
+ .to have_css('.ng-option', text: option, visible: :visible)
+ end
+
+ def expect_visible
+ expect(field_container).to have_css('ng-select')
+ end
+ end
+ end
+end
diff --git a/spec/support/form_fields/primerized/form_field.rb b/spec/support/form_fields/primerized/form_field.rb
new file mode 100644
index 00000000000..a97c67b7aef
--- /dev/null
+++ b/spec/support/form_fields/primerized/form_field.rb
@@ -0,0 +1,13 @@
+module FormFields
+ module Primerized
+ class FormField < FormFields::FormField
+ def property_name
+ if property.is_a? CustomField
+ property.attribute_name(:kebab_case)
+ else
+ property.to_s
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/pages/projects/show.rb b/spec/support/pages/projects/show.rb
index 8d685e8c514..a2c3cac9b14 100644
--- a/spec/support/pages/projects/show.rb
+++ b/spec/support/pages/projects/show.rb
@@ -50,6 +50,35 @@ module Pages
def toast_type
:rails
end
+
+ def visit_page
+ visit path
+ end
+
+ def within_async_loaded_sidebar(&)
+ within '#project-attributes-sidebar' do
+ expect(page).to have_css("[data-qa-selector='project-attributes-sidebar-async-content']")
+ yield
+ end
+ end
+
+ def within_custom_field_section_container(section, &)
+ within("[data-qa-selector='project-custom-field-section-#{section.id}']", &)
+ end
+
+ def within_custom_field_container(custom_field, &)
+ within("[data-qa-selector='project-custom-field-#{custom_field.id}']", &)
+ end
+
+ def open_edit_dialog_for_section(section)
+ within_async_loaded_sidebar do
+ within_custom_field_section_container(section) do
+ page.find("[data-qa-selector='project-custom-field-section-edit-button']").click
+ end
+ end
+
+ expect(page).to have_css("[data-qa-selector='async-dialog-content']", wait: 5)
+ end
end
end
end