Sha256: deb52c9c5ad4320f7d4d7db52ff76c1d6059803b79713e61f73d206a4a1376c7

Contents?: true

Size: 1.88 KB

Versions: 74

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Blacklight::JsonPresenter, api: true do
  let(:response) do
    instance_double(Blacklight::Solr::Response,
                    documents: docs,
                    prev_page: nil,
                    next_page: 2,
                    total_pages: 3,
                    aggregations: aggregations)
  end
  let(:docs) do
    [
      SolrDocument.new(id: '123', title_tsim: 'Book1', author_tsim: 'Julie'),
      SolrDocument.new(id: '456', title_tsim: 'Book2', author_tsim: 'Rosie')
    ]
  end

  let(:aggregations) do
    { 'format_si' => Blacklight::Solr::Response::Facets::FacetField.new("format_si", [{ label: "Book", value: 'Book', hits: 20 }]) }
  end

  let(:config) do
    Blacklight::Configuration.new do |config|
      config.add_facet_field 'format', field: 'format_si', label: 'Format'
      config.add_index_field 'title_tsim', label: 'Title:'
    end
  end

  let(:presenter) { described_class.new(response, config) }

  describe '#search_facets' do
    let(:search_facets) { presenter.search_facets }

    context 'with defined facets that are present in the response' do
      it 'returns them' do
        expect(search_facets.map(&:name)).to eq ['format_si']
      end
    end

    context 'when there are defined facets that are not in the response' do
      before do
        config.add_facet_field 'example_query_facet_field', label: 'Publish Date', query: {}
      end

      let(:aggregations) do
        {
          'format_si' => Blacklight::Solr::Response::Facets::FacetField.new("format_si", [{ label: "Book", value: 'Book', hits: 20 }]),
          'example_query_facet_field' => Blacklight::Solr::Response::Facets::FacetField.new("example_query_facet_field", [])
        }
      end

      it 'filters out the facets that are not defined' do
        expect(search_facets.map(&:name)).to eq ['format_si']
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
blacklight-7.26.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.25.3 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.25.2 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.25.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.25.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.24.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.23.0.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.23.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.22.2 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.22.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.22.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.21.2 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.21.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.21.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.20.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.20.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.19.2 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.19.1 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.19.0 spec/presenters/blacklight/json_presenter_spec.rb
blacklight-7.18.1 spec/presenters/blacklight/json_presenter_spec.rb