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.33.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta4 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta3 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta2 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-8.0.0.beta1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.33.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.32.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.31.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.30.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.29.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.28.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.27.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.27.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.26.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.26.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.25.3 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.25.2 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.25.1 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.25.0 spec/components/blacklight/advanced_search_form_component_spec.rb
blacklight-7.24.0 spec/components/blacklight/advanced_search_form_component_spec.rb