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

tests[Op-51021] Extract health status unit tests to component spec

Kabiru Mwenja6759edd39bf1
diff --git a/modules/storages/spec/components/storages/admin/health_status_component_spec.rb b/modules/storages/spec/components/storages/admin/health_status_component_spec.rb
new file mode 100644
index 00000000000..8a3f3285741
--- /dev/null
+++ b/modules/storages/spec/components/storages/admin/health_status_component_spec.rb
@@ -0,0 +1,93 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+#
+require 'spec_helper'
+require_module_spec_helper
+
+RSpec.describe Storages::Admin::HealthStatusComponent, type: :component do
+ include ActiveSupport::Testing::TimeHelpers
+ frozen_date_time = Time.zone.local(2023, 11, 28, 1, 2, 3)
+
+ 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
+ travel_to(frozen_date_time) do
+ create(:nextcloud_storage_with_complete_configuration, :as_healthy)
+ end
+ end
+
+ it 'shows a healthy status' do
+ expect(page).to have_test_selector('storage-health-label-healthy', text: 'Healthy')
+ expect(page).to have_test_selector('storage-health-checked-at', text: "Last checked 11/28/2023 01:02 AM")
+ end
+ end
+
+ context 'with storage health pending' do
+ shared_let(:storage) do
+ travel_to(frozen_date_time) do
+ create(:nextcloud_storage_with_complete_configuration)
+ end
+ end
+
+ it 'shows pending label' do
+ expect(page).to have_test_selector('storage-health-label-pending', text: 'Pending')
+ end
+ end
+
+ context 'with unhealthy storage' do
+ shared_let(:storage) do
+ travel_to(frozen_date_time) do
+ create(:nextcloud_storage_with_complete_configuration, :as_unhealthy)
+ end
+ end
+
+ it 'shows an error status' do
+ expect(page).to have_test_selector('storage-health-label-error', text: 'Error')
+ expect(page).to have_test_selector('storage-health-reason', text: 'Error code: description since 11/28/2023 01:02 AM')
+ end
+ end
+
+ context 'with unhealthy storage, long reason' do
+ shared_let(:storage) do
+ travel_to(frozen_date_time) do
+ create(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)
+ end
+ end
+
+ it 'shows a formatted error reason' do
+ expect(page).to have_test_selector('storage-health-label-error', text: 'Error')
+ expect(page).to have_test_selector('storage-health-reason',
+ text: 'Unauthorized: Outbound request not authorized since 11/28/2023 01:02 AM')
+ end
+ end
+end
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index f6b239f2ec5..77b0ac3b172 100644
--- a/modules/storages/spec/features/admin_storages_spec.rb
+++ b/modules/storages/spec/features/admin_storages_spec.rb
@@ -532,6 +532,12 @@ RSpec.describe 'Admin storages',
expect(page).to have_test_selector('label-managed-project-folders-status', text: 'Active')
end
end
+
+ it 'renders health status information' do
+ visit edit_admin_settings_storage_path(storage)
+
+ expect(page).to have_test_selector('storage-health-label-pending', text: 'Pending')
+ end
end
context 'with OneDrive Storage' do
@@ -623,51 +629,4 @@ RSpec.describe 'Admin storages',
end
end
end
-
- describe 'Health status information in edit page' do
- frozen_date_time = Time.zone.local(2023, 11, 28, 1, 2, 3)
-
- let(:complete_nextcloud_storage_health_pending) { create(:nextcloud_storage_with_complete_configuration) }
- let(:complete_nextcloud_storage_health_healthy) { create(:nextcloud_storage_with_complete_configuration, :as_healthy) }
- let(:complete_nextcloud_storage_health_unhealthy) { create(:nextcloud_storage_with_complete_configuration, :as_unhealthy) }
- let(:complete_nextcloud_storage_health_unhealthy_long_reason) do
- create(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)
- end
-
- before do
- Timecop.freeze(frozen_date_time)
- complete_nextcloud_storage_health_pending
- complete_nextcloud_storage_health_healthy
- complete_nextcloud_storage_health_unhealthy
- complete_nextcloud_storage_health_unhealthy_long_reason
- end
-
- after do
- Timecop.return
- end
-
- it 'shows healthy status for storages that are healthy' do
- visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_healthy)
- expect(page).to have_test_selector('storage-health-label-healthy', text: 'Healthy')
- expect(page).to have_test_selector('storage-health-checked-at', text: "Last checked 11/28/2023 01:02 AM")
- end
-
- it 'shows pending label for a storage that is pending' do
- visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_pending)
- expect(page).to have_test_selector('storage-health-label-pending', text: 'Pending')
- end
-
- it 'shows error status for storages that are unhealthy' do
- visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_unhealthy)
- expect(page).to have_test_selector('storage-health-label-error', text: 'Error')
- expect(page).to have_test_selector('storage-health-reason', text: 'Error code: description since 11/28/2023 01:02 AM')
- end
-
- it 'shows formatted error reason for storages that are unhealthy' do
- visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_unhealthy_long_reason)
- expect(page).to have_test_selector('storage-health-label-error', text: 'Error')
- expect(page).to have_test_selector('storage-health-reason', text:
- 'Unauthorized: Outbound request not authorized since 11/28/2023 01:02 AM')
- end
- end
end