Sha256: 37e1c2570f18fb255664ccb280dd033e0c1d759b05dc16afe7f0c4423a087b9e

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::Search::FacetSuggestInput, type: :component do
  let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet', suggest: true }
  let(:presenter) { instance_double(Blacklight::FacetFieldPresenter) }

  before do
    allow(presenter).to receive(:label).and_return 'Language'
  end

  it 'has an input with the facet-suggest class, which the javascript needs to find it' do
    rendered = render_inline(described_class.new(facet: facet, presenter: presenter))
    expect(rendered.css("input.facet-suggest").count).to eq 1
  end

  it 'has an input with the data-facet-field attribute, which the javascript needs to determine the correct query' do
    rendered = render_inline(described_class.new(facet: facet, presenter: presenter))
    expect(rendered.css('input[data-facet-field="language_facet"]').count).to eq 1
  end

  it 'has a visible label that is associated with the input' do
    rendered = render_inline(described_class.new(facet: facet, presenter: presenter))
    label = rendered.css('label').first
    expect(label.text.strip).to eq 'Filter Language'

    id_in_label_for = label.attribute('for').text
    expect(id_in_label_for).to eq('facet_suggest_language_facet')

    expect(rendered.css('input').first.attribute('id').text).to eq id_in_label_for
  end

  context 'when the facet is explicitly configured to suggest: false' do
    let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet', suggest: false }

    it 'does not display' do
      expect(render_inline(described_class.new(facet: facet, presenter: presenter)).to_s).to eq ''
    end
  end

  context 'when the facet is not explicitly configured with a suggest key' do
    let(:facet) { Blacklight::Configuration::FacetField.new key: 'language_facet' }

    it 'does not display' do
      expect(render_inline(described_class.new(facet: facet, presenter: presenter)).to_s).to eq ''
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-8.8.0 spec/components/blacklight/search/facet_suggest_input_spec.rb