Sha256: b92c3fe0922b1c54e41c3971d702882f96d94c7d86d1b2185910111721caa8ce

Contents?: true

Size: 1.94 KB

Versions: 28

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

# spec for default partial to display solr document fields in catalog show view

RSpec.describe "catalog/_show" do
  include BlacklightHelper
  include CatalogHelper

  before do
    allow(controller).to receive(:action_name).and_return('show')
    @config = Blacklight::Configuration.new do |config|
      config.show.display_type_field = 'asdf'
      config.add_show_field 'one_field', label: 'One:'
      config.add_show_field 'empty_field', label: 'Three:'
      config.add_show_field 'four_field', label: 'Four:'
    end

    @fname_1 = "one_field"
    @fname_2 = "solr_field_not_in_config"
    @fname_3 = "empty_field"
    @fname_4 = "four_field"

    @document = SolrDocument.new(id: 1, @fname_1 => "val_1", @fname_2 => "val2", @fname_4 => "val_4")

    @flabel_1 = "One:"
    @flabel_3 = "Two:"
    @flabel_4 = "Four:"

    allow(view).to receive(:blacklight_config).and_return(@config)
    assigns[:document] = @document
    @rendered = view.render_document_partial @document, :show
  end

  it "only displays fields listed in the initializer" do
    expect(@rendered).not_to include("val_2")
    expect(@rendered).not_to include(@fname_2)
  end

  it "skips over fields listed in initializer that are not in solr response" do
    expect(@rendered).not_to include(@fname_3)
  end

  it "displays field labels from initializer and raw solr field names in the class" do
    # labels
    expect(@rendered).to include(@flabel_1)
    expect(@rendered).to include(@flabel_4)
    # classes
    expect(@rendered).to include("blacklight-#{@fname_1}")
    expect(@rendered).to include("blacklight-#{@fname_4}")
  end

  # this test probably belongs in a Cucumber feature
  #  it "should display fields in the order listed in the initializer" do
  #    pending
  #  end

  it "has values for displayed fields" do
    expect(@rendered).to include("val_1")
    expect(@rendered).to include("val_4")
    expect(@rendered).not_to include("val_2")
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
blacklight-7.40.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.39.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.38.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.37.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.36.2 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.36.1 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.36.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.35.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.34.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.33.1 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.33.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.32.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.31.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.30.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.29.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.28.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.27.1 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.27.0 spec/views/catalog/_show.html.erb_spec.rb
blacklight-7.26.1 spec/views/catalog/_show.html.erb_spec.rb