Sha256: ea251fa3ab15a65406268fd13fe539640374c59e22b630a9a2a04709dc7f4d59

Contents?: true

Size: 1.98 KB

Versions: 24

Compression:

Stored size: 1.98 KB

Contents

describe 'spotlight/search_configurations/_facets', type: :view do
  let(:exhibit) { FactoryBot.create(:exhibit) }
  let!(:custom_field) { FactoryBot.create(:custom_field, exhibit: exhibit, label: 'Foobar', field_type: 'vocab') }
  let(:config) do
    exhibit.blacklight_configuration
  end
  let(:field_metadata) { double('field_metadata') }
  let(:empty_facet) { { document_count: 0, value_count: 0, terms: [] } }
  let(:nonempty_facet) { { document_count: 1, value_count: 3, terms: %w(a b c) } }
  let(:f) do
    form_helper = nil
    controller.view_context.bootstrap_form_for(config, url: '/update') do |f|
      form_helper = f
    end
    form_helper
  end

  before do
    assign(:blacklight_configuration, config)
    allow(view).to receive_messages(current_exhibit: exhibit,
                                    blacklight_config: config.blacklight_config)
    allow(field_metadata).to receive(:field).with(any_args).and_return(nonempty_facet)
    allow(field_metadata).to receive(:field).with('genre_ssim').and_return(empty_facet)
    allow(field_metadata).to receive(:field).with(custom_field.field).and_return(empty_facet)
    assign(:field_metadata, field_metadata)
    render partial: 'spotlight/search_configurations/facets', locals: { f: f }
  end

  it 'shows the config for the non-empty personal name facet' do
    expect(rendered).to have_content 'Personal Names'
  end

  it 'shows the config for the empty custom facet' do
    expect(rendered).to have_content 'Foobar'
  end

  it 'hides the config for the empty genre facet' do
    expect(rendered).not_to have_content 'Genre'
  end

  describe do
    before do
      original_config = Spotlight::Engine.blacklight_config.deep_dup
      allow(Spotlight::Engine).to receive(:blacklight_config).and_return(original_config)
      original_config.add_facet_field 'some_hidden_field', if: ->(*_args) { false }
    end

    it 'hides the config facets configured not to display' do
      expect(rendered).not_to have_content 'Some hidden field'
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.4.0 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.3.3 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.3.2 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.3.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.3.0 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.2.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.2.0 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.1.0 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.2 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc6 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc5 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc4 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc3 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc2 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-2.0.0.rc1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-1.5.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
blacklight-spotlight-1.4.1 spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb