Sha256: adafb5ecbf0b823d4c2a6e21c46e48f4c6af6e7a905949fdbb6ace4cab1cb159

Contents?: true

Size: 1.85 KB

Versions: 62

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::AdvancedSearchFormComponent, type: :component do
  subject(:render) do
    component.render_in(view_context)
  end

  let(:component) { described_class.new(url: '/whatever', response: response, params: params) }
  let(:response) { Blacklight::Solr::Response.new({ facet_counts: { facet_fields: { format: { 'Book' => 10, 'CD' => 5 } } } }.with_indifferent_access, {}) }
  let(:params) { {} }

  let(:rendered) do
    Capybara::Node::Simple.new(render)
  end

  let(:view_context) { controller.view_context }

  before do
    allow(view_context).to receive(:facet_limit_for).and_return(nil)
  end

  context 'with additional parameters' do
    let(:params) { { some: :parameter, an_array: [1, 2] } }

    it 'adds additional parameters as hidden fields' do
      expect(rendered).to have_field 'some', with: 'parameter', type: :hidden
      expect(rendered).to have_field 'an_array[]', with: '1', type: :hidden
      expect(rendered).to have_field 'an_array[]', with: '2', type: :hidden
    end
  end

  it 'has text fields for each search field' do
    expect(rendered).to have_selector '.advanced-search-field', count: 4
    expect(rendered).to have_field 'clause_0_field', with: 'all_fields', type: :hidden
    expect(rendered).to have_field 'clause_1_field', with: 'title', type: :hidden
    expect(rendered).to have_field 'clause_2_field', with: 'author', type: :hidden
    expect(rendered).to have_field 'clause_3_field', with: 'subject', type: :hidden
  end

  it 'has filters' do
    expect(rendered).to have_selector '.blacklight-format'
    expect(rendered).to have_field 'f_inclusive[format][]', with: 'Book'
    expect(rendered).to have_field 'f_inclusive[format][]', with: 'CD'
  end

  it 'has a sort field' do
    expect(rendered).to have_select 'sort', options: %w[relevance year author title]
  end
end

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
blacklight-7.40.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.39.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.38.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.2.2 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.2.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.2.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.37.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.36.2 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.36.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.36.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.35.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.1.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.34.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta8 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta7 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta6 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta5 spec/components/blacklight/advanced_search_form_component_spec.rb