mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Fine-tune the shown forms of custom fields & fix tests
This commit is contained in:
@@ -84,8 +84,12 @@ module CustomFields
|
||||
end
|
||||
|
||||
def persisted_cf_has_no_items_or_projects?
|
||||
if custom_field.list? && custom_field.custom_options.empty? && custom_field.projects.empty?
|
||||
return true
|
||||
if custom_field.list? && custom_field.custom_options.empty?
|
||||
if custom_field.respond_to?(:projects)
|
||||
custom_field.projects.empty?
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
custom_field.persisted? &&
|
||||
|
||||
@@ -82,7 +82,6 @@ module CustomFields
|
||||
details_form.text_field(
|
||||
name: :regexp,
|
||||
label: label(:regexp),
|
||||
size: 50,
|
||||
caption: instructions(:regexp),
|
||||
input_width: :medium
|
||||
)
|
||||
@@ -238,7 +237,7 @@ module CustomFields
|
||||
end
|
||||
|
||||
def show_right_to_left_field?
|
||||
%w[text].include?(model.field_format)
|
||||
model.is_a?(WorkPackageCustomField) && %w[text].include?(model.field_format)
|
||||
end
|
||||
|
||||
def show_multi_value_field?
|
||||
@@ -258,7 +257,8 @@ module CustomFields
|
||||
end
|
||||
|
||||
def show_is_searchable_field?
|
||||
%w[bool date float int user version hierarchy weighted_item_list calculated_value].exclude?(model.field_format)
|
||||
(model.is_a?(WorkPackageCustomField) || model.is_a?(ProjectCustomField)) &&
|
||||
%w[bool date float int user version hierarchy weighted_item_list calculated_value].exclude?(model.field_format)
|
||||
end
|
||||
|
||||
def show_non_open_versions_field?
|
||||
|
||||
@@ -65,10 +65,10 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
flex.with_column do
|
||||
render Primer::Beta::Button.new(
|
||||
scheme: :primary,
|
||||
type: :submit,
|
||||
) do |button|
|
||||
type: :submit
|
||||
) do |button|
|
||||
button.with_leading_visual_icon(icon: :check)
|
||||
t(:button_submit)
|
||||
t(:button_save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,7 +93,7 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
no_label: true %>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<td class="custom-option-default-value">
|
||||
<%= co_f.check_box :default_value,
|
||||
container_class: "custom-option-default-value",
|
||||
data: {
|
||||
@@ -105,7 +105,7 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<td>
|
||||
<span class="reorder-icons">
|
||||
<a
|
||||
title="<%= t(:label_sort_highest) %>"
|
||||
aria-label="<%= t(:label_sort_highest) %>"
|
||||
rel="nofollow"
|
||||
href="#"
|
||||
class="sort-up-custom-option"
|
||||
@@ -113,7 +113,7 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<%= op_icon("icon-context icon-sort-up icon-small") %>
|
||||
</a>
|
||||
<a
|
||||
title="<%= t(:label_sort_higher) %>"
|
||||
aria-label="<%= t(:label_sort_higher) %>"
|
||||
rel="nofollow"
|
||||
href="#"
|
||||
class="move-up-custom-option"
|
||||
@@ -121,14 +121,14 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<%= op_icon("icon-context icon-arrow-up2 icon-small") %>
|
||||
</a>
|
||||
<a
|
||||
title="<%= t(:label_sort_lower) %>"
|
||||
aria-label="<%= t(:label_sort_lower) %>"
|
||||
rel="nofollow" href="#"
|
||||
class="move-down-custom-option"
|
||||
data-action="admin--custom-fields#moveRowDown">
|
||||
<%= op_icon("icon-context icon-arrow-down2 icon-small") %>
|
||||
</a>
|
||||
<a
|
||||
title="<%= t(:label_sort_lowest) %>"
|
||||
aria-label="<%= t(:label_sort_lowest) %>"
|
||||
rel="nofollow"
|
||||
href="#"
|
||||
class="sort-down-custom-option"
|
||||
|
||||
@@ -58,10 +58,10 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
flex.with_column do
|
||||
render Primer::Beta::Button.new(
|
||||
scheme: :primary,
|
||||
type: :submit,
|
||||
) do |button|
|
||||
type: :submit
|
||||
) do |button|
|
||||
button.with_leading_visual_icon(icon: :check)
|
||||
t(:button_submit)
|
||||
t(:button_save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,7 +41,5 @@ RSpec.describe "Edit project custom fields", :js do
|
||||
it_behaves_like "shows checkboxes for configuration" do
|
||||
let(:required_supported) { false }
|
||||
end
|
||||
it_behaves_like "editing the field" do
|
||||
let(:using_primer) { true }
|
||||
end
|
||||
it_behaves_like "editing the field"
|
||||
end
|
||||
|
||||
@@ -108,7 +108,7 @@ RSpec.describe "Create project custom fields in sections", :js do
|
||||
it "prevents creating a new project custom field with an empty name" do
|
||||
click_on("Save")
|
||||
|
||||
expect(page).to have_field "custom_field_name", validation_message: /Please fill (in|out) this field./
|
||||
expect(page).to have_field("custom_field_name", with: "", validation_error: "Name can't be blank")
|
||||
|
||||
# expect no redirect
|
||||
expect(page).to have_no_current_path(admin_settings_project_custom_fields_path(tab: "ProjectCustomField"))
|
||||
|
||||
@@ -232,12 +232,6 @@ end
|
||||
RSpec.shared_examples "editing the field" do
|
||||
current_user { admin }
|
||||
|
||||
let(:using_primer) do
|
||||
super()
|
||||
rescue NoMethodError
|
||||
false
|
||||
end
|
||||
|
||||
before do
|
||||
visit edit_admin_settings_project_custom_field_path(custom_field)
|
||||
end
|
||||
@@ -272,11 +266,7 @@ RSpec.shared_examples "editing the field" do
|
||||
fill_in("Name", with: "")
|
||||
click_on("Save")
|
||||
|
||||
if using_primer
|
||||
expect(page).to have_css(".FormControl-inlineValidation", text: "Name can't be blank")
|
||||
else
|
||||
expect(page).to have_field "Name", validation_message: /Please fill (in|out) this field./
|
||||
end
|
||||
expect(page).to have_field("custom_field_name", with: "", validation_error: "Name can't be blank")
|
||||
|
||||
expect(page).to have_no_text("Successful update")
|
||||
|
||||
|
||||
@@ -46,7 +46,14 @@ RSpec.shared_examples_for "list custom fields" do |type|
|
||||
cf_page.set_name "Operating System"
|
||||
|
||||
expect(page).to have_text("Allow multi-select")
|
||||
check("custom_field_multi_value")
|
||||
check("multi_value")
|
||||
|
||||
click_on "Save"
|
||||
cf_page.expect_and_dismiss_flash(message: "Successful creation.")
|
||||
expect(page).to have_field("multi_value", checked: true)
|
||||
|
||||
click_link "Items"
|
||||
wait_for_network_idle
|
||||
|
||||
expect(page).to have_css(".custom-option-row", count: 1)
|
||||
within all(".custom-option-row").last do
|
||||
@@ -73,15 +80,11 @@ RSpec.shared_examples_for "list custom fields" do |type|
|
||||
within all(".custom-option-row").last do
|
||||
find(".custom-option-value input").set "Solaris"
|
||||
|
||||
click_on "Move to top"
|
||||
click_link accessible_name: "Move to top"
|
||||
end
|
||||
|
||||
click_on "Save"
|
||||
|
||||
expect(page).to have_text("Successful creation")
|
||||
|
||||
expect(page).to have_field("custom_field_multi_value", checked: true)
|
||||
|
||||
expect(page).to have_css(".custom-option-row", count: 3)
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_0_value", with: "Solaris")
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_1_value", with: "Windows")
|
||||
@@ -271,11 +274,5 @@ RSpec.shared_examples_for "expected fields for the custom field's format", :aggr
|
||||
else
|
||||
expect(page).to have_no_label(label_allow_non_open_versions)
|
||||
end
|
||||
|
||||
if format == "List"
|
||||
expect(page).to have_fieldset(label_possible_values)
|
||||
else
|
||||
expect(page).to have_no_fieldset(label_possible_values)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,12 +50,17 @@ RSpec.describe "List custom fields edit", :js do
|
||||
|
||||
fill_in "custom_field_name", with: "My List CF"
|
||||
|
||||
click_on "Save"
|
||||
|
||||
index_cf_page.expect_and_dismiss_flash(message: "Successful creation.")
|
||||
|
||||
click_link "Items"
|
||||
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_0_value")
|
||||
fill_in "custom_field_custom_options_attributes_0_value", with: "A"
|
||||
|
||||
click_on "Save"
|
||||
|
||||
index_cf_page.expect_and_dismiss_flash(message: "Successful creation.")
|
||||
wait_for_network_idle
|
||||
|
||||
# Expect correct values
|
||||
cf = CustomField.last
|
||||
@@ -63,12 +68,11 @@ RSpec.describe "List custom fields edit", :js do
|
||||
expect(cf.possible_values.map(&:value)).to eq %w(A)
|
||||
|
||||
# Edit again
|
||||
find("a", text: "My List CF").click
|
||||
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_0_value")
|
||||
fill_in "custom_field_custom_options_attributes_0_value", with: "B"
|
||||
|
||||
click_on "Save"
|
||||
wait_for_network_idle
|
||||
|
||||
index_cf_page.expect_and_dismiss_flash(message: "Successful update.")
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ RSpec.describe "work package list custom fields", :js do
|
||||
|
||||
click_on custom_field.name
|
||||
wait_for_reload
|
||||
|
||||
click_link "Items"
|
||||
wait_for_reload
|
||||
end
|
||||
|
||||
it "adds new options" do
|
||||
@@ -97,17 +100,15 @@ RSpec.describe "work package list custom fields", :js do
|
||||
|
||||
fill_in("custom_field_custom_options_attributes_1_value", with: "")
|
||||
fill_in("custom_field_custom_options_attributes_1_value", with: "Sega")
|
||||
check("custom_field_multi_value")
|
||||
check("custom_field_custom_options_attributes_0_default_value")
|
||||
check("custom_field_custom_options_attributes_2_default_value")
|
||||
within first(".custom-option-row") do
|
||||
click_on "Move to bottom"
|
||||
click_link accessible_name: "Move to bottom"
|
||||
end
|
||||
click_on "Save"
|
||||
|
||||
expect(page).to have_text("Successful update")
|
||||
expect(page).to have_text("Platform")
|
||||
expect(page).to have_field("custom_field_multi_value", checked: true)
|
||||
|
||||
%w[Sega Nintendo PC Playstation].each_with_index do |value, i|
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_#{i}_value", with: value)
|
||||
@@ -116,7 +117,7 @@ RSpec.describe "work package list custom fields", :js do
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_0_default_value", checked: false)
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_1_default_value", checked: true)
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_2_default_value", checked: false)
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_3_default_value", checked: true)
|
||||
expect(page).to have_field("custom_field_custom_options_attributes_3_default_value", checked: false)
|
||||
end
|
||||
|
||||
it "shows the correct breadcrumbs" do
|
||||
|
||||
@@ -48,6 +48,12 @@ RSpec.describe "Multi-value custom fields creation", :js, :selenium do
|
||||
SeleniumHubWaiter.wait
|
||||
fill_in "custom_field_name", with: "My List CF"
|
||||
|
||||
click_on "Save"
|
||||
index_cf_page.expect_and_dismiss_flash(message: "Successful creation.")
|
||||
|
||||
click_link "Items"
|
||||
wait_for_network_idle
|
||||
|
||||
expect(page).to have_css("input#custom_field_custom_options_attributes_0_value")
|
||||
fill_in "custom_field_custom_options_attributes_0_value", with: "A"
|
||||
|
||||
@@ -65,11 +71,8 @@ RSpec.describe "Multi-value custom fields creation", :js, :selenium do
|
||||
|
||||
click_on "Save"
|
||||
|
||||
index_cf_page.expect_and_dismiss_flash(message: "Successful creation.")
|
||||
|
||||
# Edit again
|
||||
SeleniumHubWaiter.wait
|
||||
page.find("a", text: "My List CF").click
|
||||
expect(page).to have_css("input#custom_field_custom_options_attributes_0_value[value=A]")
|
||||
expect(page).to have_css("input#custom_field_custom_options_attributes_1_value[value=B]")
|
||||
expect(page).to have_css("input#custom_field_custom_options_attributes_2_value[value=C]")
|
||||
|
||||
@@ -37,6 +37,10 @@ RSpec.describe "Reordering custom options of a list custom field", :js, :seleniu
|
||||
cf_page.visit!
|
||||
click_link custom_field.name
|
||||
|
||||
wait_for_network_idle
|
||||
click_link "Items"
|
||||
wait_for_network_idle
|
||||
|
||||
click_link "Reorder values alphabetically"
|
||||
cf_page.accept_alert_dialog!
|
||||
expect_flash(message: I18n.t(:notice_successful_update))
|
||||
|
||||
@@ -153,17 +153,6 @@ RSpec.describe CustomField do
|
||||
end
|
||||
end
|
||||
|
||||
describe "WITH a list field WITHOUT a custom option" do
|
||||
before do
|
||||
field.field_format = "list"
|
||||
end
|
||||
|
||||
it "is not valid" do
|
||||
expect(field)
|
||||
.not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "WITH a list field WITH a custom option" do
|
||||
before do
|
||||
field.field_format = "list"
|
||||
|
||||
@@ -53,7 +53,7 @@ module Pages
|
||||
end
|
||||
|
||||
def set_all_projects(value)
|
||||
find_by_id("custom_field_is_for_all").set value
|
||||
find_by_id("is_for_all").set value
|
||||
end
|
||||
|
||||
def has_form_element?(name)
|
||||
|
||||
Reference in New Issue
Block a user