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

Update tests and treat corner cases on rendering storage health status

Marcello Rochade39d2540ff9
diff --git a/modules/storages/app/components/storages/admin/side_panel/health_status_component.html.erb b/modules/storages/app/components/storages/admin/side_panel/health_status_component.html.erb
index 5ee3ce94ab8..15cea3bfb15 100644
--- a/modules/storages/app/components/storages/admin/side_panel/health_status_component.html.erb
+++ b/modules/storages/app/components/storages/admin/side_panel/health_status_component.html.erb
@@ -39,8 +39,8 @@ See COPYRIGHT and LICENSE files for more details.
health_status_container.with_row(mt: 2) do
primer_form_with(
- model: @storage,
- url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
+ model:,
+ url: validate_connection_admin_settings_storage_connection_validation_path(model),
method: :post,
data: { turbo: true }
) do
@@ -56,14 +56,14 @@ See COPYRIGHT and LICENSE files for more details.
end
end
- if @storage.automatic_management_enabled?
+ if model.automatic_management_enabled?
health_status_container.with_row(mt: 2) do
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.project_folders.subtitle") }
end
health_status_container.with_row(mt: 2) do
concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "storage-health-checked-at")) do
- I18n.t('storages.health.checked', datetime: helpers.format_time(@storage.health_checked_at))
+ I18n.t('storages.health.checked', datetime: helpers.format_time(model.health_checked_at))
end)
concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
@@ -71,7 +71,7 @@ See COPYRIGHT and LICENSE files for more details.
end)
end
- if @storage.health_unhealthy?
+ if model.health_unhealthy?
health_status_container.with_row(mt: 2) do
render(Primer::Beta::Text.new(color: :muted, test_selector: "storage-health-error")) do
formatted_health_reason
diff --git a/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb b/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
index 6c7a1f79ec4..1de2253d289 100644
--- a/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
+++ b/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
@@ -31,20 +31,15 @@
module Storages
module Admin
module SidePanel
- class HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class HealthStatusComponent < ApplicationComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- def initialize(storage:)
- super(storage)
- @storage = storage
- end
-
private
def health_status_indicator
- case @storage.health_status
+ case model.health_status
when "healthy"
{ scheme: :success, label: I18n.t("storages.health.label_healthy") }
when "unhealthy"
@@ -57,8 +52,15 @@ module Storages
# This method returns the health identifier, description and the time since when the error occurs in a
# formatted manner. e.g. "Not found: Outbound request destination not found since 12/07/2023 03:45 PM"
def formatted_health_reason
- "#{@storage.health_reason_identifier.tr('_', ' ').strip.capitalize}: #{@storage.health_reason_description} " +
- I18n.t("storages.health.since", datetime: helpers.format_time(@storage.health_changed_at))
+ identifier = model.health_reason_identifier.tr("_", " ").strip
+ description = model.health_reason_description
+
+ if description.present?
+ identifier.capitalize!
+ identifier << ": #{description}"
+ end
+
+ "#{identifier} #{I18n.t('storages.health.since', datetime: helpers.format_time(model.health_changed_at))}"
end
def validation_result_placeholder
diff --git a/modules/storages/app/components/storages/admin/side_panel_component.html.erb b/modules/storages/app/components/storages/admin/side_panel_component.html.erb
index 4282f7d9710..0a699dd5f40 100644
--- a/modules/storages/app/components/storages/admin/side_panel_component.html.erb
+++ b/modules/storages/app/components/storages/admin/side_panel_component.html.erb
@@ -1,7 +1,7 @@
<%=
component_wrapper do
render(Primer::OpenProject::SidePanel.new) do |panel|
- panel.with_section(Storages::Admin::SidePanel::HealthStatusComponent.new(storage: @storage))
+ panel.with_section(Storages::Admin::SidePanel::HealthStatusComponent.new(@storage))
if @storage.automatic_management_enabled?
panel.with_section(Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))
diff --git a/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb b/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
index 8d139374dbc..a8410af1c0d 100644
--- a/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
+++ b/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
@@ -32,14 +32,14 @@ require_module_spec_helper
RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :component do
frozen_date_time = Time.zone.local(2023, 11, 28, 1, 2, 3)
- subject(:health_status_component) { described_class.new(storage:) }
+ subject(:health_status_component) { described_class.new(storage) }
before do
render_inline(health_status_component)
end
context "with healthy storage" do
- shared_let(:storage) do
+ let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_healthy)
end
@@ -52,7 +52,7 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :compone
end
context "with storage health pending" do
- shared_let(:storage) do
+ let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration)
end
@@ -64,7 +64,7 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :compone
end
context "with unhealthy storage" do
- shared_let(:storage) do
+ let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_unhealthy)
end
@@ -76,8 +76,22 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :compone
end
end
+ context "with an unhealthy storage with a localized error message" do
+ let(:error_text) { I18n.t("services.errors.models.nextcloud_sync_service.unauthorized") }
+ let(:storage) do
+ travel_to(frozen_date_time) do
+ create(:nextcloud_storage_with_complete_configuration, :as_unhealthy, health_reason: error_text)
+ end
+ end
+
+ it "shows a correctly formatted error message" do
+ expect(page).to have_test_selector("storage-health-status", text: "Error")
+ expect(page).to have_test_selector("storage-health-error", text: "#{error_text} since 11/28/2023 01:02 AM")
+ end
+ end
+
context "with unhealthy storage, long reason" do
- shared_let(:storage) do
+ let(:storage) do
travel_to(frozen_date_time) do
create(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)
end