Sha256: da430403e04eb0a4b3cc19425908836f02c458cda09b8e1b2f20ff7fc3b16f53

Contents?: true

Size: 1.93 KB

Versions: 61

Compression:

Stored size: 1.93 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)
  end

  describe '#fields' do
    let(:field) { instance_double(Blacklight::Configuration::Field) }

    before do
      allow(config).to receive(:index_fields_for).and_return(title: field)
    end

    it 'returns the list from the configs' do
      expect(subject.send(:fields)).to eq(title: field)
    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

61 entries across 61 versions & 2 rubygems

Version Path
blacklight-7.39.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.38.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.37.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.36.2 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.36.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.36.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.35.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.34.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.33.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.33.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.32.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.31.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.30.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.29.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.28.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.27.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.27.0 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.26.1 spec/presenters/blacklight/index_presenter_spec.rb
blacklight-7.26.0 spec/presenters/blacklight/index_presenter_spec.rb