Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: retain the search scope and query terms in the search form on… #1504

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/components/arclight/search_bar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%= render(Blacklight::SearchBarComponent.new(
**@kwargs,
params: @params.merge(f: (@params[:f] || {}).except(:collection)))) do |c| %>
params: @params.merge(f: (@params[:f] || {}).except(:collection)),
q: @q,
search_field: @search_field)) do |c| %>

<% c.with_before_input_group do %>
<div class="input-group within-collection-dropdown">
Expand Down
2 changes: 1 addition & 1 deletion app/components/arclight/search_bar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def within_collection_options
end

def collection_name
@collection_name ||= Array(@params.dig(:f, :collection)).first ||
@collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first ||
helpers.current_context_document&.collection_name
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/features/fielded_search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@
end
end
end

describe 'search box scope retention' do
it 'retains the selected field on the search results page' do
visit search_catalog_path q: 'root', search_field: 'name'
expect(page).to have_select 'search_field', selected: 'Name'
end
end
end
5 changes: 5 additions & 0 deletions spec/features/search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
expect(page).to have_css '.index_title', text: /A brief account/
end

it 'retains the search query in the search box' do
visit search_catalog_path q: 'papers', search_field: 'all_fields'
expect(page).to have_css 'input#q[value="papers"]'
end

it 'renders the expected metadata for a collection' do
visit search_catalog_path q: '', search_field: 'all_fields'

Expand Down