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
[#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.rbindex 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 truthdef joinsArel.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.idLEFT JOIN project_phase_definitions pd ON pd.id = active_phases.active_phase_definition_id+ JOIN projects on projects.id = work_packages.project_idSQL)enddiff --git a/spec/features/work_packages/table/project_phase_field_spec.rb b/spec/features/work_packages/table/project_phase_field_spec.rbindex 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 dobuild(:public_query, user: current_user, project: work_package.project)endlet(: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 doquery.sort_criteria = sort_criteria if sort_criteriaquery.group_by = group_by if group_byquery.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 = falsequery.save!wp_table.visit_query query- wp_table.expect_work_package_listed work_packagewait_for_network_idleend@@ -101,6 +108,45 @@ RSpec.describe "Project phase field in the work package table", :js dowp_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" dolet(:sort_criteria) { [%w[project_phase asc]] }@@ -174,6 +220,41 @@ RSpec.describe "Project phase field in the work package table", :js do})endend++ 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+ endendcontext "when viewing multiple projects" do@@ -214,6 +295,49 @@ RSpec.describe "Project phase field in the work package table", :js do})endend++ 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+ endendend@@ -252,6 +376,40 @@ RSpec.describe "Project phase field in the work package table", :js do})endend++ 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+ endendend