Skip to content

Commit

Permalink
Recompute % complete when cleared with work and work is set again
Browse files Browse the repository at this point in the history
Also correctly reference scenario ids from work package #57370
https://community.openproject.org/wp/57370
  • Loading branch information
cbliard committed Aug 23, 2024
1 parent a09b683 commit b19d34a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export default class TouchedFieldMarkerController extends Controller {
// force remaining work derivation
this.markUntouched('remaining_hours');
this.markTouched('done_ratio');
} else if (this.isTouchedAndEmpty('done_ratio') && this.isValueSet('remaining_hours')) {
// force % complete derivation
this.markUntouched('done_ratio');
this.markTouched('remaining_hours');
}
}

Expand Down
45 changes: 39 additions & 6 deletions spec/features/work_packages/progress_modal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def visit_progress_query_displaying_work_package
progress_popover.expect_values(remaining_work: "6h")
end

specify "Case 4: when remaining work or % complete are set, work never " \
specify "Case 23-7: when remaining work or % complete are set, work never " \
"changes, instead remaining work and % complete are derived" do
visit_progress_query_displaying_work_package

Expand All @@ -482,7 +482,7 @@ def visit_progress_query_displaying_work_package
end

# scenario from https://community.openproject.org/wp/57370
specify "Case 5: when work is cleared, and remaining work is set, " \
specify "Case 23-11: when work is cleared, and remaining work is set, " \
"then work is derived again" do
visit_progress_query_displaying_work_package

Expand All @@ -498,7 +498,7 @@ def visit_progress_query_displaying_work_package
end

# scenario from https://community.openproject.org/wp/57370
specify "Case 6: when remaining work is cleared, and work is set, " \
specify "Case 23-14: when remaining work is cleared, and work is set, " \
"then remaining work is derived again" do
visit_progress_query_displaying_work_package

Expand All @@ -509,18 +509,35 @@ def visit_progress_query_displaying_work_package

# set remaining work
progress_popover.set_values(work: "20h")
# work is derived
# => work is derived
progress_popover.expect_values(work: "20h", remaining_work: "8h", percent_complete: "60%")
end

# scenario from https://community.openproject.org/wp/57370
specify "Case 33-14: when work and % complete are cleared, and then work " \
"is set again then % complete is derived again" do
visit_progress_query_displaying_work_package

progress_popover.open
# clear work and % complete
progress_popover.set_values(work: "", percent_complete: "")
progress_popover.expect_values(work: "", remaining_work: "4h", percent_complete: "")

# set work
progress_popover.set_values(work: "20h")
# => % complete is derived
progress_popover.expect_values(work: "20h", remaining_work: "4h", percent_complete: "80%")
end
end

context "given work, remaining work, and % complete are all empty" do
before do
update_work_package_with(work_package, estimated_hours: nil, remaining_hours: nil, done_ratio: nil)
end

specify "Case 1: when remaining work and % complete are both set, work " \
"is derived because it's empty" do
# scenario from https://community.openproject.org/wp/57370
specify "Case 20-4: when remaining work and % complete are both set, work " \
"is derived because it's initially empty" do
visit_progress_query_displaying_work_package

progress_popover.open
Expand All @@ -530,6 +547,22 @@ def visit_progress_query_displaying_work_package
progress_popover.set_values(remaining_work: "10h")
progress_popover.expect_values(work: "20h")
end

# scenario from https://community.openproject.org/wp/57370
specify "Case 30-1: when % complete is set, remaining work is set, and " \
"% complete is changed, then work is always derived" do
visit_progress_query_displaying_work_package

progress_popover.open
progress_popover.set_values(percent_complete: "40%")
progress_popover.expect_values(work: "", remaining_work: "", percent_complete: "40%")

progress_popover.set_values(remaining_work: "60h")
progress_popover.expect_values(work: "100h", remaining_work: "60h", percent_complete: "40%")

progress_popover.set_values(percent_complete: "80%")
progress_popover.expect_values(work: "300h", remaining_work: "60h", percent_complete: "80%")
end
end
end
end

0 comments on commit b19d34a

Please sign in to comment.