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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.erbindex 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) doprimer_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.endend- if @storage.automatic_management_enabled?+ if model.automatic_management_enabled?health_status_container.with_row(mt: 2) dorender(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.health.project_folders.subtitle") }endhealth_status_container.with_row(mt: 2) doconcat(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) dorender(Primer::Beta::Text.new(color: :muted, test_selector: "storage-health-error")) doformatted_health_reasondiff --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.rbindex 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 Storagesmodule Adminmodule SidePanel- class HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent+ class HealthStatusComponent < ApplicationComponentinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(storage:)- super(storage)- @storage = storage- end-privatedef health_status_indicator- case @storage.health_status+ case model.health_statuswhen "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))}"enddef validation_result_placeholderdiff --git a/modules/storages/app/components/storages/admin/side_panel_component.html.erb b/modules/storages/app/components/storages/admin/side_panel_component.html.erbindex 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 dorender(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.rbindex 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_helperRSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :component dofrozen_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 dorender_inline(health_status_component)endcontext "with healthy storage" do- shared_let(:storage) do+ let(:storage) dotravel_to(frozen_date_time) docreate(:nextcloud_storage_with_complete_configuration, :as_healthy)end@@ -52,7 +52,7 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :componeendcontext "with storage health pending" do- shared_let(:storage) do+ let(:storage) dotravel_to(frozen_date_time) docreate(:nextcloud_storage_with_complete_configuration)end@@ -64,7 +64,7 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :componeendcontext "with unhealthy storage" do- shared_let(:storage) do+ let(:storage) dotravel_to(frozen_date_time) docreate(:nextcloud_storage_with_complete_configuration, :as_unhealthy)end@@ -76,8 +76,22 @@ RSpec.describe Storages::Admin::SidePanel::HealthStatusComponent, type: :componeendend+ 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) dotravel_to(frozen_date_time) docreate(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)end