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

Don't render the range limit facet on zero results pages; fixes #237. #281

Merged
merged 1 commit into from
Nov 14, 2024
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
12 changes: 11 additions & 1 deletion app/components/blacklight_range_limit/range_facet_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ def initialize(facet_field:, layout: nil, classes: BlacklightRangeLimit.classes)
@classes = classes
end

# Don't render if we have no values at all -- most commonly on a zero results page.
# Normally we'll have at least a min and a max (of values in result set, solr returns),
# OR a count of objects missing a value -- if we don't have ANY of that, there is literally
# nothing we can display, and we're probably in a zero results situation.
def render?
(@facet_field.min.present? && @facet_field.max.present?) ||
@facet_field.missing_facet_item.present?
end

def range_config
@facet_field.range_config
end

def range_limit_url(options = {})
helpers.main_app.url_for(@facet_field.search_state.to_h.merge(range_field: @facet_field.key, action: 'range_limit').merge(options))
helpers.main_app.url_for(@facet_field.search_state.to_h.merge(range_field: @facet_field.key,
action: 'range_limit').merge(options))
end

def uses_distribution?
Expand Down
69 changes: 38 additions & 31 deletions spec/components/range_facet_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,6 @@
allow(component).to receive(:search_facet_path).and_return('/range/key')
end

it 'renders into the default facet layout' do
expect(rendered).to have_selector('h3', text: 'My facet field')
.and have_selector('div.collapse')
end

context 'with min/max' do
let(:facet_field_params) do
{
range_queries: [],
min: 100,
max: 300
}
end

# This is JS api
it "renders a link to fetch distribution info" do
# need request_url for routing of links generated
with_request_url '/catalog' do
expect(rendered).to have_selector(".distribution a.load_distribution[href]")
end
end
end

context 'with range data' do
let(:facet_field_params) do
{
Expand All @@ -80,21 +57,26 @@
}
end

it 'renders into the default facet layout' do
expect(rendered).to have_selector('h3', text: 'My facet field')
.and have_selector('div.collapse')
end

it 'renders the range data into the profile' do
expect(rendered).to have_selector('.distribution li', count: 2)
.and have_selector('.distribution li', text: '100 to 199')
.and have_selector('.distribution li', text: '200 to 300')
end
end

it 'renders a form for the range' do
expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
.and have_field('range[key][begin]')
.and have_field('range[key][end]')
end
it 'renders a form for the range' do
expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
.and have_field('range[key][begin]')
.and have_field('range[key][end]')
end

it 'does not render the missing link if there are no matching documents' do
expect(rendered).not_to have_link '[Missing]'
it 'does not render the missing link if there are no matching documents' do
expect(rendered).not_to have_link '[Missing]'
end
end

context 'with missing documents' do
Expand All @@ -111,4 +93,29 @@
expect(rendered).to have_link '[Missing]', href: expected_facet_query_param
end
end

context 'with min/max but no range segments' do
let(:facet_field_params) do
{
range_queries: [],
min: 100,
max: 300
}
end

it "renders a link to fetch distribution info" do
# need request_url for routing of links generated
with_request_url '/catalog' do
expect(rendered).to have_selector(".distribution a.load_distribution[href]")
end
end
end

context 'with no data to display (e.g., no results page)' do
let(:facet_field_params) { { min: nil, max: nil, missing_facet_item: nil } }

it 'does not render the range limit facet' do
expect(component.render?).to be false
end
end
end
9 changes: 9 additions & 0 deletions spec/features/blacklight_range_limit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@
expect(page).to_not have_content 'Publication Date Sort'
end
end

context 'when on a zero results found page' do
it 'should not render the range limit facet' do
visit search_catalog_path(q: 'asdfasdfasdf')
expect(page).to_not have_selector '#facets .facet-limit.blacklight-pub_date_si'
expect(page).to_not have_selector 'input#range_pub_date_si_begin'
expect(page).to_not have_selector 'input#range_pub_date_si_end'
end
end
end

describe "Blacklight Range Limit with configured input labels" do
Expand Down
Loading