spec/components/blacklight/constraints_component_spec.rb in blacklight-7.40.0 vs spec/components/blacklight/constraints_component_spec.rb in blacklight-8.0.0.beta1
- old
+ new
@@ -11,17 +11,25 @@
{ search_state: search_state }
end
let(:blacklight_config) do
Blacklight::Configuration.new.configure do |config|
- config.add_facet_field 'some_facet'
+ 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 no constraints' do
+ describe '#render?' do
+ it 'is false' do
+ expect(component.render?).to be false
+ end
+ end
+ end
+
context 'with a query' do
let(:query_params) { { q: 'some query' } }
it 'renders a start-over link' do
expect(rendered).to have_link 'Start Over', href: '/catalog'
@@ -41,24 +49,20 @@
end
context 'with a facet' do
let(:query_params) { { f: { some_facet: ['some value'] } } }
- before do
- controller.blacklight_config.configure do |config|
- config.add_facet_field :some_facet
- end
+ it 'renders the query' do
+ expect(rendered).to have_selector('.constraint-value > .filter-name', text: 'Some Facet').and(have_selector('.constraint-value > .filter-value', text: 'some value'))
end
- # this has to be cleaned up to prevent leaking class configuration
- after do
- controller.blacklight_config.configure do |config|
- config['facet_fields'].delete('some_facet')
- end
- end
+ context 'that is not configured' do
+ let(:query_params) { { f: { some_facet: ['some value'], missing: ['another value'] } } }
- it 'renders the query' do
- expect(rendered).to have_selector('.constraint-value > .filter-name', text: 'Some Facet').and(have_selector('.constraint-value > .filter-value', text: 'some value'))
+ it 'renders only the configured constraints' do
+ expect(rendered).to have_selector('.constraint-value > .filter-name', text: 'Some Facet').and(have_selector('.constraint-value > .filter-value', text: 'some value'))
+ expect(rendered).not_to have_selector('.constraint-value > .filter-name', text: 'Missing')
+ end
end
end
describe '.for_search_history' do
subject(:component) { described_class.for_search_history(**params) }