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-51021]: Decompose storage list component, and corresponding feature tests
Kabiru Mwenja9e72b5a563c3
diff --git a/modules/storages/app/components/storages/admin/storage_list_component.html.erb b/modules/storages/app/components/storages/admin/storage_list_component.html.erbindex 3f0047245f6..bc6db8ce2e9 100644--- a/modules/storages/app/components/storages/admin/storage_list_component.html.erb+++ b/modules/storages/app/components/storages/admin/storage_list_component.html.erb@@ -23,35 +23,7 @@storages.map do |storage|component.with_row(scheme: :default, id: storage_row_css_id(storage)) do- grid_layout('op-storage-list--row', tag: :div, align_items: :center) do |grid|- grid.with_area(:name, tag: :div, mr: 3, classes: 'ellipsis') do- concat(render(Primer::Beta::Link.new(href: edit_admin_settings_storage_path(storage), scheme: :primary, mr: 1, data: { 'test-selector': 'storage-name' })) { storage.name })-- unless storage.configured?- concat(render(Primer::Beta::Label.new(scheme: :attention, test_selector: "label-incomplete")) { I18n.t('storages.label_incomplete') })- end-- if storage.health_unhealthy?- concat(render(Primer::Beta::Label.new(scheme: :danger, test_selector: "storage-health-label-error")) { I18n.t('storages.health.label_error') })- end- end-- grid.with_area(:host, tag: :div, mr: 3, color: :subtle, data: { 'test-selector': 'storage-host' }, classes: 'ellipsis') do- render(Primer::Beta::Truncate.new(font_weight: :light)) { storage.host }- end-- grid.with_area(:user, tag: :div, color: :subtle, mr: 3, font_weight: :light, data: { 'test-selector': 'storage-creator' }, classes: 'ellipsis') do- render(Users::AvatarComponent.new(user: storage.creator, size: :mini, link: false, show_name: true, name_classes: 'hidden-for-tablet-and-small-laptops'))- end-- grid.with_area(:provider, tag: :div, color: :subtle, mr: 3, hide: :sm, data: { 'test-selector': 'storage-provider' }) do- render(Primer::Beta::Truncate.new(font_weight: :light)) { I18n.t("storages.provider_types.#{storage.short_provider_type}.name") }- end-- grid.with_area(:time, tag: :div, color: :subtle) do- render(Primer::Beta::Text.new(font_weight: :light)) { I18n.t('activity.item.created_on', datetime: helpers.format_time(storage.created_at)).capitalize }- end- end+ render(Storages::Admin::StorageRowComponent.new(storage))endendenddiff --git a/modules/storages/app/components/storages/admin/storage_row_component.html.erb b/modules/storages/app/components/storages/admin/storage_row_component.html.erbnew file mode 100644index 00000000000..415c51b2bc8--- /dev/null+++ b/modules/storages/app/components/storages/admin/storage_row_component.html.erb@@ -0,0 +1,31 @@+<%=+ grid_layout('op-storage-list--row', tag: :div, align_items: :center) do |grid|+ grid.with_area(:name, tag: :div, mr: 3, classes: 'ellipsis') do+ concat(render(Primer::Beta::Link.new(href: url_helpers.edit_admin_settings_storage_path(storage), scheme: :primary, mr: 1, data: { 'test-selector': 'storage-name' })) { storage.name })++ unless storage.configured?+ concat(render(Primer::Beta::Label.new(scheme: :attention, test_selector: "label-incomplete")) { I18n.t('storages.label_incomplete') })+ end++ if storage.health_unhealthy?+ concat(render(Primer::Beta::Label.new(scheme: :danger, test_selector: "storage-health-label-error")) { I18n.t('storages.health.label_error') })+ end+ end++ grid.with_area(:host, tag: :div, mr: 3, color: :subtle, data: { 'test-selector': 'storage-host' }, classes: 'ellipsis') do+ render(Primer::Beta::Truncate.new(font_weight: :light)) { storage.host }+ end++ grid.with_area(:user, tag: :div, color: :subtle, mr: 3, font_weight: :light, data: { 'test-selector': 'storage-creator' }, classes: 'ellipsis') do+ render(Users::AvatarComponent.new(user: storage.creator, size: :mini, link: false, show_name: true, name_classes: 'hidden-for-tablet-and-small-laptops'))+ end++ grid.with_area(:provider, tag: :div, color: :subtle, mr: 3, hide: :sm, data: { 'test-selector': 'storage-provider' }) do+ render(Primer::Beta::Truncate.new(font_weight: :light)) { I18n.t("storages.provider_types.#{storage.short_provider_type}.name") }+ end++ grid.with_area(:time, tag: :div, color: :subtle) do+ render(Primer::Beta::Text.new(font_weight: :light)) { I18n.t('activity.item.created_on', datetime: helpers.format_time(storage.created_at)).capitalize }+ end+ end+%>diff --git a/modules/storages/app/components/storages/admin/storage_row_component.rb b/modules/storages/app/components/storages/admin/storage_row_component.rbnew file mode 100644index 00000000000..dffb1abc1d5--- /dev/null+++ b/modules/storages/app/components/storages/admin/storage_row_component.rb@@ -0,0 +1,38 @@+# frozen_string_literal: true++#-- 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.+#+++#+module Storages::Admin+ class StorageRowComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent+ include OpPrimer::ComponentHelpers+ alias_method :storage, :model++ delegate :url_helpers, to: 'Rails.application.routes'+ end+enddiff --git a/modules/storages/spec/components/storages/admin/storage_list_component_spec.rb b/modules/storages/spec/components/storages/admin/storage_list_component_spec.rbnew file mode 100644index 00000000000..dd688c6d41b--- /dev/null+++ b/modules/storages/spec/components/storages/admin/storage_list_component_spec.rb@@ -0,0 +1,59 @@+#-- 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::StorageListComponent, type: :component do+ shared_let(:nextcloud_storage) { create(:nextcloud_storage) }+ shared_let(:one_drive_storage) { create(:one_drive_storage) }++ let(:storages) { [nextcloud_storage, one_drive_storage] }++ subject(:storage_list_component) { described_class.new(storages) }++ before do+ render_inline(storage_list_component)+ end++ context 'with storages' do+ it 'lists all storages' do+ expect(page).to have_list_item(count: 2)+ expect(page).to have_list_item(nextcloud_storage.name)+ expect(page).to have_list_item(one_drive_storage.name)+ end+ end++ context 'with no storages' do+ let(:storages) { [] }++ it 'renders a blank slate' do+ expect(page).to have_text("You don't have any storages yet.")+ end+ end+enddiff --git a/modules/storages/spec/components/storages/admin/storage_row_component_spec.rb b/modules/storages/spec/components/storages/admin/storage_row_component_spec.rbnew file mode 100644index 00000000000..d9954ac0ed6--- /dev/null+++ b/modules/storages/spec/components/storages/admin/storage_row_component_spec.rb@@ -0,0 +1,130 @@+#-- 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::StorageRowComponent, type: :component do+ include Rails.application.routes.url_helpers++ subject(:storage_row_component) { described_class.new(storage) }++ before do+ render_inline(storage_row_component)+ end++ describe 'Nextcloud storage' do+ shared_examples 'a Nextcloud storage row' do+ it 'render the storage name' do+ expect(page).to have_link(storage.name, href: edit_admin_settings_storage_path(storage))+ end++ it 'renders the storage creator' do+ pending 'Invisible on small screens: Find a way to render inline'+ expect(page).to have_test_selector('storage-creator', text: storage.creator.name)+ end++ it 'renders the storage provider' do+ expect(page).to have_test_selector('storage-provider', text: 'Nextcloud')+ end++ it 'renders the storage host' do+ expect(page).to have_test_selector('storage-host', text: storage.host)+ end+ end++ context 'with complete storage' do+ shared_let(:storage) { create(:nextcloud_storage_with_local_connection) }++ it_behaves_like 'a Nextcloud storage row'++ it 'does not show an incomplete label' do+ expect(page).not_to have_test_selector('label-incomplete')+ end+ end++ context 'with incomplete storage' do+ shared_let(:storage) { create(:nextcloud_storage) }++ it_behaves_like 'a Nextcloud storage row'++ it 'renders an "Incomplete" label' do+ expect(page).to have_test_selector('label-incomplete', text: 'Incomplete')+ end+ end++ context 'with unhealthy storage' do+ shared_let(:storage) do+ create(:nextcloud_storage_with_complete_configuration, :as_unhealthy)+ end++ it_behaves_like 'a Nextcloud storage row'++ it 'renders an "Error" label' do+ expect(page).to have_test_selector('storage-health-label-error', text: 'Error')+ end+ end+ end++ describe 'OneDrive/SharePoint storage' do+ shared_examples 'a OneDrive/SharePoint storage row' do+ it 'render the storage name' do+ expect(page).to have_link(storage.name, href: edit_admin_settings_storage_path(storage))+ end++ it 'renders the storage creator' do+ pending 'Invisible on small screens: Find a way to render inline'+ expect(page).to have_test_selector('storage-creator', text: storage.creator.name)+ end++ it 'renders the storage provider' do+ expect(page).to have_test_selector('storage-provider', text: 'OneDrive/SharePoint')+ end+ end++ context 'with complete storage' do+ shared_let(:storage) { create(:sharepoint_dev_drive_storage) }++ it_behaves_like 'a OneDrive/SharePoint storage row'++ it 'does not show an incomplete label' do+ expect(page).not_to have_test_selector('label-incomplete')+ end+ end++ context 'with incomplete storage' do+ shared_let(:storage) { create(:one_drive_storage) }++ it_behaves_like 'a OneDrive/SharePoint storage row'++ it 'renders an "Incomplete" label' do+ expect(page).to have_test_selector('label-incomplete', text: 'Incomplete')+ end+ end+ end+enddiff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rbindex 3421c8b4f30..96835920676 100644--- a/modules/storages/spec/features/admin_storages_spec.rb+++ b/modules/storages/spec/features/admin_storages_spec.rb@@ -40,69 +40,32 @@ RSpec.describe 'Admin storages',describe 'File storages list' docontext 'with storages' do- shared_let(:complete_storage) { create(:nextcloud_storage_with_local_connection) }- shared_let(:incomplete_storage) { create(:nextcloud_storage) }- shared_let(:complete_nextcloud_storage_health_pending) { create(:nextcloud_storage_with_complete_configuration) }+ shared_let(:nextcloud_storage) { create(:nextcloud_storage) }+ shared_let(:one_drive_storage) { create(:one_drive_storage) }- shared_let(:complete_nextcloud_storage_health_healthy) do- create(:nextcloud_storage_with_complete_configuration, :as_healthy)- end-- shared_let(:complete_nextcloud_storage_health_unhealthy) do- create(:nextcloud_storage_with_complete_configuration, :as_unhealthy)- end-- it 'renders a list of storages' do+ before dovisit admin_settings_storages_path+ end- expect(page).to be_axe_clean.within '#content'-- expect(page).to have_test_selector('storage-name', text: complete_storage.name)- expect(page).to have_test_selector('storage-name', text: incomplete_storage.name)- expect(page).to have_button 'Storage', aria: { label: 'Add new storage' }-- within "li#storages_nextcloud_storage_#{complete_storage.id}" do- expect(page).not_to have_test_selector('label-incomplete')- expect(page).to have_link(complete_storage.name, href: edit_admin_settings_storage_path(complete_storage))- expect(page).to have_test_selector('storage-creator', text: complete_storage.creator.name)- expect(page).to have_test_selector('storage-provider', text: 'Nextcloud')- expect(page).to have_test_selector('storage-host', text: complete_storage.host)- end-- within "li#storages_nextcloud_storage_#{incomplete_storage.id}" do- expect(page).to have_test_selector('label-incomplete')- expect(page).to have_test_selector('storage-name', text: incomplete_storage.name)- expect(page).to have_test_selector('storage-provider', text: 'Nextcloud')- expect(page).to have_test_selector('storage-host', text: incomplete_storage.host)- expect(page).to have_css('.op-principal--name', text: incomplete_storage.creator.name)- end-- within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_pending.id}" do- expect(page).not_to have_test_selector('storage-health-label-error')- expect(page).not_to have_test_selector('storage-health-label-healthy')- expect(page).not_to have_test_selector('storage-health-label-pending')- end-- within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_healthy.id}" do- expect(page).not_to have_test_selector('storage-health-label-healthy')- expect(page).not_to have_test_selector('storage-health-label-error')- expect(page).not_to have_test_selector('storage-health-label-pending')+ it 'renders a list of all storages' do+ within :css, '#content' do+ expect(page).to have_list_item(count: 5)+ expect(page).to have_list_item(nextcloud_storage.name)+ expect(page).to have_list_item(one_drive_storage.name)end+ end- within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_unhealthy.id}" do- expect(page).to have_test_selector('storage-health-label-error')- expect(page).not_to have_test_selector('storage-health-label-healthy')- expect(page).not_to have_test_selector('storage-health-label-pending')- end+ it 'renders content that is accessible' do+ expect(page).to be_axe_clean.within('#content')endendcontext 'with no storages' do- it 'renders a blank slate' do+ before dovisit admin_settings_storages_path+ end- expect(page).to be_axe_clean.within '#content'-+ it 'renders a blank slate' do# Show Add storage buttonexpect(page).to have_button 'Storage', aria: { label: 'Add new storage' }@@ -111,6 +74,10 @@ RSpec.describe 'Admin storages',expect(page.find('.PageHeader-title')).to have_text('File storages')expect(page).to have_text("You don't have any storages yet.")end++ it 'renders content that is accessible' do+ expect(page).to be_axe_clean.within('#content')+ endendend