Skip to content

Commit

Permalink
Add a test for the constraints component. Add catalog_controller to m…
Browse files Browse the repository at this point in the history
…ake human_readable_type filterable in hyrax 4
  • Loading branch information
bbpennel committed Sep 22, 2023
1 parent 9cfa24e commit 543d40d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def single_item_search_builder(id)
config.add_facet_field solr_name('edition', :facetable), label: 'Version', limit: 5
config.add_facet_field solr_name('language', :facetable), helper_method: :language_links_facets, limit: 5
config.add_facet_field solr_name('member_of_collections', :symbol), limit: 5, label: 'Collection'
config.add_facet_field solr_name('human_readable_type', :facetable), label: 'Type', show: false

# The generic_type isn't displayed on the facet list
# It's used to give a label to the filter that comes from the user profile
Expand Down
65 changes: 65 additions & 0 deletions spec/components/hyc/constraints_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'rails_helper'

RSpec.describe Hyc::ConstraintsComponent, type: :component do
subject(:component) { described_class.new(**params) }
let(:rendered) { render_inline(component).to_s }

let(:page) { Capybara::Node::Simple.new(rendered) }

let(:params) do
{ search_state: search_state }
end

let(:blacklight_config) do
Blacklight::Configuration.new.configure do |config|
config.add_facet_field 'some_facet'
end
end

let(:search_state) { Blacklight::SearchState.new(query_params.with_indifferent_access, blacklight_config) }
let(:query_params) { {} }

context 'with a query' do
let(:query_params) { { q: 'some query' } }

it 'renders a start-over link' do
expect(page).to have_link 'Start Over', href: '/catalog?locale=en'
end

it 'has a header' do
expect(page).to have_selector('h2', text: 'Search Constraints')
end

it 'wraps the output in a div' do
expect(page).to have_selector('div#appliedParams')
end

it 'renders the query' do
expect(page).to have_selector('.applied-filter.constraint', text: 'some query')
end
end

context 'with a collections type' do
let(:query_params) { { f: { human_readable_type_sim: ['Collection'] } } }

it 'does not render a start-over link' do
expect(page).to_not have_link 'Start Over'
end

it 'does not have a header' do
expect(page).to_not have_selector('h2', text: 'Search Constraints')
end
end

context 'with a different type selected' do
let(:query_params) { { f: { human_readable_type_sim: ['AdminSet'] } } }

it 'renders a start-over link' do
expect(page).to have_link 'Start Over', href: '/catalog?locale=en'
end

it 'has a header' do
expect(page).to have_selector('h2', text: 'Search Constraints')
end
end
end
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@

config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)

config.include ViewComponent::TestHelpers, type: :component
end

0 comments on commit 543d40d

Please sign in to comment.