-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve how adv search handles incoming params (#3278)
* Prevent duplicate hidden fields in adv search form * Apply incoming inclusive facets to adv search form * Correct misleading test description - use rspec `is_expected` syntax to simplify tests
- Loading branch information
Showing
6 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/presenters/blacklight/facet_checkbox_item_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
class FacetCheckboxItemPresenter < Blacklight::FacetItemPresenter | ||
# Check if the query parameters have any inclusive facets with the given value | ||
# @return [Boolean] | ||
def selected? | ||
search_state.filter(facet_config).values(except: [:filters, :missing]).flatten.include?(value) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/presenters/blacklight/facet_checkbox_item_presenter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Blacklight::FacetCheckboxItemPresenter, type: :presenter do | ||
subject(:presenter) do | ||
described_class.new(facet_item, facet_config, view_context, facet_field, search_state) | ||
end | ||
|
||
let(:facet_item) { Blacklight::Solr::Response::Facets::FacetItem.new(value: 'Book', hits: 30) } | ||
let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'format') } | ||
let(:view_context) { controller.view_context } | ||
let(:filter_field) { Blacklight::SearchState::FilterField.new(facet_config, search_state) } | ||
let(:facet_field) { Blacklight::Solr::Response::Facets::FacetField.new('format', [facet_item]) } | ||
let(:params) { ActionController::Parameters.new(f_inclusive: { format: ["Book"] }) } | ||
let(:blacklight_config) { Blacklight::Configuration.new } | ||
let(:search_state) { Blacklight::SearchState.new(params, blacklight_config) } | ||
|
||
before do | ||
blacklight_config.add_facet_field 'format' | ||
end | ||
|
||
describe '#selected?' do | ||
subject { presenter.selected? } | ||
|
||
context 'with a matching inclusive filter' do | ||
it { is_expected.to be true } | ||
end | ||
|
||
context 'with an inclusive filter that does not match' do | ||
let(:params) { ActionController::Parameters.new(f_inclusive: { format: ["Manuscript"] }) } | ||
|
||
it { is_expected.to be false } | ||
end | ||
|
||
context 'with a matching exclusive filter' do | ||
let(:params) { ActionController::Parameters.new(f: { format: ["Book"] }) } | ||
|
||
it { is_expected.to be false } | ||
end | ||
end | ||
end |