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

chore[Op#52449]: define health notification component spec

Kabiru Mwenja816885dbc700
diff --git a/modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
similarity index 90%
rename from modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erb
rename to modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
index b7b219fe036..449f5c69ad4 100644
--- a/modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
@@ -2,7 +2,7 @@
component_wrapper(data: { turbo: true }) do
flex_layout do |notifications_container|
notifications_container.with_row do
- render(Primer::Beta::Heading.new(tag: :h4)) { t("storages.email_notifications.title") }
+ render(Primer::Beta::Heading.new(tag: :h4)) { t("storages.health_email_notifications.title") }
end
notifications_container.with_row(mt: 2) do
@@ -28,7 +28,7 @@
end
end
- notifications_container.with_row(mt: 3) do
+ notifications_container.with_row(mt: 3, test_selector: "health-notifications-description") do
render(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar/notifications_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
similarity index 77%
rename from modules/storages/app/components/storages/admin/sidebar/notifications_component.rb
rename to modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
index 40ef9fb0431..fe19dab2382 100644
--- a/modules/storages/app/components/storages/admin/sidebar/notifications_component.rb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
@@ -28,7 +28,7 @@
module Storages
module Admin
- class Sidebar::NotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class Sidebar::HealthNotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
@@ -44,12 +44,12 @@ module Storages
def notification_status
if storage.health_notifications_enabled?
{ icon: :"bell-slash",
- label: I18n.t("storages.email_notifications.unsubscribe"),
- description: I18n.t("storages.email_notifications.description_subscribed") }
+ label: I18n.t("storages.health_email_notifications.unsubscribe"),
+ description: I18n.t("storages.health_email_notifications.description_subscribed") }
else
{ icon: :bell,
- label: I18n.t("storages.email_notifications.subscribe"),
- description: I18n.t("storages.email_notifications.description_unsubscribed") }
+ label: I18n.t("storages.health_email_notifications.subscribe"),
+ description: I18n.t("storages.health_email_notifications.description_unsubscribed") }
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
index a0f4d0d86c1..3b19f1e32f1 100644
--- a/modules/storages/app/components/storages/admin/sidebar_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar_component.html.erb
@@ -2,7 +2,7 @@
component_wrapper do
render(Primer::OpenProject::BorderGrid.new) do |border_grid|
border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }
- border_grid.with_row { render(Storages::Admin::Sidebar::NotificationsComponent.new(storage: @storage)) }
+ border_grid.with_row { render(Storages::Admin::Sidebar::HealthNotificationsComponent.new(storage: @storage)) }
end
end
%>
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 31471986444..a33257169bb 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -169,7 +169,7 @@ class Storages::Admin::StoragesController < ApplicationController
return head :forbidden unless %w[1 0].include?(permitted_storage_params[:health_notifications_enabled])
if @storage.update(health_notifications_enabled: permitted_storage_params[:health_notifications_enabled])
- update_via_turbo_stream(component: Storages::Admin::Sidebar::NotificationsComponent.new(storage: @storage.reload))
+ update_via_turbo_stream(component: Storages::Admin::Sidebar::HealthNotificationsComponent.new(storage: @storage.reload))
respond_with_turbo_streams
else
flash.now[:primer_banner] = {
diff --git a/modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb b/modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb
new file mode 100644
index 00000000000..356c435effc
--- /dev/null
+++ b/modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb
@@ -0,0 +1,70 @@
+#-- 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::Sidebar::HealthNotificationsComponent, type: :component do
+ context "when subscribed to email notifications" do
+ let(:health_notifications_component) { described_class.new(storage:) }
+
+ let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_enabled) }
+
+ before do
+ render_inline(health_notifications_component)
+ end
+
+ it "renders an unsubscribe option with info" do
+ expect(page).to have_css("input[type=hidden][value='0']", visible: :hidden)
+ expect(page).to have_test_selector(
+ "health-notifications-description",
+ text: "Email notifications for this storage have been turned on for all administrators."
+ )
+ expect(page).to have_button("Unsubscribe")
+ end
+ end
+
+ context "when unsubscribed to email notifications" do
+ let(:health_notifications_component) { described_class.new(storage:) }
+
+ let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_disabled) }
+
+ before do
+ render_inline(health_notifications_component)
+ end
+
+ it "renders an unsubscribe option with info" do
+ expect(page).to have_css("input[type=hidden][value='1']", visible: :hidden)
+ expect(page).to have_test_selector(
+ "health-notifications-description",
+ text: "Health status email notifications for this storage have been turned off for all administrators."
+ )
+ expect(page).to have_button("Subscribe")
+ end
+ end
+end
diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rb
index ec7232cb53c..eedac36bc0e 100644
--- a/modules/storages/spec/factories/storage_factory.rb
+++ b/modules/storages/spec/factories/storage_factory.rb
@@ -76,6 +76,14 @@ FactoryBot.define do
health_changed_at { Time.now.utc }
health_checked_at { Time.now.utc }
end
+
+ trait :with_health_notifications_enabled do
+ health_notifications_enabled { true }
+ end
+
+ trait :with_health_notifications_disabled do
+ health_notifications_enabled { false }
+ end
end
factory :nextcloud_storage,