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 bug validation message is not shown when a following phase has a default start date and an invalid finsih date

Dombi Attilaf7efe3d777ce
diff --git a/app/services/project_life_cycle_steps/set_attributes_service.rb b/app/services/project_life_cycle_steps/set_attributes_service.rb
index fb2bb481b05..3e4c5871a37 100644
--- a/app/services/project_life_cycle_steps/set_attributes_service.rb
+++ b/app/services/project_life_cycle_steps/set_attributes_service.rb
@@ -29,8 +29,8 @@
module ProjectLifeCycleSteps
class SetAttributesService < ::BaseServices::SetAttributes
def perform(*)
+ model.set_default_start_date
super.tap do
- model.set_default_start_date
model.set_calculated_duration
end
end
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 8b5645c8a4f..78093731c78 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
@@ -80,87 +80,10 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
end
end
end
-
- describe "the datepicker interaction" do
- # Start date is already defined in the included context
- let(:finish_date) { start_date + 1.day }
- let(:new_start_date) { start_date - 1.week }
- let(:new_finish_date) { start_date }
-
- it "interconnects the calendar with the date input fields" do
- dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
-
- # Set date input fields by choosing a range in the calendar
- dialog.set_date_for(values: [start_date, finish_date])
-
- dialog.expect_input("Start date", value: start_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Finish date", value: finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: 2, disabled: true)
-
- # Set a new finish date by focusing the finish date field
- dialog.activate_field("Finish date")
- dialog.set_date_for(values: [new_finish_date])
-
- dialog.expect_input("Start date", value: start_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"), active: true)
- dialog.expect_input("Duration", value: 1, disabled: true)
-
- # Set a new start date by focusing the start date field
- dialog.activate_field("Start date")
- dialog.set_date_for(values: [new_start_date])
-
- dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
- # Expect the finish date to be cleared and activated
- dialog.expect_input("Finish date", value: "", active: true)
- dialog.expect_input("Duration", value: "", disabled: true)
-
- # Set the new finish date too
- dialog.activate_field("Finish date")
- dialog.set_date_for(values: [new_finish_date])
-
- dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: 8, disabled: true)
-
- # Clearing the date fields by using the clear button
- dialog.clear_dates
-
- # Setting the finish date without a start date being present
- dialog.activate_field("Finish date")
- dialog.set_date_for(values: [new_finish_date])
-
- # The empty start date is focused and the new finish date is filled in
- dialog.expect_input("Start date", value: "", active: true)
- dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: "", disabled: true)
-
- # Filling the activated start date should complete the range
- dialog.set_date_for(values: [new_start_date])
-
- dialog.expect_input("Start date", value: new_start_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Finish date", value: new_finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: 8, disabled: true)
-
- # Manually setting an inverse range should show an validation message
- fill_in("Finish date", with: (new_start_date - 1.day).strftime("%Y-%m-%d"))
- .send_keys(:tab)
-
- dialog.expect_validation_message(
- "Finish date",
- text: "Finish date must be after the start date."
- )
-
- # Setting a correct range will clear the error message
- fill_in("Finish date", with: new_finish_date.strftime("%Y-%m-%d"))
- .send_keys(:tab)
-
- dialog.expect_no_validation_message("Finish date")
- end
- end
end
- context "when all LifeCycleSteps have a value" do
- it "shows all the Project::Phases and updates them correctly" do
+ context "when all Project::Phase have dates set" do
+ it "shows and updates them correctly" do
life_cycle_initiating_was = life_cycle_initiating.dup
life_cycle_planning_was = life_cycle_planning.dup
life_cycle_executing_was = life_cycle_executing.dup
@@ -169,15 +92,13 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
# Set a value for life_cycle_initiating
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
- life_cycle_initiating.tap do |step|
- dialog.expect_input("Start date", value: step.start_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Finish date", value: step.finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: step.duration, disabled: true)
- end
+ dialog.expect_input("Start date", value: initiating_start_date)
+ dialog.expect_input("Finish date", value: initiating_finish_date)
+ dialog.expect_input("Duration", value: initiating_duration, disabled: true)
retry_block do
# Retrying due to a race condition between filling the input vs submitting the form preview.
- original_dates = [life_cycle_initiating.start_date, life_cycle_initiating.finish_date]
+ original_dates = [initiating_start_date, initiating_finish_date]
dialog.set_date_for(values: original_dates)
page.driver.clear_network_traffic
@@ -202,17 +123,29 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
end
end
- # Clear the value of life_cycle_planning
+ # Open the life_cycle_planning dialog
+ expected_start_date = start_date + 1.day
+ expected_finish_date = expected_start_date + planning_duration - 1.day
dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning, wait_angular: true)
- life_cycle_planning.tap do |step|
- dialog.expect_input("Start date", value: step.start_date.strftime("%Y-%m-%d"), disabled: true)
- dialog.expect_input("Finish date", value: step.finish_date.strftime("%Y-%m-%d"))
- dialog.expect_input("Duration", value: step.duration, disabled: true)
- end
+ dialog.expect_input("Start date", value: expected_start_date, disabled: true)
+ dialog.expect_input("Finish date", value: expected_finish_date)
+ dialog.expect_input("Duration", value: planning_duration, disabled: true)
+
+ # Set invalid range (finish date before start date) via input field
+ fill_in("Finish date", with: (expected_start_date - 1.day).strftime("%Y-%m-%d"))
+ .send_keys(:tab)
+ dialog.expect_validation_message(
+ "Finish date",
+ text: "Finish date must be after the start date."
+ )
+
+ # Clear the value of life_cycle_planning
dialog.clear_dates
+ dialog.expect_no_validation_message("Finish date")
+
# Saving the dialog is successful
dialog.submit
dialog.expect_closed
@@ -262,6 +195,105 @@ RSpec.describe "Edit project phases on project overview page", :js, with_flag: {
"#{I18n.l life_cycle_closing.finish_date}")
end
end
+
+ describe "the datepicker interaction" do
+ let(:new_start_date) { start_date - 1.week }
+ let(:new_finish_date) { start_date }
+
+ it "interconnects the calendar with the date input fields" do
+ # Opening the first phase
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_initiating, wait_angular: true)
+
+ dialog.expect_input("Start date", value: initiating_start_date)
+ dialog.expect_input("Finish date", value: initiating_finish_date)
+ dialog.expect_input("Duration", value: 2, disabled: true)
+
+ # Update only finish date via calendar (with finish date field active)
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ dialog.expect_input("Start date", value: initiating_start_date)
+ dialog.expect_input("Finish date", value: new_finish_date, active: true)
+ dialog.expect_input("Duration", value: 1, disabled: true)
+
+ # Update start date via calendar (with start date field active)
+ dialog.activate_field("Start date")
+ dialog.set_date_for(values: [new_start_date])
+
+ dialog.expect_input("Start date", value: new_start_date)
+ dialog.expect_input("Finish date", value: "", active: true) # finish date cleared and activated
+ dialog.expect_input("Duration", value: "", disabled: true)
+
+ # Set finish date again via calendar
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ dialog.expect_input("Start date", value: new_start_date)
+ dialog.expect_input("Finish date", value: new_finish_date)
+ dialog.expect_input("Duration", value: 8, disabled: true)
+
+ # Clear both date fields via clear buttons
+ dialog.clear_dates
+
+ # Set finish date with empty start date via calendar
+ dialog.activate_field("Finish date")
+ dialog.set_date_for(values: [new_finish_date])
+
+ # The empty start date is focused and the new finish date is filled in
+ dialog.expect_input("Start date", value: "", active: true)
+ dialog.expect_input("Finish date", value: new_finish_date)
+ dialog.expect_input("Duration", value: "", disabled: true)
+
+ # Complete range by setting start date via the calendar
+ dialog.set_date_for(values: [new_start_date])
+
+ dialog.expect_input("Start date", value: new_start_date)
+ dialog.expect_input("Finish date", value: new_finish_date)
+ dialog.expect_input("Duration", value: 8, disabled: true)
+ end
+ end
+ end
+
+ context "when only the first Project::Phase has dates set" do
+ it "shows updates the following Project::Phase correctly" do
+ # Opening the second phase with no dates
+ life_cycle_planning.update!(start_date: nil, finish_date: nil, duration: nil)
+ dialog = overview_page.open_edit_dialog_for_life_cycle(life_cycle_planning, wait_angular: true)
+
+ # The start date automatically succeeds the life_cycle_initiating
+ initiating_finish_date_succesor = initiating_finish_date + 1.day
+
+ dialog.expect_input("Start date", value: initiating_finish_date_succesor, disabled: true)
+ dialog.expect_input("Finish date", value: "")
+ dialog.expect_input("Duration", value: "", disabled: true)
+
+ retry_block do
+ # Set invalid range (finish date before start date) via input field
+ fill_in("Finish date", with: initiating_finish_date.strftime("%Y-%m-%d"))
+ .send_keys(:tab)
+
+ dialog.expect_validation_message(
+ "Finish date",
+ text: "Finish date must be after the start date."
+ )
+ end
+
+ # Correct the finish date to clear validation via the datepicker
+ dialog.set_date_for(values: [planning_finish_date])
+
+ dialog.expect_input("Start date", value: initiating_finish_date_succesor, disabled: true)
+ dialog.expect_input("Finish date", value: planning_finish_date)
+ dialog.expect_input("Duration", value: planning_duration, disabled: true)
+
+ dialog.submit # Saving the dialog is successful
+ dialog.expect_closed
+
+ # Sidebar shows the refreshed life_cycle_planning
+ life_cycle_planning.reload
+ overview_page.within_life_cycle_container(life_cycle_planning) do
+ expect(page).to have_text formatted_date_range(life_cycle_planning)
+ end
+ end
end
context "when there is an invalid custom field on the project (Regression#60666)" do
diff --git a/spec/features/projects/life_cycle/overview_page/shared_context.rb b/spec/features/projects/life_cycle/overview_page/shared_context.rb
index 29088fa3717..b45acc2ae55 100644
--- a/spec/features/projects/life_cycle/overview_page/shared_context.rb
+++ b/spec/features/projects/life_cycle/overview_page/shared_context.rb
@@ -48,32 +48,45 @@ RSpec.shared_context "with seeded projects and phases" do
let(:start_date) { Time.zone.today.next_week }
+ let(:initiating_start_date) { start_date }
+ let(:initiating_finish_date) { start_date + 1.day }
+ let(:initiating_duration) { 2 }
+ let(:planning_start_date) { start_date + 2.days }
+ let(:planning_finish_date) { start_date + 5.days }
+ let(:planning_duration) { 4 }
+ let(:executing_start_date) { start_date + 6.days }
+ let(:executing_finish_date) { start_date + 7.days }
+ let(:executing_duration) { 2 }
+ let(:closing_start_date) { start_date + 8.days }
+ let(:closing_finish_date) { start_date + 12.days }
+ let(:closing_duration) { 4 }
+
let(:life_cycle_initiating) do
create :project_phase,
definition: life_cycle_initiating_definition,
- start_date:,
- finish_date: start_date + 1.day,
+ start_date: initiating_start_date,
+ finish_date: initiating_finish_date,
project:
end
let(:life_cycle_planning) do
create :project_phase,
definition: life_cycle_planning_definition,
- start_date: start_date + 2.days,
- finish_date: start_date + 5.days,
+ start_date: planning_start_date,
+ finish_date: planning_finish_date,
project:
end
let(:life_cycle_executing) do
create :project_phase,
definition: life_cycle_executing_definition,
- start_date: start_date + 6.days,
- finish_date: start_date + 7.days,
+ start_date: executing_start_date,
+ finish_date: executing_finish_date,
project:
end
let(:life_cycle_closing) do
create :project_phase,
definition: life_cycle_closing_definition,
- start_date: start_date + 8.days,
- finish_date: start_date + 12.days,
+ start_date: closing_start_date,
+ finish_date: closing_finish_date,
project:
end
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 e9cc99a15f3..0bd8c613ce4 100644
--- a/spec/support/components/projects/project_life_cycles/edit_dialog.rb
+++ b/spec/support/components/projects/project_life_cycles/edit_dialog.rb
@@ -126,7 +126,9 @@ module Components
def expect_input(label, value: nil, disabled: false, active: false)
field_options = { disabled: }
- field_options[:with] = value if value
+ if value
+ field_options[:with] = value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value
+ end
field_options[:class] = "op-datepicker-modal--date-field_current" if active
within_async_content do