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
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.erbsimilarity index 90%rename from modules/storages/app/components/storages/admin/sidebar/notifications_component.html.erbrename to modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erbindex 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 }) doflex_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") }endnotifications_container.with_row(mt: 2) do@@ -28,7 +28,7 @@endend- notifications_container.with_row(mt: 3) do+ notifications_container.with_row(mt: 3, test_selector: "health-notifications-description") dorender(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }endenddiff --git a/modules/storages/app/components/storages/admin/sidebar/notifications_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rbsimilarity index 77%rename from modules/storages/app/components/storages/admin/sidebar/notifications_component.rbrename to modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rbindex 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 Storagesmodule Admin- class Sidebar::NotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent+ class Sidebar::HealthNotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponentinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers@@ -44,12 +44,12 @@ module Storagesdef notification_statusif 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") }endendenddiff --git a/modules/storages/app/components/storages/admin/sidebar_component.html.erb b/modules/storages/app/components/storages/admin/sidebar_component.html.erbindex 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 dorender(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)) }endend%>diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 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 < ApplicationControllerreturn 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_streamselseflash.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.rbnew file mode 100644index 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+enddiff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rbindex 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 dohealth_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 }+ endendfactory :nextcloud_storage,