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 tests for new duration display with days and hours only

Christophe Bliard23637b1fe813
diff --git a/app/services/duration_converter.rb b/app/services/duration_converter.rb
index 2746f65ef88..6e200f65b6c 100644
--- a/app/services/duration_converter.rb
+++ b/app/services/duration_converter.rb
@@ -103,14 +103,10 @@ class DurationConverter
def output(duration_in_hours)
return duration_in_hours if duration_in_hours.nil?
- # Prevents rounding errors when including seconds by chopping
- # off the overflow seconds and keeping the nearest minute.
- seconds = ((duration_in_hours * 3600) + 30).to_i
- seconds_overflow = seconds % 60
- seconds_to_the_nearest_minute = seconds - seconds_overflow
+ seconds = (duration_in_hours * 3600).to_i
# :days_and_hours format return "0h" when parsing 0.
- ChronicDuration.output(seconds_to_the_nearest_minute,
+ ChronicDuration.output(seconds,
format: :days_and_hours,
**duration_length_options)
end
diff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.ts
index 6ee46b52e3f..1cfe1182be1 100644
--- a/frontend/src/app/core/datetime/timezone.service.ts
+++ b/frontend/src/app/core/datetime/timezone.service.ts
@@ -154,11 +154,9 @@ export class TimezoneService {
daysPerMonth: this.configurationService.daysPerMonth(),
}):string {
// Keep in sync with app/services/duration_converter#output
- const seconds = this.toSeconds(durationString) + 30;
- const secondsOverflow = seconds % 60;
- const secondsToTheNearestMinute = seconds - secondsOverflow;
+ const seconds = this.toSeconds(durationString);
- return outputChronicDuration(secondsToTheNearestMinute, opts) || '0h';
+ return outputChronicDuration(seconds, opts) || '0h';
}
public formattedISODate(date:any):string {
diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rb
index f1fb3f7ce36..83de01b451a 100644
--- a/spec/features/work_packages/progress_modal_spec.rb
+++ b/spec/features/work_packages/progress_modal_spec.rb
@@ -351,7 +351,7 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
work_edit_field.activate!
work_edit_field.expect_modal_field_value("1d 2h")
- remaining_work_edit_field.expect_modal_field_value("2h 7m")
+ remaining_work_edit_field.expect_modal_field_value("2.12h") # 2h 7m
percent_complete_edit_field.expect_modal_field_value("78", readonly: true)
end
end
@@ -384,8 +384,8 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
# work should be displayed as "2h 34m" ("2h 33m 36s" rounded to minutes),
# and remaining work as "17m" ("16m 48s" rounded to minutes)
work_edit_field.activate!
- work_edit_field.expect_modal_field_value("2h 34m")
- remaining_work_edit_field.expect_modal_field_value("17m")
+ work_edit_field.expect_modal_field_value("2.56h") # 2h 34m
+ remaining_work_edit_field.expect_modal_field_value("0.28h") # 17m
end
end
@@ -538,7 +538,7 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
work_edit_field.set_value("14")
page.driver.wait_for_network_idle # Wait for live-update to finish
- remaining_work_edit_field.expect_modal_field_value("1d")
+ remaining_work_edit_field.expect_modal_field_value("1d 0h")
end
specify "Case 3: when work is set to 2h, " \
diff --git a/spec/features/work_packages/remaining_time_spec.rb b/spec/features/work_packages/remaining_time_spec.rb
index 599d999fec3..118fd5dd648 100644
--- a/spec/features/work_packages/remaining_time_spec.rb
+++ b/spec/features/work_packages/remaining_time_spec.rb
@@ -50,7 +50,7 @@ RSpec.describe "Work packages remaining time", :js, :with_cuprite do
# need to update work first to enable the remaining work field
wp_page.update_attributes estimatedTime: "200" # rubocop:disable Rails/ActiveRecordAliases
wp_page.update_attributes remainingTime: "125" # rubocop:disable Rails/ActiveRecordAliases
- wp_page.expect_attributes remainingTime: "3w 5h"
+ wp_page.expect_attributes remainingTime: "15d 5h"
work_package.reload
expect(work_package.remaining_hours).to eq 125.0
@@ -70,8 +70,8 @@ RSpec.describe "Work packages remaining time", :js, :with_cuprite do
# need to update work first to enable the remaining work field
wp_table_page.update_work_package_attributes work_package, estimatedTime: "200"
wp_table_page.update_work_package_attributes work_package, remainingTime: "125"
- wp_table_page.expect_work_package_with_attributes work_package, remainingTime: "3w 5h"
- wp_table_page.expect_sums_row_with_attributes remainingTime: "3w 5h"
+ wp_table_page.expect_work_package_with_attributes work_package, remainingTime: "15d 5h"
+ wp_table_page.expect_sums_row_with_attributes remainingTime: "15d 5h"
work_package.reload
expect(work_package.remaining_hours).to eq 125.0