diff --git a/app/components/work_packages/progress/base_modal_component.rb b/app/components/work_packages/progress/base_modal_component.rb index ecc48c4bf59a..e19efd16e410 100644 --- a/app/components/work_packages/progress/base_modal_component.rb +++ b/app/components/work_packages/progress/base_modal_component.rb @@ -68,10 +68,6 @@ def learn_more_href OpenProject::Static::Links.links[:progress_tracking_docs][:href] end - def should_display_migration_warning? - work_package.done_ratio.present? && work_package.estimated_hours.nil? && work_package.remaining_hours.nil? - end - private def map_field(field) diff --git a/app/components/work_packages/progress/status_based/modal_body_component.html.erb b/app/components/work_packages/progress/status_based/modal_body_component.html.erb index d969fc6829f7..bdaa051f7b1d 100644 --- a/app/components/work_packages/progress/status_based/modal_body_component.html.erb +++ b/app/components/work_packages/progress/status_based/modal_body_component.html.erb @@ -11,12 +11,6 @@ <%= render(WorkPackages::ProgressForm.new(f, work_package:, mode:, focused_field:)) %> <% end %> - <% if should_display_migration_warning? %> - <% modal_body.with_row(mt: 3) do |_migration_warning| %> - <%= render(Primer::Alpha::Banner.new) { t("work_package.progress.modal.migration_warning_text") } %> - <% end %> - <% end %> - <% modal_body.with_row(mt: 3) do |_tooltip| %> <%= render(Primer::Beta::Text.new(font_weight: :semibold)) { t("work_package.progress.label_note") } %> <%= render(Primer::Beta::Text.new) { t("work_package.progress.modal.status_based_help_text") } %> diff --git a/app/components/work_packages/progress/work_based/modal_body_component.rb b/app/components/work_packages/progress/work_based/modal_body_component.rb index d22b4d586970..2df6328dcc45 100644 --- a/app/components/work_packages/progress/work_based/modal_body_component.rb +++ b/app/components/work_packages/progress/work_based/modal_body_component.rb @@ -38,6 +38,10 @@ def initialize(work_package, focused_field: nil) @mode = :work_based end + + def should_display_migration_warning? + work_package.done_ratio.present? && work_package.estimated_hours.nil? && work_package.remaining_hours.nil? + end end # rubocop:enable OpenProject/AddPreviewForViewComponent diff --git a/spec/components/work_packages/progress/work_based/modal_body_component_spec.rb b/spec/components/work_packages/progress/work_based/modal_body_component_spec.rb index a304347e2c25..a91c18857a05 100644 --- a/spec/components/work_packages/progress/work_based/modal_body_component_spec.rb +++ b/spec/components/work_packages/progress/work_based/modal_body_component_spec.rb @@ -67,4 +67,38 @@ end end end + + describe "#should_display_migration_warning?" do + subject(:component) { described_class.new(work_package) } + + context "when the work package has a percent complete value but no work or remaining work set" do + let(:work_package) do + create(:work_package) do |work_package| + work_package.estimated_hours = nil + work_package.remaining_hours = nil + work_package.done_ratio = 10 + work_package.save!(validate: false) + end + end + + it "returns true" do + expect(component.should_display_migration_warning?).to be true + end + end + + context "when the work package has a percent complete value but and a work value but no remaining work set" do + let(:work_package) do + create(:work_package) do |work_package| + work_package.estimated_hours = 55 + work_package.remaining_hours = nil + work_package.done_ratio = 10 + work_package.save!(validate: false) + end + end + + it "returns false" do + expect(component.should_display_migration_warning?).to be false + end + end + end end diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rb index c21f73a78652..a8e198cbff9d 100644 --- a/spec/features/work_packages/progress_modal_spec.rb +++ b/spec/features/work_packages/progress_modal_spec.rb @@ -423,7 +423,7 @@ def update_work_package_with(work_package, attributes) work_package.save!(validate: false) end - shared_examples_for "renders a banner with a warning message" do + shared_examples_for "migration warning" do |should_render: false| it "renders a banner with a warning message" do work_package_table.visit_query(progress_query) work_package_table.expect_work_package_listed(work_package) @@ -431,16 +431,16 @@ def update_work_package_with(work_package, attributes) work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime) modal = work_edit_field.activate! - modal.expect_migration_warning_banner + modal.expect_migration_warning_banner(should_render:) end end context "on work based mode" do - include_examples "renders a banner with a warning message" + include_examples "migration warning", should_render: true end context "on status based mode", with_settings: { work_package_done_ratio: "status" } do - include_examples "renders a banner with a warning message" + include_examples "migration warning", should_render: false end end end diff --git a/spec/support/edit_fields/progress_edit_field.rb b/spec/support/edit_fields/progress_edit_field.rb index 7b6b092b3c14..fc2f2cd89b3b 100644 --- a/spec/support/edit_fields/progress_edit_field.rb +++ b/spec/support/edit_fields/progress_edit_field.rb @@ -170,10 +170,15 @@ def expect_select_field_with_no_options(*unexpected_options) end end - def expect_migration_warning_banner + def expect_migration_warning_banner(should_render: true) within modal_element do - expect(page) - .to have_text(I18n.t("work_package.progress.modal.migration_warning_text")) + if should_render + expect(page) + .to have_text(I18n.t("work_package.progress.modal.migration_warning_text")) + else + expect(page) + .to have_no_text(I18n.t("work_package.progress.modal.migration_warning_text")) + end end end