From 465917e0cc42a72904a126b4bced1a011188fd41 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 21 Apr 2021 16:46:43 -0700 Subject: [PATCH 1/3] Pass the icon key to the render_view_type_group_icon helper --- .../blacklight/response/view_type_button_component.rb | 2 +- lib/blacklight/configuration/view_config.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/blacklight/response/view_type_button_component.rb b/app/components/blacklight/response/view_type_button_component.rb index 0bc7ad0034..5d283e6118 100644 --- a/app/components/blacklight/response/view_type_button_component.rb +++ b/app/components/blacklight/response/view_type_button_component.rb @@ -15,7 +15,7 @@ def initialize(view:, key: nil, selected: false, search_state: nil, classes: 'bt end def icon - @view_context.render_view_type_group_icon(@view) + @view_context.render_view_type_group_icon(@view.icon || @key) end def label diff --git a/lib/blacklight/configuration/view_config.rb b/lib/blacklight/configuration/view_config.rb index 8072222bff..bb2f424f97 100644 --- a/lib/blacklight/configuration/view_config.rb +++ b/lib/blacklight/configuration/view_config.rb @@ -11,6 +11,8 @@ class ViewConfig < Blacklight::OpenStructWithHashAccess # @return [String, Symbol] solr field to use to render a document title # @!attribute display_type_field # @return [String, Symbol] solr field to use to render format-specific partials + # @!attribute icon + # @return [String, Symbol] icon file to use in the view picker # @!attribute document_actions # @return [NestedOpenStructWithHashAccess{Symbol => Blacklight::Configuration::ToolConfig}] 'tools' to render for each document def search_bar_presenter_class From b9b2a03ffb118965feaf973505db26d5612d1155 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 21 Apr 2021 16:49:21 -0700 Subject: [PATCH 2/3] Deprecate render_view_type_group_icon, which is just a pass-through to blacklight_icon --- .../blacklight/response/view_type_button_component.rb | 4 +++- app/helpers/blacklight/catalog_helper_behavior.rb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/components/blacklight/response/view_type_button_component.rb b/app/components/blacklight/response/view_type_button_component.rb index 5d283e6118..581bd7a44d 100644 --- a/app/components/blacklight/response/view_type_button_component.rb +++ b/app/components/blacklight/response/view_type_button_component.rb @@ -15,7 +15,9 @@ def initialize(view:, key: nil, selected: false, search_state: nil, classes: 'bt end def icon - @view_context.render_view_type_group_icon(@view.icon || @key) + Deprecation.silence(Blacklight::CatalogHelperBehavior) do + @view_context.render_view_type_group_icon(@view.icon || @key) + end end def label diff --git a/app/helpers/blacklight/catalog_helper_behavior.rb b/app/helpers/blacklight/catalog_helper_behavior.rb index 685a2511a6..33440f755c 100644 --- a/app/helpers/blacklight/catalog_helper_behavior.rb +++ b/app/helpers/blacklight/catalog_helper_behavior.rb @@ -253,11 +253,13 @@ def thumbnail_url document ## # Render the view type icon for the results view picker # + # @deprecated # @param [String] view # @return [String] def render_view_type_group_icon view blacklight_icon(view) end + deprecation_deprecate render_view_type_group_icon: 'call blacklight_icon instead' ## # Get the default view type classes for a view in the results view picker From a19c271c5612055fdce437aabae002fd52769427 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 21 Apr 2021 16:50:11 -0700 Subject: [PATCH 3/3] Replace stubbing by configuring the view icon to use one that actually exists --- .../catalog/_view_type_group.html.erb_spec.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spec/views/catalog/_view_type_group.html.erb_spec.rb b/spec/views/catalog/_view_type_group.html.erb_spec.rb index 5b2b49f52c..60fc86fa7b 100644 --- a/spec/views/catalog/_view_type_group.html.erb_spec.rb +++ b/spec/views/catalog/_view_type_group.html.erb_spec.rb @@ -3,13 +3,9 @@ RSpec.describe "catalog/_view_type_group" do let(:blacklight_config) { Blacklight::Configuration.new } let(:response) { instance_double(Blacklight::Solr::Response, empty?: false) } - let(:icon_instance) { instance_double(Blacklight::Icon) } before do allow(view).to receive(:view_label), &:to_s - allow(Blacklight::Icon).to receive(:new).and_return icon_instance - allow(icon_instance).to receive(:svg).and_return '' - allow(icon_instance).to receive(:options).and_return({}) allow(view).to receive_messages(how_sort_and_per_page?: true, blacklight_config: blacklight_config) controller.request.path_parameters[:action] = 'index' assign(:response, response) @@ -24,13 +20,16 @@ it "displays the group" do blacklight_config.configure do |config| config.view.delete(:list) - config.view.a - config.view.b - config.view.c + config.view.a.icon = :list + config.view.b.icon = :list + config.view.c.icon = :list end render partial: 'catalog/view_type_group' expect(rendered).to have_selector('.btn-group.view-type-group') expect(rendered).to have_selector('.view-type-a', text: 'a') + within '.view-type-a' do + expect(rendered).to have_selector 'svg' + end expect(rendered).to have_selector('.view-type-b', text: 'b') expect(rendered).to have_selector('.view-type-c', text: 'c') end @@ -38,8 +37,8 @@ it "sets the current view to 'active'" do blacklight_config.configure do |config| config.view.delete(:list) - config.view.a - config.view.b + config.view.a.icon = :list + config.view.b.icon = :list end render partial: 'catalog/view_type_group' expect(rendered).to have_selector('.active', text: 'a')