Sha256: 27375c02d74f4dd2d2767854b0b2a25e3c21d205a3972372923bcf4cba2b5490

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

describe Spotlight::BrowseCategorySearchBuilder do
  class BrowseCategoryMockSearchBuilder < Blacklight::SearchBuilder
    include Blacklight::Solr::SearchBuilderBehavior
    include Spotlight::BrowseCategorySearchBuilder
  end

  subject { BrowseCategoryMockSearchBuilder.new(scope).with(blacklight_params) }

  let(:exhibit) { FactoryBot.create(:exhibit) }
  let(:scope) { double(blacklight_config: exhibit.blacklight_config, current_exhibit: exhibit) }
  let(:solr_request) { Blacklight::Solr::Request.new }
  let(:blacklight_params) { { browse_category_id: search.id } }
  let(:search) { FactoryBot.create(:search, exhibit: exhibit, query_params: { sort: 'type', f: { genre_ssim: ['term'] }, q: 'search query' }) }

  describe '#restrict_to_browse_category' do
    it 'adds the search query parameters from the browse category' do
      params = subject.to_hash.with_indifferent_access

      expect(params).to include(
        q: 'search query',
        fq: ['{!term f=genre_ssim}term'],
        sort: 'sort_type_ssi asc'
      )
    end

    context 'with a user-provided query' do
      let(:blacklight_params) { { browse_category_id: search.id, q: 'cats' } }

      it 'uses the user-provided query to further restrict the search' do
        params = subject.to_hash.with_indifferent_access
        expect(params).not_to include(:q)
        expect(params).to include(
          json: {
            query: {
              bool: {
                must: [
                  { edismax: { query: 'cats' } },
                  { edismax: { query: 'search query' } }
                ]
              }
            }
          }
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blacklight-spotlight-3.3.0 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.2.0 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.1.0 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.0.3 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.0.2 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.0.1 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.0.0 spec/models/spotlight/browse_category_search_builder_spec.rb
blacklight-spotlight-3.0.0.rc6 spec/models/spotlight/browse_category_search_builder_spec.rb