Skip to content

Commit

Permalink
Recompute progress values when changing status on new work package form
Browse files Browse the repository at this point in the history
Because of the weird way we initialize the fake work package, it could
believe that the status did not change and no recomputation was needed.
This is an edge case, and I'm not satisfied with its design.
  • Loading branch information
cbliard committed Sep 17, 2024
1 parent 5579eb4 commit c40bd5f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def derive_remaining_work?
end

def status_percent_complete_changed?
work_package.status_id_changed? && work_package.status.default_done_ratio != work_package.done_ratio_was
work_package.status_id.present? && work_package.status_id_came_from_user? \
&& work_package.status.default_done_ratio != work_package.done_ratio_was
end

# Update +% complete+ from the status if the status changed.
Expand Down
19 changes: 19 additions & 0 deletions spec/features/work_packages/progress_modal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ def visit_progress_query_displaying_work_package
work_package_create_page.save!
work_package_table.expect_and_dismiss_toaster(message: "Successful creation.")
end

it "updates remaining work when status is changed" do
work_package_create_page.visit!
work_package_create_page.set_attributes({ subject: "hello" })

progress_popover.open
progress_popover.expect_hints(work: nil, remaining_work: nil)
progress_popover.set_values(work: "14h")
progress_popover.expect_values(remaining_work: "14h")
progress_popover.expect_hints(remaining_work: :derived)
progress_popover.save

status_field = work_package_create_page.edit_field(:status)
status_field.update("in progress")

progress_popover.open
progress_popover.expect_values(work: "14h", remaining_work: "7h")
progress_popover.expect_hints(remaining_work: :derived)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@
end
end

context "given a work package with status and % complete not being in sync" do
before do
work_package.status = status_50_pct_complete
work_package.done_ratio = 0
work_package.estimated_hours = 10.0
work_package.remaining_hours = 10.0
work_package.clear_changes_information
end

context "when status is set again to the same value" do
let(:set_attributes) { { status: status_50_pct_complete } }
let(:expected_derived_attributes) { { remaining_hours: 5.0, done_ratio: 50 } }
let(:expected_kept_attributes) { %w[estimated_hours] }

include_examples "update progress values", description: "updates % complete value to the status default % complete value " \
"and derives remaining work",
expected_hints: {
remaining_work: :derived
}
end
end

context "given a work package with work and remaining work being empty, and a status with 0% complete" do
before do
work_package.status = status_0_pct_complete
Expand Down

0 comments on commit c40bd5f

Please sign in to comment.