Sha256: 6145804e5415eaf23a1e5b5764d8465a247a6b31ceda8fc0857597408c2f564f

Contents?: true

Size: 1.89 KB

Versions: 10

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

RSpec.describe Blacklight::IndexPresenter, api: true do
  include Capybara::RSpecMatchers
  subject { presenter }

  let(:request_context) { double(document_index_view_type: 'list') }
  let(:config) { Blacklight::Configuration.new }

  let(:presenter) { described_class.new(document, request_context, config) }
  let(:parameter_class) { ActionController::Parameters }
  let(:params) { parameter_class.new }
  let(:controller) { double }
  let(:search_state) { Blacklight::SearchState.new(params, config, controller) }

  let(:document) do
    SolrDocument.new(id: 1,
                     'link_to_facet_true' => 'x',
                     'link_to_facet_named' => 'x',
                     'qwer' => 'document qwer value')
  end

  before do
    allow(request_context).to receive(:search_state).and_return(search_state)
    allow(request_context).to receive(:action_name).and_return(:index)
  end

  describe '#fields' do
    before do
      config.add_index_field 'title'
    end

    it 'returns the list from the configs' do
      expect(subject.send(:fields).keys).to eq ['title']
    end
  end

  describe "#thumbnail" do
    subject { presenter.thumbnail }

    it { is_expected.to be_instance_of Blacklight::ThumbnailPresenter }
  end

  describe '#display_type' do
    context 'with no configuration' do
      it 'returns an empty array' do
        expect(presenter.display_type).to be_empty
      end
    end

    context 'with a default value' do
      it 'returns the default' do
        expect(presenter.display_type(default: 'default')).to eq ['default']
      end
    end

    context 'with field configuration' do
      let(:document) do
        SolrDocument.new(id: 1, xyz: 'abc')
      end

      before do
        config.index.display_type_field = :xyz
      end

      it 'returns the value from the field' do
        expect(presenter.display_type).to eq ['abc']
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
blacklight-8.2.2 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.2.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.2.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.1.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.0.beta8 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.0.beta7 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.0.beta6 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-8.0.0.beta5 spec/presenters/blacklight/index_presenter_spec.rb