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

Rewrite Sidebar in storages to SidePanel component

Oliver Günthercdde6f895b6a
diff --git a/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb
new file mode 100644
index 00000000000..a1b75fa4926
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.html.erb
@@ -0,0 +1,65 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ component_wrapper(data: { turbo: true }) do
+ render(Primer::OpenProject::SidePanel::Section.new) do |section|
+ section.with_title { t("storages.health_email_notifications.title") }
+
+ flex_layout do |notifications_container|
+ notifications_container.with_row(mt: 2) do
+ form_for(@storage, method: :patch,
+ url: change_health_notifications_enabled_admin_settings_storage_path(@storage),
+ data: { turbo_stream: true }) do |f|
+ flex_layout do |notification_status_actions|
+ notification_status_actions.with_row do
+ f.hidden_field :health_notifications_enabled, value: (@storage.health_notifications_should_be_sent? ? "0" : "1")
+ end
+
+ notification_status_actions.with_row(test_selector: "storage-health-notifications-button") do
+ render(Primer::Beta::Button.new(
+ scheme: :default,
+ block: :true,
+ type: :submit
+ )) do |button|
+ button.with_leading_visual_icon(icon: notification_status[:icon])
+ notification_status[:label]
+ end
+ end
+ end
+ end
+ end
+
+ notifications_container.with_row(mt: 3, test_selector: "storage-health-notifications-description") do
+ render(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb
similarity index 94%
rename from modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
rename to modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb
index 38c5f4f8c5f..f27e0207198 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
+++ b/modules/storages/app/components/storages/admin/side_panel/health_notifications_component.rb
@@ -28,7 +28,7 @@
module Storages
module Admin
- class Sidebar::HealthNotificationsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class SidePanel::HealthNotificationsComponent < ApplicationComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
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
new file mode 100644
index 00000000000..2d1abf098db
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/side_panel/health_status_component.html.erb
@@ -0,0 +1,87 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ component_wrapper do
+ render(Primer::OpenProject::SidePanel::Section.new) do |section|
+ section.with_title { I18n.t("storages.health.title") }
+
+ flex_layout do |health_status_container|
+ if @storage.provider_type_one_drive?
+ health_status_container.with_row(mt: 2) do
+ render(Storages::Admin::SidePanel::ValidationResultComponent.new(result: validation_result_placeholder))
+ end
+
+ health_status_container.with_row(mt: 2) do
+ primer_form_with(
+ model: @storage,
+ url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
+ method: :post,
+ data: { turbo: true }
+ ) do
+ render(Primer::Beta::Button.new(
+ scheme: :link,
+ color: :default,
+ font_weight: :bold,
+ type: :submit,
+ )) do |button|
+ button.with_leading_visual_icon(icon: "meter")
+ I18n.t("storages.health.connection_validation.action")
+ end
+ end
+ end
+ end
+
+ if @storage.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))
+ end)
+
+ concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
+ health_status_indicator[:label]
+ end)
+ end
+
+ if @storage.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
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb b/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
similarity index 99%
rename from modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
rename to modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
index 97a3383375a..74c53fb2156 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_status_component.rb
+++ b/modules/storages/app/components/storages/admin/side_panel/health_status_component.rb
@@ -30,7 +30,7 @@
module Storages
module Admin
- module Sidebar
+ module SidePanel
class HealthStatusComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include ApplicationHelper
include OpTurbo::Streamable
diff --git a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb b/modules/storages/app/components/storages/admin/side_panel/validation_result_component.html.erb
similarity index 55%
rename from modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb
rename to modules/storages/app/components/storages/admin/side_panel/validation_result_component.html.erb
index b50ef244204..c92d05827ac 100644
--- a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.html.erb
+++ b/modules/storages/app/components/storages/admin/side_panel/validation_result_component.html.erb
@@ -29,30 +29,28 @@ See COPYRIGHT and LICENSE files for more details.
<%=
component_wrapper do
- flex_layout do |container|
- container.with_row do
- render(Primer::Beta::Text.new(font_weight: :bold, test_selector: "validation-result--subtitle")) do
- I18n.t("storages.health.connection_validation.subtitle")
- end
- end
-
- if @result.validation_result_exists?
- container.with_row(mt: 2) do
- status = status_indicator
-
- concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "validation-result--timestamp")) do
- I18n.t('storages.health.checked', datetime: helpers.format_time(@result.timestamp))
- end)
- concat(render(Primer::Beta::Label.new(scheme: status[:scheme])) { status[:label] })
+ render(Primer::OpenProject::SidePanel::Section.new) do |section|
+ section.with_title(test_selector: "validation-result--subtitle") { I18n.t("storages.health.connection_validation.subtitle") }
+
+ flex_layout do |container|
+ if @result.validation_result_exists?
+ container.with_row(mt: 2) do
+ status = status_indicator
+
+ concat(render(Primer::Beta::Text.new(pr: 2, test_selector: "validation-result--timestamp")) do
+ I18n.t('storages.health.checked', datetime: helpers.format_time(@result.timestamp))
+ end)
+ concat(render(Primer::Beta::Label.new(scheme: status[:scheme])) { status[:label] })
+ end
end
- end
- if @result.description.present?
- prefix = @result.error_code? ? "#{@result.error_code.upcase}: " : ""
+ if @result.description.present?
+ prefix = @result.error_code? ? "#{@result.error_code.upcase}: " : ""
- container.with_row(mt: 2) do
- render(Primer::Beta::Text.new(color: :muted, test_selector: "validation-result--description")) do
- prefix + @result.description
+ container.with_row(mt: 2) do
+ render(Primer::Beta::Text.new(color: :muted, test_selector: "validation-result--description")) do
+ prefix + @result.description
+ end
end
end
end
diff --git a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb b/modules/storages/app/components/storages/admin/side_panel/validation_result_component.rb
similarity index 99%
rename from modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb
rename to modules/storages/app/components/storages/admin/side_panel/validation_result_component.rb
index f145051b292..9cfef307513 100644
--- a/modules/storages/app/components/storages/admin/sidebar/validation_result_component.rb
+++ b/modules/storages/app/components/storages/admin/side_panel/validation_result_component.rb
@@ -30,7 +30,7 @@
module Storages
module Admin
- module Sidebar
+ module SidePanel
class ValidationResultComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
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
new file mode 100644
index 00000000000..4282f7d9710
--- /dev/null
+++ b/modules/storages/app/components/storages/admin/side_panel_component.html.erb
@@ -0,0 +1,11 @@
+<%=
+ component_wrapper do
+ render(Primer::OpenProject::SidePanel.new) do |panel|
+ panel.with_section(Storages::Admin::SidePanel::HealthStatusComponent.new(storage: @storage))
+
+ if @storage.automatic_management_enabled?
+ panel.with_section(Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))
+ end
+ end
+ end
+%>
diff --git a/modules/storages/app/components/storages/admin/sidebar_component.rb b/modules/storages/app/components/storages/admin/side_panel_component.rb
similarity index 93%
rename from modules/storages/app/components/storages/admin/sidebar_component.rb
rename to modules/storages/app/components/storages/admin/side_panel_component.rb
index d9224ca87ce..7b277475c7c 100644
--- a/modules/storages/app/components/storages/admin/sidebar_component.rb
+++ b/modules/storages/app/components/storages/admin/side_panel_component.rb
@@ -28,7 +28,7 @@
module Storages
module Admin
- class SidebarComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class SidePanelComponent < ApplicationComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
deleted file mode 100644
index 475f69d103e..00000000000
--- a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
+++ /dev/null
@@ -1,65 +0,0 @@
-<%#-- 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.
-
-++#%>
-
-<%=
- 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.health_email_notifications.title") }
- end
-
- notifications_container.with_row(mt: 2) do
- form_for(@storage, method: :patch,
- url: change_health_notifications_enabled_admin_settings_storage_path(@storage),
- data: { turbo_stream: true }) do |f|
- flex_layout do |notification_status_actions|
- notification_status_actions.with_row do
- f.hidden_field :health_notifications_enabled, value: (@storage.health_notifications_should_be_sent? ? "0" : "1")
- end
-
- notification_status_actions.with_row(test_selector: "storage-health-notifications-button") do
- render(Primer::Beta::Button.new(
- scheme: :default,
- block: :true,
- type: :submit
- )) do |button|
- button.with_leading_visual_icon(icon: notification_status[:icon])
- notification_status[:label]
- end
- end
- end
- end
- end
-
- notifications_container.with_row(mt: 3, test_selector: "storage-health-notifications-description") do
- render(Primer::Beta::Text.new(color: :subtle)) { notification_status[:description] }
- end
- end
- end
-%>
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
deleted file mode 100644
index 81159ee2538..00000000000
--- a/modules/storages/app/components/storages/admin/sidebar/health_status_component.html.erb
+++ /dev/null
@@ -1,87 +0,0 @@
-<%#-- 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.
-
-++#%>
-
-<%=
- component_wrapper do
- flex_layout do |health_status_container|
- health_status_container.with_row do
- render(Primer::Beta::Heading.new(tag: :h4)) { I18n.t("storages.health.title") }
- end
-
- if @storage.provider_type_one_drive?
- health_status_container.with_row(mt: 2) do
- render(Storages::Admin::Sidebar::ValidationResultComponent.new(result: validation_result_placeholder))
- end
-
- health_status_container.with_row(mt: 2) do
- primer_form_with(
- model: @storage,
- url: validate_connection_admin_settings_storage_connection_validation_path(@storage),
- method: :post,
- data: { turbo: true }
- ) do
- render(Primer::Beta::Button.new(
- scheme: :link,
- color: :default,
- font_weight: :bold,
- type: :submit,
- )) do |button|
- button.with_leading_visual_icon(icon: "meter")
- I18n.t("storages.health.connection_validation.action")
- end
- end
- end
- end
-
- if @storage.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))
- end)
-
- concat(render(Primer::Beta::Label.new(scheme: health_status_indicator[:scheme], test_selector: "storage-health-status")) do
- health_status_indicator[:label]
- end)
- end
-
- if @storage.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
- end
- end
- end
- 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
deleted file mode 100644
index 918d19b5039..00000000000
--- a/modules/storages/app/components/storages/admin/sidebar_component.html.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<%=
- component_wrapper do
- render(Primer::OpenProject::BorderGrid.new) do |border_grid|
- border_grid.with_row { render(Storages::Admin::Sidebar::HealthStatusComponent.new(storage: @storage)) }
-
- if @storage.automatic_management_enabled?
- border_grid.with_row { render(Storages::Admin::Sidebar::HealthNotificationsComponent.new(storage: @storage)) }
- end
- end
- end
-%>
diff --git a/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb b/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb
index fd758c0ea16..612dda1c2a6 100644
--- a/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/connection_validation_controller.rb
@@ -45,7 +45,7 @@ module Storages
@result = Peripherals::OneDriveConnectionValidator
.new(storage: @storage)
.validate
- update_via_turbo_stream(component: Sidebar::ValidationResultComponent.new(result: @result))
+ update_via_turbo_stream(component: SidePanel::ValidationResultComponent.new(result: @result))
respond_to_with_turbo_streams
end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 13ec7e2007b..1e9f59714f7 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -188,7 +188,7 @@ class Storages::Admin::StoragesController < ApplicationController
return head :bad_request 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::HealthNotificationsComponent.new(storage: @storage))
+ update_via_turbo_stream(component: Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))
respond_with_turbo_streams
else
flash.now[:primer_banner] = {
diff --git a/modules/storages/app/views/storages/admin/storages/edit.html.erb b/modules/storages/app/views/storages/admin/storages/edit.html.erb
index 8d8e7f2d2d1..20814d8e371 100644
--- a/modules/storages/app/views/storages/admin/storages/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/edit.html.erb
@@ -49,7 +49,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= render(::Storages::Admin::StorageViewComponent.new(@storage)) %>
<% end %>
<% component.with_sidebar(col_placement: :end, row_placement: :end) do %>
- <%= render(::Storages::Admin::SidebarComponent.new(storage: @storage)) %>
+ <%= render(::Storages::Admin::SidePanelComponent.new(storage: @storage)) %>
<% end %>
<% end %>
<% else %>
diff --git a/modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb b/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb
similarity index 96%
rename from modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb
rename to modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb
index 84d53ab7a06..1657540b466 100644
--- a/modules/storages/spec/components/storages/admin/sidebar/health_notifications_component_spec.rb
+++ b/modules/storages/spec/components/storages/admin/side_panel/health_notifications_component_spec.rb
@@ -29,7 +29,7 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe Storages::Admin::Sidebar::HealthNotificationsComponent, type: :component do
+RSpec.describe Storages::Admin::SidePanel::HealthNotificationsComponent, type: :component do
context "when subscribed to email notifications" do
let(:storage) { build_stubbed(:nextcloud_storage, :with_health_notifications_enabled, :as_automatically_managed) }
diff --git a/modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb b/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
similarity index 97%
rename from modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb
rename to modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
index 5ad2634d581..31d4d4bac7d 100644
--- a/modules/storages/spec/components/storages/admin/sidebar/health_status_component_spec.rb
+++ b/modules/storages/spec/components/storages/admin/side_panel/health_status_component_spec.rb
@@ -29,7 +29,7 @@
require "spec_helper"
require_module_spec_helper
-RSpec.describe Storages::Admin::Sidebar::HealthStatusComponent, type: :component do
+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:) }
diff --git a/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb b/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb
index b3b0cfe7b9d..c5d3aa89ede 100644
--- a/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb
+++ b/modules/storages/spec/requests/storages/admin/connection_validation_spec.rb
@@ -31,6 +31,10 @@ require "spec_helper"
RSpec.describe "connection validation", :skip_csrf do
describe "POST /admin/settings/storages/:id/connection_validation/validate_connection" do
let(:storage) { create(:one_drive_storage) }
+ let(:template_body) do
+ template = Nokogiri(last_response.body).css("template").first.inner_html
+ Capybara.string(template)
+ end
let(:user) { create(:admin) }
let(:validator) do
double = instance_double(Storages::Peripherals::OneDriveConnectionValidator)
@@ -52,25 +56,24 @@ RSpec.describe "connection validation", :skip_csrf do
it "returns a turbo update template" do
expect(subject.status).to eq(200)
- doc = Nokogiri::HTML(subject.body)
- expect(doc.xpath(xpath_for_subtitle).text).to eq("Connection validation")
+ expect(template_body).to have_test_selector("validation-result--subtitle", text: "Connection validation")
if show_timestamp
- expect(doc.xpath(xpath_for_timestamp)).not_to be_empty
+ expect(template_body).to have_test_selector("validation-result--timestamp")
else
- expect(doc.xpath(xpath_for_timestamp)).to be_empty
+ expect(template_body).not_to have_test_selector("validation-result--timestamp")
end
if label.present?
- expect(doc.xpath(xpath_for_label).text).to eq(label)
+ expect(template_body).to have_css(".Label", text: label)
else
- expect(doc.xpath(xpath_for_label).text).to be_empty
+ expect(template_body).to have_no_selector(".Label")
end
if description.present?
- expect(doc.xpath(xpath_for_description).text).to eq(description)
+ expect(template_body).to have_test_selector("validation-result--description", text: description)
else
- expect(doc.xpath(xpath_for_description).text).to be_empty
+ expect(template_body).not_to have_test_selector("validation-result--description", text: description)
end
end
end
@@ -119,24 +122,4 @@ RSpec.describe "connection validation", :skip_csrf do
show_timestamp: true, label: "Healthy", description: nil
end
end
-
- private
-
- def xpath_for_subtitle
- "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--subtitle']"
- end
-
- def xpath_for_timestamp
- "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--timestamp']"
- end
-
- def xpath_for_label
- "#{xpath_for_turbo_target}/div/div/span[contains(@class, 'Label')]"
- end
-
- def xpath_for_description
- "#{xpath_for_turbo_target}/div/div/span[@data-test-selector='validation-result--description']"
- end
-
- def xpath_for_turbo_target = "//turbo-stream[@target='storages-admin-sidebar-validation-result-component']/template"
end