Skip to content

Commit

Permalink
Start shifting from individual fields to drop-downs
Browse files Browse the repository at this point in the history
Next steps:
Write a test in the component spec, make a parallel to the guided search fields partial that aligns with the new advanced search (e.g. "clause_1_field", etc.)

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
  • Loading branch information
maxkadel and sandbergja committed Aug 21, 2023
1 parent 9045ee1 commit 5add049
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
<div class="input-criteria">

<div id="guided_search">
<% search_field_controls.each do |control| %>
<%= control %>
<% end %>
<%= render 'advanced/guided_search_fields' %>
<%# search_field_controls.each do |control| %>
<%# control %>
<%# end %>
</div>
</div>
<%# End Column 1 %>
Expand Down
23 changes: 14 additions & 9 deletions app/components/orangelight/advanced_search_form_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ def pub_date_field
def pub_date_presenter
view_context.facet_field_presenter(pub_date_field, {})
end

def initialize_search_field_controls
search_fields.values.each.with_index do |field, i|
search_fields.values.each.with_index do |field, index|
with_search_field_control do
fields_for('clause[]', i, include_id: false) do |f|
content_tag(:div, class: 'form-group advanced-search-field row mb-3') do
f.label(:query, field.display_label('search'), class: "col-sm-3 col-form-label text-md-right") +
content_tag(:div, class: 'col-sm-9') do
f.hidden_field(:field, value: field.key) +
f.text_field(:query, value: query_for_search_clause(field.key), class: 'form-control')
end
fields_for_etc(index:, field:)
end
end
end

def fields_for_etc(index:, field:)
fields_for('clause[]', index, include_id: false) do |foo|
content_tag(:div, class: 'form-group advanced-search-field row mb-3') do
foo.label(:query, field.display_label('search'), class: "col-sm-3 col-form-label text-md-right") +
content_tag(:div, class: 'col-sm-9') do
foo.hidden_field(:field, value: field.key) +
foo.text_field(:query, value: query_for_search_clause(field.key), class: 'form-control')
end
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@

feature :view_components_advanced_search,
description: "When on / true, use the built-in advanced search form. When off / false, use the traditional one"

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject(:render) do
component.render_in(view_context)
end
let(:component) { described_class.new(url: '/whatever', response: , params:) }
let(:component) { described_class.new(url: '/whatever', response:, params:) }

let(:response) do
Blacklight::Solr::Response.new({}.with_indifferent_access, {})
Expand Down Expand Up @@ -35,11 +35,12 @@
allow(view_context).to receive(:facet_limit_for).and_return(nil)
end

it "renders fields in the correct order" do
expected_order = [
"Keyword", "Title", "Author/Creator", "Subject", "Title starts with",
it "has a dropdown with the expected options" do
expected_options = [
"Keyword", "Title", "Author/Creator", "Subject", "Title starts with",
"Publisher", "Notes", "Series title", "ISBN", "ISSN"
]
expect(rendered.all('label').map(&:text)).to match_array(expected_order)
options = rendered.all('select')[1].all('option').map(&:text)
expect(options).to eq(expected_options)
end
end
3 changes: 1 addition & 2 deletions spec/features/advanced_searching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@
expect(page).to have_content('Limit results by')
end

xit 'has drop-downs for search fields' do
it 'has drop-downs for search fields' do
search_fields = page.find_all('.search-field')
expect(search_fields.size).to eq(4)
# expect(page).to have_selector('.search-field')
end

end

context 'with a numismatics advanced search type' do
Expand Down

0 comments on commit 5add049

Please sign in to comment.