Skip to content

Commit

Permalink
Merge pull request #2444 from projectblacklight/view-type-group
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored Apr 22, 2021
2 parents 560af8a + a19c271 commit b4f54e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Deprecation.silence(Blacklight::CatalogHelperBehavior) do
@view_context.render_view_type_group_icon(@view.icon || @key)
end
end

def label
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/blacklight/configuration/view_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions spec/views/catalog/_view_type_group.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<svg></svg>'
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)
Expand All @@ -24,22 +20,25 @@
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

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')
Expand Down

0 comments on commit b4f54e6

Please sign in to comment.