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

Render help text for missing values only on work-based mode

Aaron Contreras7c8d75e5d759
diff --git a/app/components/work_packages/progress/base_modal_component.rb b/app/components/work_packages/progress/base_modal_component.rb
index ecc48c4bf59..e19efd16e41 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 @@ module WorkPackages
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 d969fc6829f..bdaa051f7b1 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 d22b4d58697..2df6328dcc4 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 @@ module WorkPackages
@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 a304347e2c2..a91c18857a0 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 @@ RSpec.describe WorkPackages::Progress::WorkBased::ModalBodyComponent,
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 c21f73a7865..a8e198cbff9 100644
--- a/spec/features/work_packages/progress_modal_spec.rb
+++ b/spec/features/work_packages/progress_modal_spec.rb
@@ -423,7 +423,7 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
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 @@ RSpec.describe "Progress modal", :js, :with_cuprite do
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 7b6b092b3c1..fc2f2cd89b3 100644
--- a/spec/support/edit_fields/progress_edit_field.rb
+++ b/spec/support/edit_fields/progress_edit_field.rb
@@ -170,10 +170,15 @@ class ProgressEditField < EditField
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