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

Fix project life cycle dialog specs

Dombi Attila1893e67906f7
diff --git a/app/services/project_life_cycle_steps/update_service.rb b/app/services/project_life_cycle_steps/update_service.rb
index a8a5a33aa92..5a3692caff3 100644
--- a/app/services/project_life_cycle_steps/update_service.rb
+++ b/app/services/project_life_cycle_steps/update_service.rb
@@ -28,5 +28,13 @@
module ProjectLifeCycleSteps
class UpdateService < ::BaseServices::Update
+ def after_perform(call)
+ life_cycle_step = call.result
+
+ project = life_cycle_step.project
+ project.touch_and_save_journals
+
+ call
+ end
end
end
diff --git a/modules/overviews/app/controllers/overviews/project_phases_controller.rb b/modules/overviews/app/controllers/overviews/project_phases_controller.rb
index e87528549a9..e666aea43aa 100644
--- a/modules/overviews/app/controllers/overviews/project_phases_controller.rb
+++ b/modules/overviews/app/controllers/overviews/project_phases_controller.rb
@@ -75,7 +75,8 @@ module ::Overviews
private
def find_project_phase_and_project
- @project_phase = Project::Phase.where(active: true).eager_load(:definition).find(params[:id])
+ @project_phase = Project::Phase.where(active: true).eager_load(:definition, :project).find(params[:id])
+ @project = @project_phase.project
rescue ActiveRecord::RecordNotFound
# TODO: Use rescue from in the controller, and remove all the rescue instances
render_404
diff --git a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
index b41cf2793a7..cd776f5b72f 100644
--- a/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
+++ b/spec/features/projects/life_cycle/overview_page/dialog/update_spec.rb
@@ -53,18 +53,14 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
end
it "shows all the Project::Phases without a value" do
- dialog = overview_page.open_edit_dialog_for_life_cycles
-
- dialog.expect_input("Initiating", value: "", position: 1)
- dialog.expect_input("Planning", value: "", position: 2)
- dialog.expect_input("Executing", value: "", position: 3)
- dialog.expect_input("Closing", value: "", position: 4)
+ project_life_cycles.each do |life_cycle|
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle)
+ dialog.expect_input(life_cycle.name, value: "")
- # Saving the dialog is successful
- dialog.submit
- dialog.expect_closed
+ dialog.submit # Saving the dialog is successful
+ dialog.expect_closed
+ end
- # Sidebar displays the same empty values
project_life_cycles.each do |life_cycle|
overview_page.within_life_cycle_container(life_cycle) do
expect(page).to have_text "-"
@@ -75,13 +71,12 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
context "when all LifeCycleSteps have a value" do
it "shows all the Project::Phases and updates them correctly" do
- dialog = overview_page.open_edit_dialog_for_life_cycles
+ # Set a value for life_cycle_initiating
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating)
expect_angular_frontend_initialized
- project.available_phases.each do |step|
- dialog.expect_input_for(step)
- end
+ dialog.expect_input_for(life_cycle_initiating)
initiating_dates = [start_date - 1.week, start_date]
@@ -98,6 +93,15 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
expect(page.driver.browser.network.traffic.size).to eq(1)
end
+ # Saving the dialog is successful
+ dialog.submit
+ dialog.expect_closed
+
+ # Clear the value of life_cycle_planning
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning)
+ expect_angular_frontend_initialized
+
+ dialog.expect_input_for(life_cycle_planning)
dialog.clear_date_for(life_cycle_planning)
# Saving the dialog is successful
@@ -140,66 +144,6 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
"#{I18n.l life_cycle_planning_was.finish_date}")
end
end
-
- it "shows the validation errors", with_settings: { journal_aggregation_time_minutes: 0 } do
- expect_angular_frontend_initialized
- wait_for_network_idle
-
- dialog = overview_page.open_edit_dialog_for_life_cycles
-
- expected_text = "Date range can't be earlier than the previous phase's end date."
-
- # Cycling is required so we always select a different date on the datepicker,
- # making sure the change event is triggered.
- cycled_days = [0, 1].cycle
-
- # Retrying due to a race condition between filling the input vs submitting the form preview.
- retry_block do
- values = [start_date + cycled_days.next.days] * 2
- dialog.set_date_for(life_cycle_planning, values:)
-
- dialog.expect_validation_message(life_cycle_planning, text: expected_text)
- end
-
- # Saving the dialog fails
- dialog.submit
- dialog.expect_open
-
- # The validation message is kept after the unsuccessful save attempt
- dialog.expect_validation_message(life_cycle_planning, text: expected_text)
-
- retry_block do
- # The validation message is cleared when date is changed
- values = [start_date + 2.days + cycled_days.next.days] * 2
- dialog.set_date_for(life_cycle_planning, values:)
- dialog.expect_no_validation_message(life_cycle_planning)
- end
-
- # Saving the dialog is successful
- dialog.submit
- dialog.expect_closed
-
- activity_page.visit!
-
- activity_page.show_details
-
- life_cycle_planning_was = life_cycle_planning.dup
- life_cycle_planning.reload
- activity_page.within_journal(number: 1) do
- expected_date_from = [
- I18n.l(life_cycle_planning_was.start_date),
- I18n.l(life_cycle_planning_was.finish_date)
- ].join(" - ")
-
- expected_date_to = [
- I18n.l(life_cycle_planning.start_date),
- I18n.l(life_cycle_planning.finish_date)
- ].join(" - ")
- activity_page.expect_activity("Planning changed from " \
- "#{expected_date_from} to " \
- "#{expected_date_to}")
- end
- end
end
context "when there is an invalid custom field on the project (Regression#60666)" do
@@ -211,7 +155,7 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
end
it "allows saving and closing the dialog without the custom field validation to interfere" do
- dialog = overview_page.open_edit_dialog_for_life_cycles
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating)
expect_angular_frontend_initialized
diff --git a/spec/support/components/projects/project_life_cycles/edit_dialog.rb b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
index 3837cbf17dd..4a22c6dd5a1 100644
--- a/spec/support/components/projects/project_life_cycles/edit_dialog.rb
+++ b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
@@ -50,7 +50,8 @@ module Components
end
def clear_date_for(step)
- find("input[id^='project_available_phases_attributes_#{step.position - 1}']").set ""
+ find("input[id^='project_phase_date_range']").set ""
+ find_by_id("edit-project-life-cycles-dialog-title").click
end
def set_date_for(step, values:)
@@ -59,7 +60,7 @@ module Components
datepicker = Components::RangeDatepicker.new(dialog_selector)
datepicker.open(
- "input[id^='project_available_phases_attributes_#{step.position - 1}']"
+ "input[id^='project_phase_date_range']"
)
values.each do |date|
@@ -98,12 +99,12 @@ module Components
expect(page).to have_css(async_content_container_css_selector)
end
- def expect_input(label, value:, position:)
+ def expect_input(label, value:)
within_async_content do
expect(page).to have_field(
label,
with: value,
- name: "project[available_phases_attributes][#{position - 1}][date_range]"
+ name: "project_phase[date_range]"
)
end
end
@@ -111,7 +112,7 @@ module Components
def expect_input_for(step)
value = "#{step.start_date.strftime('%Y-%m-%d')} - #{step.finish_date.strftime('%Y-%m-%d')}"
- expect_input(step.name, value:, position: step.position)
+ expect_input(step.name, value:)
end
def expect_caption(step, text: nil, present: true)
@@ -136,7 +137,7 @@ module Components
def expect_selector_for(step, selector:, text: nil, present: true)
within_async_content do
- input_id = "#project_available_phases_attributes_#{step.position - 1}_date_range"
+ input_id = "#project_phase_date_range"
parent = find(input_id).ancestor("primer-datepicker-field")
if present
diff --git a/spec/support/pages/projects/show.rb b/spec/support/pages/projects/show.rb
index 708d1525b9c..1d52305260f 100644
--- a/spec/support/pages/projects/show.rb
+++ b/spec/support/pages/projects/show.rb
@@ -85,9 +85,9 @@ module Pages
wait_for_size_animation_completion("[data-test-selector='async-dialog-content']")
end
- def open_edit_dialog_for_life_cycles
+ def open_edit_dialog_for_life_cycle(life_cycle)
within_life_cycles_sidebar do
- page.find("[data-test-selector='project-life-cycles-edit-button']").click
+ page.find("[data-test-selector='project-life-cycle-edit-button-#{life_cycle.id}']").click
end
Components::Projects::ProjectLifeCycles::EditDialog.new.tap(&:expect_open)