Skip to content

Commit

Permalink
Incorporate feedback from review
Browse files Browse the repository at this point in the history
* Make this feature opt-in.  You can add suggest: true to your facet config in the catalog controller to start using it.
* Use text_field_tag
  • Loading branch information
sandbergja committed Oct 22, 2024
1 parent 079ec45 commit efab330
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
14 changes: 7 additions & 7 deletions app/components/blacklight/search/facet_suggest_input.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<label for="facet-suggest-<%= facet.key %>">
<label for="facet_suggest_<%= facet.key %>">
<%= I18n.t('blacklight.search.facets.suggest.label', field_label: presenter&.label) %>
</label>
<input class="facet-suggest form-control"
id="facet-suggest-<%= facet.key %>"
data-facet-field="<%= facet.key %>"
name="facet_suggest_<%= facet.key %>"
placeholder="<%= I18n.t('blacklight.search.form.search.placeholder') %>">
</input>
<%= text_field_tag "facet_suggest_#{facet.key}",
nil,
class: "facet-suggest form-control",
data: {facet_field: facet.key},
placeholder: I18n.t('blacklight.search.form.search.placeholder')
%>
4 changes: 4 additions & 0 deletions app/components/blacklight/search/facet_suggest_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def initialize(facet:, presenter:)
private

attr_accessor :facet, :presenter

def render?
facet&.suggest
end
end
end
end
18 changes: 16 additions & 2 deletions spec/components/blacklight/search/facet_suggest_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'

RSpec.describe Blacklight::Search::FacetSuggestInput, type: :component do
let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet' }
let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet', suggest: true }
let(:presenter) { instance_double(Blacklight::FacetFieldPresenter) }

before do
Expand All @@ -26,8 +26,22 @@
expect(label.text.strip).to eq 'Filter Language'

id_in_label_for = label.attribute('for').text
expect(id_in_label_for).to eq('facet-suggest-language_facet')
expect(id_in_label_for).to eq('facet_suggest_language_facet')

expect(rendered.css('input').first.attribute('id').text).to eq id_in_label_for
end

context 'when the facet is explicitly configured to suggest: false' do
let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet', suggest: false }
it 'does not display' do
expect(render_inline(described_class.new(facet: facet, presenter: presenter)).to_s).to eq ''
end
end

context 'when the facet is not explicitly configured with a suggest key' do
let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet' }
it 'does not display' do
expect(render_inline(described_class.new(facet: facet, presenter: presenter)).to_s).to eq ''
end
end
end
24 changes: 16 additions & 8 deletions spec/features/facets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,23 @@
end

describe 'Facet modal' do
it 'allows the user to filter a long list of facet values', :js do
visit '/catalog/facet/subject_ssim'
expect(page).to have_no_link 'Old age' # This is on the second page of facet values
expect(page).to have_css 'a.facet-select', count: 20

fill_in 'facet_suggest_subject_ssim', with: "ag"
context 'when configured' do
before do
enabled = CatalogController.blacklight_config.dup
enabled.facet_fields[:subject_ssim].merge!({suggest: true})
allow(CatalogController).to receive(:blacklight_config).and_return enabled
end

expect(page).to have_link 'Old age'
expect(page).to have_css 'a.facet-select', count: 2
it 'allows the user to filter a long list of facet values', :js do
visit '/catalog/facet/subject_ssim'
expect(page).to have_no_link 'Old age' # This is on the second page of facet values
expect(page).to have_css 'a.facet-select', count: 20

fill_in 'facet_suggest_subject_ssim', with: "ag"

expect(page).to have_link 'Old age'
expect(page).to have_css 'a.facet-select', count: 2
end
end
end
end

0 comments on commit efab330

Please sign in to comment.