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

[#62979] feature specs for filters

Tobias Dillmannfe1753e5d9ac
diff --git a/app/models/queries/work_packages/filter/project_phase_filter.rb b/app/models/queries/work_packages/filter/project_phase_filter.rb
index bf2c1720d5e..cc1607c2858 100644
--- a/app/models/queries/work_packages/filter/project_phase_filter.rb
+++ b/app/models/queries/work_packages/filter/project_phase_filter.rb
@@ -55,6 +55,7 @@ class Queries::WorkPackages::Filter::ProjectPhaseFilter < Queries::WorkPackages:
values.filter_map { |id| available_definitions[id.to_i] }
end
+ # TODO: copied over from ProjectPhaseSelect, refactor to use the same truth
def joins
Arel.sql(
<<~SQL.squish
@@ -68,6 +69,7 @@ class Queries::WorkPackages::Filter::ProjectPhaseFilter < Queries::WorkPackages:
GROUP BY wp.id
) AS active_phases ON active_phases.wp_id = work_packages.id
LEFT JOIN project_phase_definitions pd ON pd.id = active_phases.active_phase_definition_id
+ JOIN projects on projects.id = work_packages.project_id
SQL
)
end
diff --git a/spec/features/work_packages/table/project_phase_field_spec.rb b/spec/features/work_packages/table/project_phase_field_spec.rb
index 070a2ee56cb..d8a8964531d 100644
--- a/spec/features/work_packages/table/project_phase_field_spec.rb
+++ b/spec/features/work_packages/table/project_phase_field_spec.rb
@@ -76,6 +76,7 @@ RSpec.describe "Project phase field in the work package table", :js do
build(:public_query, user: current_user, project: work_package.project)
end
let(:query_columns) { %w(subject project_phase) }
+ let(:query_filters) { nil }
current_user { user }
@@ -84,11 +85,17 @@ RSpec.describe "Project phase field in the work package table", :js do
query.sort_criteria = sort_criteria if sort_criteria
query.group_by = group_by if group_by
query.filters.clear
+
+ if query_filters.present?
+ query_filters.each do |filter|
+ query.add_filter(filter[:name], filter[:operator], filter[:values])
+ end
+ end
+
query.show_hierarchies = false
query.save!
wp_table.visit_query query
- wp_table.expect_work_package_listed work_package
wait_for_network_idle
end
@@ -101,6 +108,45 @@ RSpec.describe "Project phase field in the work package table", :js do
wp_table.expect_work_package_with_attributes(wp_without_phase, { projectPhase: "-" })
end
+ describe "filtering" do
+ context "when filtering to include a phase" do
+ let(:query_filters) do
+ [{ name: "project_phase_definition_id", operator: "=", values: [phase_definition.id.to_s] }]
+ end
+
+ it "only shows work packages with this phase" do
+ wp_table.expect_work_package_listed(work_package)
+ wp_table.ensure_work_package_not_listed!(other_wp, wp_without_phase)
+ end
+ end
+
+ context "when filtering to include multiple phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "=",
+ values: [phase_definition.id.to_s, other_project_phase.definition.id.to_s]
+ }]
+ end
+
+ it "only shows work packages with these phases" do
+ wp_table.expect_work_package_listed(work_package, other_wp)
+ wp_table.ensure_work_package_not_listed!(wp_without_phase)
+ end
+ end
+
+ context "when filtering to exclude a phase" do
+ let(:query_filters) do
+ [{ name: "project_phase_definition_id", operator: "!", values: [other_project_phase.definition.id.to_s] }]
+ end
+
+ it "shows work packages with other phases or without a phase" do
+ wp_table.expect_work_package_listed(wp_without_phase, work_package)
+ wp_table.ensure_work_package_not_listed!(other_wp)
+ end
+ end
+ end
+
context "when sorting by project phase ASC" do
let(:sort_criteria) { [%w[project_phase asc]] }
@@ -174,6 +220,41 @@ RSpec.describe "Project phase field in the work package table", :js do
})
end
end
+
+ describe "filtering" do
+ context "when filtering to include multiple phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "=",
+ values: [phase_definition.id.to_s, other_project_phase.definition.id.to_s]
+ }]
+ end
+
+ it "does not consider inactive phases, even when you filter for them" do
+ wp_table.expect_work_package_listed(other_wp)
+ wp_table.ensure_work_package_not_listed!(wp_without_phase, work_package)
+ end
+ end
+
+ context "when filtering to exclude phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "!",
+ values: [phase_definition.id.to_s, other_project_phase.definition.id.to_s]
+ }]
+ end
+
+ it "only excludes active phases, inactive phases are treated like they are not there" do
+ # `work_package` is listed since its phase is inactive. The exclusion does not apply.
+ wp_table.expect_work_package_listed(wp_without_phase, work_package)
+
+ # successfully exclude the other work package:
+ wp_table.ensure_work_package_not_listed!(other_wp)
+ end
+ end
+ end
end
context "when viewing multiple projects" do
@@ -214,6 +295,49 @@ RSpec.describe "Project phase field in the work package table", :js do
})
end
end
+
+ describe "filtering" do
+ context "when filtering to include multiple phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "=",
+ # mind that project_phase_from_other_project refers to the same phase_definition, but is set to inactive
+ values: [phase_definition.id.to_s]
+ }]
+ end
+
+ it "does not consider inactive phases, even when you filter for them" do
+ wp_table.expect_work_package_listed(work_package)
+
+ # has no matching phase, not listed:
+ wp_table.ensure_work_package_not_listed!(wp_without_phase, other_wp)
+ # has the desired phase, but it's inactive, so not listed:
+ wp_table.ensure_work_package_not_listed!(wp_with_phase_from_another_project)
+ end
+ end
+
+ context "when filtering to exclude phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "!",
+ # mind that project_phase_from_other_project refers to the same phase_definition, but is set to inactive
+ values: [phase_definition.id.to_s]
+ }]
+ end
+
+ it "only excludes active phases, inactive phases are treated like they are not there" do
+ # The exclusion does not apply to the inactive phase:
+ wp_table.expect_work_package_listed(wp_with_phase_from_another_project)
+ # The exclusion does not apply if there is no phase at all:
+ wp_table.expect_work_package_listed(wp_without_phase, wp_from_another_project)
+
+ # This phase is active and thus excluded:
+ wp_table.ensure_work_package_not_listed!(work_package)
+ end
+ end
+ end
end
end
@@ -252,6 +376,40 @@ RSpec.describe "Project phase field in the work package table", :js do
})
end
end
+
+ describe "filtering" do
+ context "when filtering to include multiple phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "=",
+ values: [phase_definition.id.to_s, other_project_phase.definition.id.to_s]
+ }]
+ end
+
+ it "does not consider unviewable phases, even when you filter for them" do
+ wp_table.expect_work_package_listed(other_wp, work_package)
+
+ wp_table.ensure_work_package_not_listed!(wp_with_phase_from_another_project, wp_without_phase)
+ end
+ end
+
+ context "when filtering to exclude phases" do
+ let(:query_filters) do
+ [{
+ name: "project_phase_definition_id",
+ operator: "!",
+ values: [phase_definition.id.to_s, other_project_phase.definition.id.to_s]
+ }]
+ end
+
+ it "only excludes active phases, inactive phases are treated like they are not there" do
+ wp_table.expect_work_package_listed(wp_without_phase, wp_with_phase_from_another_project, wp_from_another_project)
+
+ wp_table.ensure_work_package_not_listed!(other_wp, work_package)
+ end
+ end
+ end
end
end