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

include feature specs for hierarchy filter

Bruno Pagnobe3b2184e388
diff --git a/spec/factories/custom_field_factory.rb b/spec/factories/custom_field_factory.rb
index ace2dada955..a849b8432da 100644
--- a/spec/factories/custom_field_factory.rb
+++ b/spec/factories/custom_field_factory.rb
@@ -165,6 +165,10 @@ FactoryBot.define do
field_format { "link" }
end
+ trait :hierarchy do
+ field_format { "hierarchy" }
+ end
+
factory :project_custom_field, class: "ProjectCustomField" do
project_custom_field_section
@@ -227,6 +231,7 @@ FactoryBot.define do
factory :user_wp_custom_field, traits: [:user]
factory :multi_user_wp_custom_field, traits: [:multi_user]
factory :link_wp_custom_field, traits: [:link]
+ factory :hierarchy_wp_custom_field, traits: [:hierarchy]
end
factory :issue_custom_field, class: "WorkPackageCustomField" do
diff --git a/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb b/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb
new file mode 100644
index 00000000000..579f78aa65c
--- /dev/null
+++ b/spec/features/work_packages/table/queries/hierarchy_cf_filter_spec.rb
@@ -0,0 +1,96 @@
+#-- 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 "Work package filtering by user custom field", :js do
+ let(:project) { create(:project) }
+ let(:type) { project.types.first }
+ let(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let(:filters) { Components::WorkPackages::Filters.new }
+ let(:hierarchy_root) { create(:hierarchy_item) }
+ let!(:hierarchy_cf) do
+ create(:hierarchy_wp_custom_field, hierarchy_root:).tap do |cf|
+ type.custom_fields << cf
+ project.work_package_custom_fields << cf
+ end
+ end
+ let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }
+ let!(:luke) { service.insert_item(parent: hierarchy_root, label: "luke").value! }
+ let!(:leia) { service.insert_item(parent: hierarchy_root, label: "leia").value! }
+
+ let!(:wp_luke) do
+ create(:work_package, project:, subject: "Luke's wp").tap do |wp|
+ wp.custom_field_values = { hierarchy_cf.id => luke.id }
+ wp.save!
+ end
+ end
+ let!(:wp_leia) do
+ create(:work_package, project:, subject: "Leia's wp").tap do |wp|
+ wp.custom_field_values = { hierarchy_cf.id => leia.id }
+ wp.save!
+ end
+ end
+
+ let(:admin) { create(:admin) }
+
+ current_user { admin }
+
+ describe "filters" do
+ before do
+ wp_table.visit!
+ wp_table.expect_work_package_listed(wp_luke, wp_leia)
+ end
+
+ context "when any" do
+ it "shows the work package matching the hierarchy cf filter" do
+ filters.open
+
+ # Filtering by hierarchy (=)
+
+ filters.add_filter_by(hierarchy_cf.name, "is", [luke.label], hierarchy_cf.attribute_name(:camel_case))
+
+ wp_table.ensure_work_package_not_listed!(wp_leia)
+ wp_table.expect_work_package_listed(wp_luke)
+ end
+ end
+
+ context "when is not" do
+ it "is not" do
+ filters.open
+
+ # Filtering by hierarchy (!)
+
+ filters.add_filter_by(hierarchy_cf.name, "is not", [luke.label], hierarchy_cf.attribute_name(:camel_case))
+
+ wp_table.ensure_work_package_not_listed!(wp_luke)
+ wp_table.expect_work_package_listed(wp_leia)
+ end
+ end
+ end
+end