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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add initial form specs for CustomField::Inputs
Alexander Brandon Colesbeb6ecfa7fbb
diff --git a/spec/forms/custom_fields/inputs/bool_spec.rb b/spec/forms/custom_fields/inputs/bool_spec.rbnew file mode 100644index 00000000000..6fb9fb34d89--- /dev/null+++ b/spec/forms/custom_fields/inputs/bool_spec.rb@@ -0,0 +1,61 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::Bool, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:boolean_project_custom_field, name: "Boolean field") }++ it_behaves_like "rendering label", "Boolean field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_unchecked_field "Boolean field", with: "1"+ end+ end++ context "when value is true" do+ let(:value) { true }++ it "renders field" do+ expect(rendered_form).to have_checked_field "Boolean field", with: "1"+ end+ end++ context "when value is false" do+ let(:value) { false }++ it "renders field" do+ expect(rendered_form).to have_unchecked_field "Boolean field", with: "1"+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/date_spec.rb b/spec/forms/custom_fields/inputs/date_spec.rbnew file mode 100644index 00000000000..b682b6fb51b--- /dev/null+++ b/spec/forms/custom_fields/inputs/date_spec.rb@@ -0,0 +1,65 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::Date, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:date_project_custom_field, name: "Date field") }++ it_behaves_like "rendering label", "Date field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_field "Date field", type: :date, with: ""+ end+ end++ context "when value is invalid" do+ let(:value) { "NOT A DATE" }++ it "renders invalid field" do+ expect(rendered_form).to have_field "Date field", type: :date, with: "NOT A DATE", aria: { invalid: true }+ end++ it "renders error message" do+ expect(rendered_form).to have_css ".FormControl-inlineValidation", text: "Value is not a valid date."+ end+ end++ context "when value is valid" do+ let(:value) { Date.civil(2024, 3, 20) }++ it "renders field" do+ expect(rendered_form).to have_field "Date field", type: :date, with: "2024-03-20"+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/float_spec.rb b/spec/forms/custom_fields/inputs/float_spec.rbnew file mode 100644index 00000000000..0cc5b13dc1e--- /dev/null+++ b/spec/forms/custom_fields/inputs/float_spec.rb@@ -0,0 +1,53 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::Float, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:float_project_custom_field, name: "Float field") }++ it_behaves_like "rendering label", "Float field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_field "Float field", type: :number, with: ""+ end+ end++ context "with a value" do+ let(:value) { 78.23 }++ it "renders field" do+ expect(rendered_form).to have_field "Float field", type: :number, with: "78.23"+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/int_spec.rb b/spec/forms/custom_fields/inputs/int_spec.rbnew file mode 100644index 00000000000..b6ff9bf155d--- /dev/null+++ b/spec/forms/custom_fields/inputs/int_spec.rb@@ -0,0 +1,53 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::Int, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:integer_project_custom_field, name: "Integer field") }++ it_behaves_like "rendering label", "Integer field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_field "Integer field", type: :number, with: ""+ end+ end++ context "with a value" do+ let(:value) { 76 }++ it "renders field" do+ expect(rendered_form).to have_field "Integer field", type: :number, with: "76"+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/multi_select_list_spec.rb b/spec/forms/custom_fields/inputs/multi_select_list_spec.rbnew file mode 100644index 00000000000..66ca952c682--- /dev/null+++ b/spec/forms/custom_fields/inputs/multi_select_list_spec.rb@@ -0,0 +1,54 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::MultiSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) do+ create(+ :list_project_custom_field,+ name: "Multi-list field",+ multi_value: true,+ possible_values: ["uno", "due", "tre", "quattro"]+ )+ end+ let(:value) { custom_field.possible_values.last(2).pluck(:id) }++ it_behaves_like "rendering label", "Multi-list field"+ it_behaves_like "rendering autocompleter", "Multi-list field", multiple: true do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-items"]).to have_json_size(4)+ expect(autocompleter["data-model"]).to have_json_size(2)+ expect(autocompleter["data-model"]).to be_json_eql(%{[{"name": "tre"}, {"name": "quattro"}]})+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/multi_user_select_list_spec.rb b/spec/forms/custom_fields/inputs/multi_user_select_list_spec.rbnew file mode 100644index 00000000000..eeb52a903a1--- /dev/null+++ b/spec/forms/custom_fields/inputs/multi_user_select_list_spec.rb@@ -0,0 +1,48 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::MultiUserSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:user_project_custom_field, name: "Users field", multi_value: true) }+ let(:value) { create_list(:user, 2) }++ it_behaves_like "rendering label", "Users field"+ it_behaves_like "rendering autocompleter", "Users field", tag_name: "opce-user-autocompleter", multiple: true do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-resource"]).to be_json_eql(%{"principals"})+ expect(autocompleter["data-url"]).to be_json_eql(%{"/api/v3/principals"})+ expect(autocompleter["data-input-value"]).to have_json_size(2)+ expect(autocompleter["data-input-value"]).to be_json_eql(value.pluck(:id).map(&:to_s).to_json)+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/multi_version_select_list_spec.rb b/spec/forms/custom_fields/inputs/multi_version_select_list_spec.rbnew file mode 100644index 00000000000..0a97a4193da--- /dev/null+++ b/spec/forms/custom_fields/inputs/multi_version_select_list_spec.rb@@ -0,0 +1,48 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::MultiVersionSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:version_project_custom_field, name: "Versions field", multi_value: true) }+ let(:value) { create_list(:version, 2, project: model) }+ let!(:other_versions) { create_list(:version, 3, project: model) }++ it_behaves_like "rendering label", "Versions field"+ it_behaves_like "rendering autocompleter", "Versions field", multiple: true do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-items"]).to have_json_size(5)+ expect(autocompleter["data-model"]).to have_json_size(2)+ expect(autocompleter["data-model"]).to be_json_eql(value.map { it.slice(:name) }.to_json).excluding("group_by")+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/single_select_list_spec.rb b/spec/forms/custom_fields/inputs/single_select_list_spec.rbnew file mode 100644index 00000000000..c1e8970abe6--- /dev/null+++ b/spec/forms/custom_fields/inputs/single_select_list_spec.rb@@ -0,0 +1,46 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::SingleSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:list_project_custom_field, name: "List field", possible_values: ["eins", "zwei", "drei"]) }+ let(:value) { custom_field.possible_values.first.id }++ it_behaves_like "rendering label", "List field"+ it_behaves_like "rendering autocompleter", "List field" do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-items"]).to have_json_size(3)+ expect(autocompleter["data-model"]).to be_json_eql(%{{"name": "eins"}})+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/single_user_select_list_spec.rb b/spec/forms/custom_fields/inputs/single_user_select_list_spec.rbnew file mode 100644index 00000000000..b29befca542--- /dev/null+++ b/spec/forms/custom_fields/inputs/single_user_select_list_spec.rb@@ -0,0 +1,47 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::SingleUserSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:user_project_custom_field, name: "User field") }+ let(:value) { create(:user) }++ it_behaves_like "rendering label", "User field"+ it_behaves_like "rendering autocompleter", "User field", tag_name: "opce-user-autocompleter" do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-resource"]).to be_json_eql(%{"principals"})+ expect(autocompleter["data-url"]).to be_json_eql(%{"/api/v3/principals"})+ expect(autocompleter["data-input-value"]).to be_json_eql(%{"#{value.id}"})+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/single_version_select_list_spec.rb b/spec/forms/custom_fields/inputs/single_version_select_list_spec.rbnew file mode 100644index 00000000000..9eb53e41504--- /dev/null+++ b/spec/forms/custom_fields/inputs/single_version_select_list_spec.rb@@ -0,0 +1,46 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::SingleVersionSelectList, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:version_project_custom_field, name: "Version field") }+ let(:value) { create(:version, name: "Version 26", project: model) }++ it_behaves_like "rendering label", "Version field"+ it_behaves_like "rendering autocompleter", "Version field" do+ it "sets correct autocompleter inputs" do+ expect(autocompleter["data-items"]).to have_json_size(1)+ expect(autocompleter["data-model"]).to be_json_eql(%{{"name":"Version 26"}}).excluding("group_by")+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/string_spec.rb b/spec/forms/custom_fields/inputs/string_spec.rbnew file mode 100644index 00000000000..90e4aebffb7--- /dev/null+++ b/spec/forms/custom_fields/inputs/string_spec.rb@@ -0,0 +1,89 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::String, type: :forms do+ include_context "with rendered custom field input form"++ context "with a string custom field" do+ let(:custom_field) { create(:string_project_custom_field, name: "String field") }++ it_behaves_like "rendering label", "String field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_field "String field", type: :text, with: ""+ end+ end++ context "when value is empty" do+ let(:value) { "" }++ it "renders field" do+ expect(rendered_form).to have_field "String field", type: :text, with: ""+ end+ end++ context "when value is present" do+ let(:value) { "weil wir es uns wert sind" }++ it "renders field" do+ expect(rendered_form).to have_field "String field", type: :text, with: "weil wir es uns wert sind"+ end+ end+ end++ context "with a link custom field" do+ let(:custom_field) { create(:link_project_custom_field, name: "Link field") }++ it_behaves_like "rendering label", "Link field"++ context "when value is invalid" do+ let(:value) { "!@£$ NOT A LINK" }++ it "renders invalid field" do+ expect(rendered_form).to have_field "Link field", type: :text, with: "!@£$ NOT A LINK", aria: { invalid: true }+ end++ it "renders error message" do+ expect(rendered_form).to have_css ".FormControl-inlineValidation", text: "Value is not a valid URL."+ end+ end++ context "when value is present" do+ let(:value) { "https://developer.mozilla.org/en-US/docs/" }++ it "renders field" do+ expect(rendered_form).to have_field "Link field", type: :text, with: "https://developer.mozilla.org/en-US/docs/"+ end+ end+ end+enddiff --git a/spec/forms/custom_fields/inputs/text_spec.rb b/spec/forms/custom_fields/inputs/text_spec.rbnew file mode 100644index 00000000000..80d9d042844--- /dev/null+++ b/spec/forms/custom_fields/inputs/text_spec.rb@@ -0,0 +1,61 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe CustomFields::Inputs::Text, type: :forms do+ include_context "with rendered custom field input form"++ let(:custom_field) { create(:text_project_custom_field, name: "Text field") }++ it_behaves_like "rendering label", "Text field"++ context "without a value" do+ it "renders field" do+ expect(rendered_form).to have_field "Text field", type: :textarea, with: "", visible: :hidden+ end+ end++ context "when value is empty" do+ let(:value) { "" }++ it "renders field" do+ expect(rendered_form).to have_field "Text field", type: :textarea, with: "", visible: :hidden+ end+ end++ context "when value is present" do+ let(:value) { "parce que nous le valons bien" }++ it "renders field" do+ expect(rendered_form).to have_field "Text field", type: :textarea, with: "parce que nous le valons bien", visible: :hidden+ end+ end+enddiff --git a/spec/support/forms/rendered_custom_field_input_form.rb b/spec/support/forms/rendered_custom_field_input_form.rbnew file mode 100644index 00000000000..7be4abc7cc4--- /dev/null+++ b/spec/support/forms/rendered_custom_field_input_form.rb@@ -0,0 +1,79 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#+++RSpec.shared_context "with rendered custom field input form" do+ include ViewComponent::TestHelpers++ let(:model) { create(:project) }+ let!(:custom_field_mapping) do+ create(:project_custom_field_project_mapping, project: model, project_custom_field: custom_field)+ end+ let(:value) { nil }++ current_user { build_stubbed(:admin) }++ def build_form(builder)+ described_class.new(builder, custom_field:, object: model)+ end++ def render_form+ render_in_view_context(model, self) do |model, spec_context|+ primer_form_with(url: "/foo", model:) do |f|+ render(spec_context.build_form(f))+ end+ end+ end++ before do+ model.custom_field_values = { "#{custom_field.id}": value } if value+ model.custom_field_values.first.valid?+ end++ subject(:rendered_form) do+ render_form+ page+ end++ shared_examples "rendering label" do |label_text|+ it "renders a label" do+ expect(rendered_form).to have_element :label, text: label_text+ end+ end++ shared_examples "rendering autocompleter" do |label_text, tag_name: "opce-autocompleter", multiple: false|+ let(:label_id) { rendered_form.find(:element, :label, text: label_text)["for"] }+ let(:autocompleter) { rendered_form.find(:element, tag_name, "data-label-for-id": "\"#{label_id}\"") }++ it "renders autocompleter field" do+ expect(rendered_form).to have_element tag_name, "data-label-for-id": "\"#{label_id}\"" do |autocompleter|+ expect(autocompleter["data-multiple"]).to be_json_eql(multiple)+ end+ end+ end+end