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

Add sidebar specs for displaying life cycles

Dombi Attila9b82812d4ec7
diff --git a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb
index 3687f4b162f..0cff2b6d13a 100644
--- a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb
+++ b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb
@@ -49,11 +49,14 @@ module ProjectLifeCycles
case @life_cycle_step
when Project::Gate
render(Primer::Beta::Text.new) do
- concat @life_cycle_step.date
+ concat helpers.format_date(@life_cycle_step.date)
end
when Project::Stage
render(Primer::Beta::Text.new) do
- concat [@life_cycle_step.start_date, " - ", @life_cycle_step.end_date].join
+ concat [
+ helpers.format_date(@life_cycle_step.start_date),
+ helpers.format_date(@life_cycle_step.end_date)
+ ].join(" - ")
end
end
end
diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
index 22335c8562c..25c27bb2945 100644
--- a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
+++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
@@ -37,7 +37,8 @@ module ProjectLifeCycles
super
@project = project
- @life_cycle_steps = @project.life_cycle_steps.active.includes(:definition)
+ @life_cycle_steps =
+ @project.life_cycle_steps.active.eager_load(:definition).order(position: :asc)
end
private
diff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rb
index 07eba12d7c4..368a388eb9f 100644
--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb
+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb
@@ -98,7 +98,10 @@ module ::Overviews
@custom_fields_sidebar_enabled =
User.current.allowed_in_project?(:view_project_attributes, @project) &&
@project.project_custom_fields.visible.any?
- @life_cycles_sidebar_enabled = OpenProject::FeatureDecisions.stages_and_gates_active?
+ @life_cycles_sidebar_enabled =
+ OpenProject::FeatureDecisions.stages_and_gates_active? &&
+ User.current.allowed_in_project?(:view_project_stages_and_gates, @project) &&
+ @project.life_cycle_steps.active.any?
end
def handle_errors(project_with_errors, section)
diff --git a/spec/features/projects/life_cycle/overview_page/shared_context.rb b/spec/features/projects/life_cycle/overview_page/shared_context.rb
new file mode 100644
index 00000000000..89aaa454e34
--- /dev/null
+++ b/spec/features/projects/life_cycle/overview_page/shared_context.rb
@@ -0,0 +1,103 @@
+#-- 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 seeded projects and stages and gates" do
+ shared_let(:project) { create(:project, name: "Foo project", identifier: "foo-project") }
+ shared_let(:standard) { create(:standard_global_role) }
+ shared_let(:admin) { create(:admin) }
+
+ shared_let(:life_cycle_initiating_definition) do
+ create :project_stage_definition, name: "Initiating"
+ end
+ shared_let(:life_cycle_ready_for_planning_definition) do
+ create :project_gate_definition, name: "Ready for Planning"
+ end
+ shared_let(:life_cycle_planning_definition) do
+ create :project_stage_definition, name: "Planning"
+ end
+ shared_let(:life_cycle_ready_for_executing_definition) do
+ create :project_gate_definition, name: "Ready for Executing"
+ end
+ shared_let(:life_cycle_executing_definition) do
+ create :project_stage_definition, name: "Executing"
+ end
+ shared_let(:life_cycle_ready_for_closing_definition) do
+ create :project_gate_definition, name: "Ready for Closing"
+ end
+ shared_let(:life_cycle_closing_definition) do
+ create :project_stage_definition, name: "Closing"
+ end
+
+ let(:life_cycle_initiating) do
+ create :project_stage,
+ definition: life_cycle_initiating_definition,
+ project:
+ end
+ let(:life_cycle_ready_for_planning) do
+ create :project_gate,
+ definition: life_cycle_ready_for_planning_definition,
+ project:
+ end
+ let(:life_cycle_planning) do
+ create :project_stage,
+ definition: life_cycle_planning_definition,
+ project:
+ end
+ let(:life_cycle_ready_for_executing) do
+ create :project_gate,
+ definition: life_cycle_ready_for_executing_definition,
+ project:
+ end
+ let(:life_cycle_executing) do
+ create :project_stage,
+ definition: life_cycle_executing_definition,
+ project:
+ end
+ let(:life_cycle_ready_for_closing) do
+ create :project_gate,
+ definition: life_cycle_ready_for_closing_definition,
+ project:
+ end
+ let(:life_cycle_closing) do
+ create :project_stage,
+ definition: life_cycle_closing_definition,
+ project:
+ end
+
+ let!(:project_life_cycles) do
+ [
+ life_cycle_initiating,
+ life_cycle_ready_for_planning,
+ life_cycle_planning,
+ life_cycle_ready_for_executing,
+ life_cycle_executing,
+ life_cycle_ready_for_closing,
+ life_cycle_closing
+ ]
+ end
+end
diff --git a/spec/features/projects/life_cycle/overview_page/sidebar_spec.rb b/spec/features/projects/life_cycle/overview_page/sidebar_spec.rb
index 3e1107cdc7b..0b0b946e519 100644
--- a/spec/features/projects/life_cycle/overview_page/sidebar_spec.rb
+++ b/spec/features/projects/life_cycle/overview_page/sidebar_spec.rb
@@ -27,10 +27,10 @@
#++
require "spec_helper"
+require_relative "shared_context"
RSpec.describe "Show project life cycles on project overview page", :js, :with_cuprite, with_flag: { stages_and_gates: true } do
- shared_let(:admin) { create(:admin) }
- shared_let(:project) { create(:project, name: "Foo project", identifier: "foo-project") }
+ include_context "with seeded projects and stages and gates"
let(:overview_page) { Pages::Projects::Show.new(project) }
@@ -40,18 +40,113 @@ RSpec.describe "Show project life cycles on project overview page", :js, :with_c
it "does show the sidebar" do
overview_page.visit_page
+ overview_page.expect_visible_sidebar
+ end
- within ".op-grid-page" do
- expect(page).to have_css(".op-grid-page--sidebar")
+ context "when stages and gates are disabled", with_flag: { stages_and_gates: false } do
+ it "does not show the sidebar" do
+ overview_page.visit_page
+ overview_page.expect_no_visible_sidebar
end
end
- context "when stages and gates are disabled", with_flag: { stages_and_gates: false } do
+ context "when all stages and gates are disabled for this project" do
+ before do
+ project_life_cycles.each { |p| p.toggle!(:active) }
+ end
+
it "does not show the sidebar" do
overview_page.visit_page
+ overview_page.expect_no_visible_sidebar
+ end
+ end
+
+ describe "with correct order and scoping" do
+ it "shows the project stages and gates in the correct order" do
+ overview_page.visit_page
+
+ overview_page.within_life_cycles_sidebar do
+ fields = page.all(".op-project-life-cycle-container")
+
+ expect(fields.size).to eq(7)
+
+ expect(fields[0].text).to include("Initiating")
+ expect(fields[1].text).to include("Ready for Planning")
+ expect(fields[2].text).to include("Planning")
+ expect(fields[3].text).to include("Ready for Executing")
+ expect(fields[4].text).to include("Executing")
+ expect(fields[5].text).to include("Ready for Closing")
+ expect(fields[6].text).to include("Closing")
+ end
+
+ life_cycle_ready_for_executing_definition.move_to_bottom
+
+ overview_page.visit_page
+
+ overview_page.within_life_cycles_sidebar do
+ fields = page.all(".op-project-life-cycle-container")
+
+ expect(fields.size).to eq(7)
+
+ expect(fields[0].text).to include("Initiating")
+ expect(fields[1].text).to include("Ready for Planning")
+ expect(fields[2].text).to include("Planning")
+ expect(fields[3].text).to include("Executing")
+ expect(fields[4].text).to include("Ready for Closing")
+ expect(fields[5].text).to include("Closing")
+ expect(fields[6].text).to include("Ready for Executing")
+ end
+ end
+
+ it "does not show stages and gates not enabled for this project in a sidebar" do
+ life_cycle_ready_for_executing.toggle!(:active)
+
+ overview_page.visit_page
+
+ overview_page.within_life_cycles_sidebar do
+ expect(page).to have_no_text life_cycle_ready_for_executing.name
+ end
+ end
+ end
+
+ describe "with correct values" do
+ describe "with values set" do
+ it "shows the correct value for the project custom field if given" do
+ overview_page.visit_page
+
+ overview_page.within_life_cycles_sidebar do
+ project_life_cycles.each do |life_cycle|
+ overview_page.within_life_cycle_container(life_cycle) do
+ expected_date = if life_cycle.is_a? Project::Stage
+ [
+ life_cycle.start_date.strftime("%m/%d/%Y"),
+ life_cycle.end_date.strftime("%m/%d/%Y")
+ ].join(" - ")
+ else
+ life_cycle.start_date.strftime("%m/%d/%Y")
+ end
+ expect(page).to have_text expected_date
+ end
+ end
+ end
+ end
+ end
+
+ describe "with no values" do
+ before do
+ Project::LifeCycleStep.update_all(start_date: nil, end_date: nil)
+ end
+
+ it "shows the correct value for the project custom field if given" do
+ overview_page.visit_page
- within ".op-grid-page" do
- expect(page).to have_no_css(".op-grid-page--sidebar")
+ overview_page.within_life_cycles_sidebar do
+ project_life_cycles.each do |life_cycle|
+ overview_page.within_life_cycle_container(life_cycle) do
+ expect(page).to have_text I18n.t("placeholders.default")
+ end
+ end
+ end
end
end
end
diff --git a/spec/support/pages/projects/show.rb b/spec/support/pages/projects/show.rb
index 9cf4b2f662e..fb246d90ec5 100644
--- a/spec/support/pages/projects/show.rb
+++ b/spec/support/pages/projects/show.rb
@@ -56,6 +56,11 @@ module Pages
expect(page).to have_no_css(".op-grid-page--grid-container")
end
+ def expect_visible_sidebar
+ expect_angular_frontend_initialized
+ expect(page).to have_css(".op-grid-page--grid-container")
+ end
+
def within_project_attributes_sidebar(&)
within "#project-custom-fields-sidebar" do
expect(page).to have_css("[data-test-selector='project-custom-fields-sidebar-async-content']")
@@ -82,6 +87,17 @@ module Pages
expect(page).to have_css("[data-test-selector='async-dialog-content']", wait: 5)
end
+ def within_life_cycles_sidebar(&)
+ within "#project-life-cycles-sidebar" do
+ expect(page).to have_css("[data-test-selector='project-life-cycles-sidebar-async-content']")
+ yield
+ end
+ end
+
+ def within_life_cycle_container(life_cycle, &)
+ within("[data-test-selector='project-life-cycle-#{life_cycle.id}']", &)
+ end
+
def expand_text(custom_field)
within_custom_field_container(custom_field) do
page.find('[data-test-selector="expand-button"]').click