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 progress-related feature tests

Christophe Bliard5abd3ab80766
diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb
index 457bf28d2c6..8e38c724787 100644
--- a/spec/features/work_packages/edit_work_package_spec.rb
+++ b/spec/features/work_packages/edit_work_package_spec.rb
@@ -131,11 +131,11 @@ RSpec.describe "edit work package", :js do
combinedDate: ["2013-03-04", "2013-03-20"],
responsible: manager.name,
assignee: manager.name,
- estimatedTime: "5",
+ estimatedTime: "10",
+ remainingTime: "7",
priority: priority2.name,
version: version.name,
category: category.name,
- percentageDone: "30",
status: status2.name,
description: "a new description"
@@ -143,7 +143,8 @@ RSpec.describe "edit work package", :js do
responsible: manager.name,
assignee: manager.name,
combinedDate: "03/04/2013 - 03/20/2013",
- estimatedTime: "5",
+ estimatedTime: "10 h",
+ remainingTime: "7 h",
percentageDone: "30%",
subject: "a new subject",
description: "a new description",
diff --git a/spec/features/work_packages/table/group_by/group_by_spec.rb b/spec/features/work_packages/table/group_by/group_by_spec.rb
index 7eff288e4f8..4c86f35fb8b 100644
--- a/spec/features/work_packages/table/group_by/group_by_spec.rb
+++ b/spec/features/work_packages/table/group_by/group_by_spec.rb
@@ -49,6 +49,6 @@ RSpec.describe "Work Package group by progress", :js do
# Expect table to be grouped into 1 group
group_by.expect_number_of_groups 1
- group_by.expect_grouped_by_value "0%", 3
+ group_by.expect_grouped_by_value "-", 3
end
end
diff --git a/spec/features/work_packages/update_ancestors_spec.rb b/spec/features/work_packages/update_ancestors_spec.rb
index cbb4932a582..37e2b1d6627 100644
--- a/spec/features/work_packages/update_ancestors_spec.rb
+++ b/spec/features/work_packages/update_ancestors_spec.rb
@@ -101,35 +101,27 @@ RSpec.describe "Update ancestors", :js, :with_cuprite do
wp_table.visit_query query
end
- context "when changing a child work and remaining work values", retry: 2 do
+ context "when changing a child work and remaining work values" do
it "updates the derived parent work, remaining work, and % complete values" do
expect do
wp_table.update_work_package_attributes(child, estimatedTime: child.estimated_hours + 1)
parent.reload
end.to change(parent, :derived_estimated_hours).by(1)
- .and change(parent, :derived_done_ratio).to(35) # 7h at 50% and 3h at 0% => 35% complete for 10h
+ .and change(parent, :derived_done_ratio).to(42) # 12h total work and 7h total remaining work => 42% complete
expect do
wp_table.update_work_package_attributes(child, remainingTime: child.remaining_hours + 2)
parent.reload
end.to change(parent, :derived_remaining_hours).by(2)
- end
- end
-
- context "when changing a child % complete value" do
- it "updates the derived parent % complete value" do
- expect do
- wp_table.update_work_package_attributes(child, percentageDone: 100)
- parent.reload
- end.to change(parent, :derived_done_ratio).to(67) # 6h at 100% and 3h at 0% => 67% complete for 9h
+ .and change(parent, :derived_done_ratio).to(25) # 12h total work and 9h total remaining work => 25% complete
end
end
context "when setting a child status to closed" do
- it "considers child % complete to be 100% and updates the derived parent % complete value accordingly" do
+ it "does not consider child % complete to be 100% and so does not update the derived parent % complete value" do
expect do
wp_table.update_work_package_attributes(child, status: "Closed")
parent.reload
- end.to change(parent, :derived_done_ratio).to(67) # 6h at 100% and 3h at 0% => 67% complete for 9h
+ end.not_to change(parent, :derived_done_ratio)
end
end
@@ -145,23 +137,29 @@ RSpec.describe "Update ancestors", :js, :with_cuprite do
end
end
+ def expect_totals(parent, descendants)
+ parent.reload
+ work_packages_for_total = [parent] + descendants
+ expected_total_work = work_packages_for_total.pluck(:estimated_hours).sum
+ expected_total_remaining_work = work_packages_for_total.pluck(:remaining_hours).sum
+ expected_done_ratio = 100.0 * (1.0 - (expected_total_remaining_work / expected_total_work))
+ expect(parent.derived_estimated_hours).to eq(expected_total_work)
+ expect(parent.derived_remaining_hours).to eq(expected_total_remaining_work)
+ expect(parent.derived_done_ratio).to eq(expected_done_ratio.round)
+ end
+
context "when adding a new child" do
it "updates the derived parent work, remaining work, and % complete values" do
context_menu = wp_table.open_context_menu_for(parent)
context_menu.choose(I18n.t("js.relation_buttons.add_new_child"))
split_view_create = Pages::SplitWorkPackageCreate.new(project:)
- split_view_create.set_attributes({ subject: "new child", estimatedTime: 1, remainingTime: 3 })
+ split_view_create.set_attributes({ subject: "new child", estimatedTime: 3, remainingTime: 1 })
split_view_create.save!
split_view_create.expect_and_dismiss_toaster message: "Successful creation"
- parent.reload
new_child = WorkPackage.last
- expect(parent.derived_estimated_hours).to eq([parent, child, second_child, new_child].pluck(:estimated_hours).sum)
- expect(parent.derived_remaining_hours).to eq([parent, child, second_child, new_child].pluck(:remaining_hours).sum)
- # child + second child + new child => parent
- # 6h at 50% + 3h at 0% + 1h at 0% => 30% complete for 10h
- expect(parent.derived_done_ratio).to eq(30)
+ expect_totals(parent, [child, second_child, new_child])
end
end
@@ -171,21 +169,13 @@ RSpec.describe "Update ancestors", :js, :with_cuprite do
context_menu.choose(I18n.t("js.relation_buttons.hierarchy_outdent"))
wp_table.expect_and_dismiss_toaster message: "Successful update"
- parent.reload
- expect(parent.derived_estimated_hours).to eq([parent, child].pluck(:estimated_hours).sum)
- expect(parent.derived_remaining_hours).to eq([parent, child].pluck(:remaining_hours).sum)
- expect(parent.derived_done_ratio).to eq(child.done_ratio)
+ expect_totals(parent, [child])
context_menu = wp_table.open_context_menu_for(second_child)
context_menu.choose(I18n.t("js.relation_buttons.hierarchy_indent"))
wp_table.expect_and_dismiss_toaster message: "Successful update"
- parent.reload
- expect(parent.derived_estimated_hours).to eq([parent, child, second_child].pluck(:estimated_hours).sum)
- expect(parent.derived_remaining_hours).to eq([parent, child, second_child].pluck(:remaining_hours).sum)
- # child + second child => parent
- # 6h at 50% + 3h at 0% => 33% complete for 9h
- expect(parent.derived_done_ratio).to eq(33)
+ expect_totals(parent, [child, second_child])
end
end
end